You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2002/09/29 17:21:21 UTC
cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core StandardContext.java
remm 2002/09/29 08:21:21
Modified: catalina/src/share/org/apache/catalina/core
StandardContext.java
Log:
- Merge refactored resources lifecycle handling from 4.1 branch.
Revision Changes Path
1.8 +94 -40 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java
Index: StandardContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- StandardContext.java 24 Aug 2002 02:27:27 -0000 1.7
+++ StandardContext.java 29 Sep 2002 15:21:21 -0000 1.8
@@ -499,6 +499,12 @@
protected boolean cachingAllowed = true;
+ /**
+ * Non proxied resources.
+ */
+ protected DirContext webappResources = null;
+
+
// ----------------------------------------------------- Context Properties
@@ -1148,16 +1154,28 @@
*/
public synchronized void setResources(DirContext resources) {
+ if (started) {
+ throw new IllegalStateException
+ (sm.getString("standardContext.resources.started"));
+ }
+
+ DirContext oldResources = this.webappResources;
+ if (oldResources == resources)
+ return;
+
if (resources instanceof BaseDirContext) {
- ((BaseDirContext) resources).setDocBase(getBasePath());
((BaseDirContext) resources).setCached(isCachingAllowed());
}
if (resources instanceof FileDirContext) {
filesystemBased = true;
}
- super.setResources(resources);
- if (started)
- postResources(); // As a servlet context attribute
+ this.webappResources = resources;
+
+ // The proxied resources will be refreshed on start
+ this.resources = null;
+
+ support.firePropertyChange("resources", oldResources,
+ this.webappResources);
}
@@ -3446,6 +3464,66 @@
/**
+ * Allocate resources, including proxy.
+ * Return <code>true</code> if initialization was successfull,
+ * or <code>false</code> otherwise.
+ */
+ public boolean resourcesStart() {
+
+ boolean ok = true;
+
+ Hashtable env = new Hashtable();
+ if (getParent() != null)
+ env.put(ProxyDirContext.HOST, getParent().getName());
+ env.put(ProxyDirContext.CONTEXT, getName());
+
+ try {
+ ProxyDirContext proxyDirContext =
+ new ProxyDirContext(env, webappResources);
+ if (webappResources instanceof BaseDirContext) {
+ ((BaseDirContext) webappResources).setDocBase(getBasePath());
+ ((BaseDirContext) webappResources).allocate();
+ }
+ this.resources = proxyDirContext;
+ } catch (Throwable t) {
+ log(sm.getString("standardContext.resourcesStart", t));
+ ok = false;
+ }
+
+ return (ok);
+
+ }
+
+
+ /**
+ * Deallocate resources and destroy proxy.
+ */
+ public boolean resourcesStop() {
+
+ boolean ok = true;
+
+ try {
+ if (resources != null) {
+ if (resources instanceof Lifecycle) {
+ ((Lifecycle) resources).stop();
+ }
+ if (webappResources instanceof BaseDirContext) {
+ ((BaseDirContext) webappResources).release();
+ }
+ }
+ } catch (Throwable t) {
+ log(sm.getString("standardContext.resourcesStop", t));
+ ok = false;
+ }
+
+ this.resources = null;
+
+ return (ok);
+
+ }
+
+
+ /**
* Load and initialize all servlets marked "load on startup" in the
* web application deployment descriptor.
*
@@ -3519,7 +3597,7 @@
boolean ok = true;
// Add missing components as necessary
- if (getResources() == null) { // (1) Required by Loader
+ if (webappResources == null) { // (1) Required by Loader
if (debug >= 1)
log("Configuring default Resources");
try {
@@ -3531,14 +3609,10 @@
log("Error initializing resources: " + e.getMessage());
ok = false;
}
- if (ok) {
- DirContext dirContext =
- ((ProxyDirContext) resources).getDirContext();
- if ((dirContext != null)
- && (dirContext instanceof BaseDirContext)) {
- ((BaseDirContext) dirContext).allocate();
- }
- }
+ }
+ if (ok) {
+ if (!resourcesStart())
+ ok = false;
}
if (getLoader() == null) { // (2) Required by Manager
if (getPrivileged()) {
@@ -3780,29 +3854,9 @@
// Stop our application listeners
listenerStop();
- // Stop our subordinate components, if any
- if (resources != null) {
- if (resources instanceof Lifecycle) {
- ((Lifecycle) resources).stop();
- } else if (resources instanceof ProxyDirContext) {
- DirContext dirContext =
- ((ProxyDirContext) resources).getDirContext();
- if (dirContext != null) {
- if (debug >= 1) {
- log("Releasing document base " + docBase);
- }
- if (dirContext instanceof BaseDirContext) {
- ((BaseDirContext) dirContext).release();
- if ((dirContext instanceof WARDirContext)
- || (dirContext instanceof FileDirContext)) {
- resources = null;
- }
- } else {
- log("Cannot release " + resources);
- }
- }
- }
- }
+ // Stop resources
+ resourcesStop();
+
if ((realm != null) && (realm instanceof Lifecycle)) {
((Lifecycle) realm).stop();
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>