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 2004/07/26 10:09:21 UTC
cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina Context.java
remm 2004/07/26 01:09:21
Modified: catalina/src/share/org/apache/catalina/startup
HostConfig.java ContextRuleSet.java
catalina/src/share/org/apache/catalina/core
StandardContext.java
catalina/src/share/org/apache/catalina Context.java
Added: catalina/src/conf context.xml
Log:
- Add code to handle resource relaoding.
- Add one extra element to Context (I couldn't find a way to avoid it).
- Add a global context.xml file, to define two basic reload resources.
- Now, I'll do the new anti locking code.
Revision Changes Path
1.36 +40 -27 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/HostConfig.java
Index: HostConfig.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/HostConfig.java,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- HostConfig.java 25 Jul 2004 23:35:37 -0000 1.35
+++ HostConfig.java 26 Jul 2004 08:09:19 -0000 1.36
@@ -464,28 +464,28 @@
// Assume this is a configuration descriptor and deploy it
log.debug(sm.getString("hostConfig.deployDescriptor", files[i]));
try {
- Context newContext = null;
+ Context context = null;
synchronized (digester) {
- newContext = (Context) digester.parse(contextXml);
+ context = (Context) digester.parse(contextXml);
}
- if (newContext instanceof Lifecycle) {
+ if (context instanceof Lifecycle) {
Class clazz = Class.forName(host.getConfigClass());
LifecycleListener listener =
(LifecycleListener) clazz.newInstance();
- ((Lifecycle) newContext).addLifecycleListener(listener);
+ ((Lifecycle) context).addLifecycleListener(listener);
}
- newContext.setConfigFile(contextXml.getAbsolutePath());
- newContext.setPath(contextPath);
+ context.setConfigFile(contextXml.getAbsolutePath());
+ context.setPath(contextPath);
// Add the context XML to the list of watched files
deployedApp.reloadResources.put
(contextXml.getAbsolutePath(), new Long(contextXml.lastModified()));
// Add the associated docBase to the redeployed list if it's a WAR
boolean isWar = false;
- if (newContext.getDocBase() != null) {
- File docBase = new File(newContext.getDocBase());
+ if (context.getDocBase() != null) {
+ File docBase = new File(context.getDocBase());
if (!docBase.isAbsolute()) {
docBase = new File(new File(host.getAppBase()),
- newContext.getDocBase());
+ context.getDocBase());
}
deployedApp.redeployResources.put(docBase.getAbsolutePath(),
new Long(docBase.lastModified()));
@@ -493,21 +493,18 @@
isWar = true;
}
}
- host.addChild(newContext);
+ host.addChild(context);
// Add the eventual unpacked WAR and all the resources which will be
// watched inside it
- if (isWar && unpackWARs && (newContext.getDocBase() != null)) {
- File docBase = new File(newContext.getDocBase());
+ if (isWar && unpackWARs && (context.getDocBase() != null)) {
+ File docBase = new File(context.getDocBase());
if (!docBase.isAbsolute()) {
docBase = new File(new File(host.getAppBase()),
- newContext.getDocBase());
+ context.getDocBase());
}
deployedApp.redeployResources.put(docBase.getAbsolutePath(),
new Long(docBase.lastModified()));
- // FIXME: Add the list of reload resources as given by the context
- // This list would by default contain /WEB-INF/web.xml and
- // /META-INF/context.xml
- // Add new element in Context to configure this
+ addWatchedResources(deployedApp, context);
}
} catch (Throwable t) {
log.error(sm.getString("hostConfig.deployDescriptor.error",
@@ -652,10 +649,7 @@
}
deployedApp.redeployResources.put(docBase.getAbsolutePath(),
new Long(docBase.lastModified()));
- // FIXME: Add the list of reload resources as given by the context
- // This list would by default contain /WEB-INF/web.xml and
- // /META-INF/context.xml
- // Add new element in Context to configure this
+ addWatchedResources(deployedApp, context);
}
} catch (Throwable t) {
log.error(sm.getString("hostConfig.deployJar.error",
@@ -728,10 +722,7 @@
host.addChild(context);
deployedApp.redeployResources.put(dir.getAbsolutePath(),
new Long(dir.lastModified()));
- // FIXME: Add the list of reload resources as given by the context
- // This list would by default contain /WEB-INF/web.xml and
- // /META-INF/context.xml
- // Add new element in Context to configure this
+ addWatchedResources(deployedApp, context);
} catch (Throwable t) {
log.error(sm.getString("hostConfig.deployDir.error", files[i]),
t);
@@ -745,6 +736,25 @@
}
+
+ /**
+ * Add watched resources to the specified Context.
+ * @param app
+ */
+ protected void addWatchedResources(DeployedApplication app, Context context) {
+ File docBase = new File(context.getDocBase());
+ if (!docBase.isAbsolute()) {
+ docBase = new File(new File(host.getAppBase()),
+ context.getDocBase());
+ }
+ String[] watchedResources = context.findWatchedResources();
+ for (int i = 0; i < watchedResources.length; i++) {
+ File resource = new File(docBase, watchedResources[i]);
+ app.reloadResources.put(resource.getAbsolutePath(),
+ new Long(resource.lastModified()));
+ }
+ }
+
/**
* Check resources for redeployment and reloading.
@@ -805,7 +815,8 @@
if (log.isDebugEnabled())
log.debug("Checking context[" + app.name + "] reload resource " + resource);
long lastModified = ((Long) app.reloadResources.get(resources[i])).longValue();
- if ((!resource.exists()) || (resource.lastModified() != lastModified)) {
+ if ((!resource.exists() && lastModified != 0L)
+ || (resource.lastModified() != lastModified)) {
// Reload application
Container context = host.findChild(app.name);
try {
@@ -822,6 +833,8 @@
log.warn(sm.getString
("hostConfig.context.restart", app.name), e);
}
+ // Update times
+ app.reloadResources.put(resources[i], new Long(resource.lastModified()));
app.timestamp = System.currentTimeMillis();
return;
}
1.11 +4 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/ContextRuleSet.java
Index: ContextRuleSet.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/ContextRuleSet.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ContextRuleSet.java 23 Jul 2004 22:57:34 -0000 1.10
+++ ContextRuleSet.java 26 Jul 2004 08:09:19 -0000 1.11
@@ -220,6 +220,9 @@
"addValve",
"org.apache.catalina.Valve");
+ digester.addCallMethod(prefix + "Context/WatchedResource",
+ "addWatchedResource", 0);
+
digester.addCallMethod(prefix + "Context/WrapperLifecycle",
"addWrapperLifecycle", 0);
1.135 +69 -3 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.134
retrieving revision 1.135
diff -u -r1.134 -r1.135
--- StandardContext.java 23 Jul 2004 22:57:35 -0000 1.134
+++ StandardContext.java 26 Jul 2004 08:09:20 -0000 1.135
@@ -65,8 +65,6 @@
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Loader;
-import org.apache.catalina.Server;
-import org.apache.catalina.ServerFactory;
import org.apache.catalina.Wrapper;
import org.apache.catalina.deploy.ApplicationParameter;
import org.apache.catalina.deploy.ContextEjb;
@@ -477,6 +475,12 @@
/**
+ * The watched resources for this application.
+ */
+ private String watchedResources[] = new String[0];
+
+
+ /**
* The welcome files for this application.
*/
private String welcomeFiles[] = new String[0];
@@ -2277,6 +2281,24 @@
/**
+ * Add a new watched resource to the set recognized by this Context.
+ *
+ * @param name New watched resource file name
+ */
+ public void addWatchedResource(String name) {
+
+ synchronized (watchedResources) {
+ String results[] = new String[watchedResources.length + 1];
+ for (int i = 0; i < watchedResources.length; i++)
+ results[i] = watchedResources[i];
+ results[watchedResources.length] = name;
+ watchedResources = results;
+ }
+
+ }
+
+
+ /**
* Add a new welcome file to the set recognized by this Context.
*
* @param name New welcome file name
@@ -2973,6 +2995,15 @@
/**
+ * Return the set of watched resources for this Context. If none are
+ * defined, a zero length array will be returned.
+ */
+ public String[] findWatchedResources() {
+ return watchedResources;
+ }
+
+
+ /**
* Return the set of welcome files defined for this Context. If none are
* defined, a zero-length array is returned.
*/
@@ -3555,6 +3586,41 @@
}
+ /**
+ * Remove the specified watched resource name from the list associated
+ * with this Context.
+ *
+ * @param name Name of the watched resource to be removed
+ */
+ public void removeWatchedResource(String name) {
+
+ synchronized (watchedResources) {
+
+ // Make sure this watched resource is currently present
+ int n = -1;
+ for (int i = 0; i < watchedResources.length; i++) {
+ if (watchedResources[i].equals(name)) {
+ n = i;
+ break;
+ }
+ }
+ if (n < 0)
+ return;
+
+ // Remove the specified watched resource
+ int j = 0;
+ String results[] = new String[watchedResources.length - 1];
+ for (int i = 0; i < watchedResources.length; i++) {
+ if (i != n)
+ results[j++] = watchedResources[i];
+ }
+ watchedResources = results;
+
+ }
+
+ }
+
+
/**
* Remove the specified welcome file name from the list recognized
* by this Context.
1.1 jakarta-tomcat-catalina/catalina/src/conf/context.xml
Index: context.xml
===================================================================
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>META-INF/context.xml</WatchedResource>
</Context>
1.15 +27 -4 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/Context.java
Index: Context.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/Context.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- Context.java 23 Jul 2004 22:57:35 -0000 1.14
+++ Context.java 26 Jul 2004 08:09:21 -0000 1.15
@@ -18,8 +18,6 @@
package org.apache.catalina;
-import java.io.File;
-
import javax.servlet.ServletContext;
import org.apache.tomcat.util.http.mapper.Mapper;
@@ -603,6 +601,15 @@
*/
public void addTaglib(String uri, String location);
+
+ /**
+ * Add a resource which will be watched for reloading by the host auto
+ * deployer. Note: this will not be used in embedded mode.
+ *
+ * @param name Path to the resource, relative to docBase
+ */
+ public void addWatchedResource(String name);
+
/**
* Add a new welcome file to the set recognized by this Context.
@@ -921,6 +928,13 @@
/**
+ * Return the set of watched resources for this Context. If none are
+ * defined, a zero length array will be returned.
+ */
+ public String[] findWatchedResources();
+
+
+ /**
* Return <code>true</code> if the specified welcome file is defined
* for this Context; otherwise return <code>false</code>.
*
@@ -928,7 +942,7 @@
*/
public boolean findWelcomeFile(String name);
-
+
/**
* Return the set of welcome files defined for this Context. If none are
* defined, a zero-length array is returned.
@@ -1118,6 +1132,15 @@
*/
public void removeTaglib(String uri);
+
+ /**
+ * Remove the specified watched resource name from the list associated
+ * with this Context.
+ *
+ * @param name Name of the watched resource to be removed
+ */
+ public void removeWatchedResource(String name);
+
/**
* Remove the specified welcome file name from the list recognized
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org