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 2003/05/23 01:04:19 UTC
cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core ContainerBase.java StandardContext.java StandardEngine.java StandardHost.java StandardServer.java
remm 2003/05/22 16:04:19
Modified: catalina/src/share/org/apache/catalina/core
ContainerBase.java StandardContext.java
StandardEngine.java StandardHost.java
StandardServer.java
Log:
- Refactor the host deployer, session manager, webapp reloading threads
into one (potentially) thread at the engine level.
- The thread code is in StandardEngine, but can be refactored into
StandardServer, in case we want to be able to have one thread for the whole
server. The main adavantage of putting the code in container is that additional
threads can be associated to branches of the container tree (ex: associate
one thread per host, one thread for a specific context, etc ...).
- The container's CL (if present) will be set as the context classloader before
invoking the execute method, and will be restored afterwards.
- I couldn't come up with good neams for the new field and the thread name.
Can you help ?
- By default, the engine will have a thread with a 10s delay.
Revision Changes Path
1.23 +156 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ContainerBase.java
Index: ContainerBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- ContainerBase.java 19 May 2003 22:45:23 -0000 1.22
+++ ContainerBase.java 22 May 2003 23:04:18 -0000 1.23
@@ -208,6 +208,12 @@
/**
+ * The execute delay for this component.
+ */
+ protected int executeDelay = -1;
+
+
+ /**
* The lifecycle event support for this component.
*/
protected LifecycleSupport lifecycle = new LifecycleSupport(this);
@@ -299,6 +305,18 @@
protected PropertyChangeSupport support = new PropertyChangeSupport(this);
+ /**
+ * The background thread.
+ */
+ private Thread thread = null;
+
+
+ /**
+ * The background thread completion semaphore.
+ */
+ private boolean threadDone = false;
+
+
// ------------------------------------------------------------- Properties
@@ -328,6 +346,32 @@
/**
+ * Get the delay between the invocation of the execute method on
+ * this container and its children. Child containers will not be invoked
+ * if their delay value is not -1 (which would mean they are using their
+ * own thread). Setting this to a positive value will cause a thread to
+ * be spawn. After waiting the specified amount of time, the thread will
+ * invoke the executePeriodic method on this container and all
+ * its children.
+ */
+ public int getExecuteDelay() {
+ return executeDelay;
+ }
+
+
+ /**
+ * Set the delay between the invocation of the execute method on this
+ * container and its children.
+ *
+ * @param delay The delay in seconds between the invocation of execute
+ * methods
+ */
+ public void setExecuteDelay(int executeDelay) {
+ this.executeDelay = executeDelay;
+ }
+
+
+ /**
* Return descriptive information about this Container implementation and
* the corresponding version number, in the format
* <code><description>/<version></code>.
@@ -1090,6 +1134,9 @@
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(START_EVENT, null);
+ // Start our thread
+ threadStart();
+
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
@@ -1113,6 +1160,9 @@
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null);
+ // Stop out thread
+ threadStop();
+
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(STOP_EVENT, null);
started = false;
@@ -1316,6 +1366,14 @@
}
+ /**
+ * Execute a periodic task, such as reloading, etc. This method will be
+ * invoked inside the classloading context of this container. Unexpected
+ * throwables will be caught and logged.
+ */
+ public void execute() {
+ }
+
// ------------------------------------------------------ Protected Methods
@@ -1516,5 +1574,102 @@
return suffix.toString();
}
-
+
+ /**
+ * Start the background thread that will periodically check for
+ * session timeouts.
+ */
+ private void threadStart() {
+
+ if (thread != null)
+ return;
+ if (executeDelay <= 0)
+ return;
+
+ threadDone = false;
+ String threadName = "ExecuteDelay[" + getName() + "]";
+ thread = new Thread(new ContainerExecuteDelay(), threadName);
+ thread.setDaemon(true);
+ thread.start();
+
+ }
+
+
+ /**
+ * Stop the background thread that is periodically checking for
+ * session timeouts.
+ */
+ private void threadStop() {
+
+ if (thread == null)
+ return;
+
+ threadDone = true;
+ thread.interrupt();
+ try {
+ thread.join();
+ } catch (InterruptedException e) {
+ ;
+ }
+
+ thread = null;
+
+ }
+
+
+ // -------------------------------------- ContainerExecuteDelay Inner Class
+
+
+ /**
+ * Private thread class to invoke the execute method of this container
+ * and its children after a fixed delay.
+ */
+ protected class ContainerExecuteDelay implements Runnable {
+
+
+ /**
+ * Perform the requested notification.
+ */
+ public void run() {
+ while (!threadDone) {
+ try {
+ Thread.sleep(executeDelay * 1000L);
+ } catch (InterruptedException e) {
+ ;
+ }
+ if (!threadDone) {
+ Container parent = (Container) getMappingObject();
+ ClassLoader cl =
+ Thread.currentThread().getContextClassLoader();
+ if (parent.getLoader() != null) {
+ cl = parent.getLoader().getClassLoader();
+ }
+ processChildren(parent, cl);
+ }
+ }
+ }
+
+ protected void processChildren(Container container, ClassLoader cl) {
+ try {
+ if (container.getLoader() != null) {
+ Thread.currentThread().setContextClassLoader
+ (container.getLoader().getClassLoader());
+ }
+ container.execute();
+ } catch (Throwable t) {
+ log.error("Exception invoking periodic operation: ", t);
+ } finally {
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+ Container[] children = container.findChildren();
+ for (int i = 0; i < children.length; i++) {
+ if (children[i].getExecuteDelay() <= 0) {
+ processChildren(children[i], cl);
+ }
+ }
+ }
+
+ }
+
+
}
1.58 +25 -1 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.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- StandardContext.java 22 May 2003 18:20:03 -0000 1.57
+++ StandardContext.java 22 May 2003 23:04:18 -0000 1.58
@@ -4392,6 +4392,30 @@
}
+ /**
+ * Execute a periodic task, such as reloading, etc. This method will be
+ * invoked inside the classloading context of this container. Unexpected
+ * throwables will be caught and logged.
+ */
+ public void execute() {
+
+ if (!started)
+ return;
+
+ if ((getManager() != null)
+ && (getManager() instanceof StandardManager)) {
+ ((StandardManager) getManager()).processExpires();
+ }
+
+ if (reloadable && (getLoader() != null)) {
+ if (getLoader().modified()) {
+ reload();
+ }
+ }
+
+ }
+
+
// ------------------------------------------------------ Protected Methods
1.20 +3 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardEngine.java
Index: StandardEngine.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardEngine.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- StandardEngine.java 19 May 2003 22:45:24 -0000 1.19
+++ StandardEngine.java 22 May 2003 23:04:18 -0000 1.20
@@ -111,6 +111,8 @@
setJvmRoute(System.getProperty("jvmRoute"));
} catch(Exception ex) {
}
+ // By default, the engine will hold the reloading thread
+ executeDelay = 10;
}
1.15 +11 -1 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHost.java
Index: StandardHost.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardHost.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- StandardHost.java 19 May 2003 22:45:24 -0000 1.14
+++ StandardHost.java 22 May 2003 23:04:18 -0000 1.15
@@ -774,6 +774,16 @@
}
+ /**
+ * Execute a periodic task, such as reloading, etc. This method will be
+ * invoked inside the classloading context of this container. Unexpected
+ * throwables will be caught and logged.
+ */
+ public void execute() {
+ lifecycle.fireLifecycleEvent("check", null);
+ }
+
+
// ------------------------------------------------------- Deployer Methods
1.17 +5 -7 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardServer.java
Index: StandardServer.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardServer.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- StandardServer.java 22 Apr 2003 17:13:22 -0000 1.16
+++ StandardServer.java 22 May 2003 23:04:18 -0000 1.17
@@ -927,8 +927,7 @@
return (false);
}
WebappLoader wloader = (WebappLoader) loader;
- if ((wloader.getCheckInterval() != 15) ||
- (wloader.getDebug() != 0) ||
+ if ((wloader.getDebug() != 0) ||
(wloader.getDelegate() != false) ||
!wloader.getLoaderClass().equals
("org.apache.catalina.loader.WebappClassLoader")) {
@@ -953,7 +952,6 @@
StandardManager smanager = (StandardManager) manager;
if ((smanager.getDebug() != 0) ||
!smanager.getPathname().equals("SESSIONS.ser") ||
- (smanager.getCheckInterval() != 60) ||
!smanager.getRandomClass().equals("java.security.SecureRandom") ||
(smanager.getMaxActiveSessions() != -1) ||
!smanager.getAlgorithm().equals("MD5")) {
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core
ContainerBase.java StandardContext.java StandardEngine.java StandardHost.java
StandardServer.java
Posted by Remy Maucherat <re...@apache.org>.
Radim Kubacki wrote:
> remm@apache.org wrote:
> Didn't you forget to commit change to StandardManager to make
> processExpires public?
Well, late-at-night commits are esp risky ;-)
Sorry ...
It's fixed now, and I have improved the names used (it wasn't too hard
:-D ). If people are happy with the names and behavior, I will document
the feature (along with the docs for the client deployer).
Remy
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core
ContainerBase.java StandardContext.java StandardEngine.java StandardHost.java
StandardServer.java
Posted by Radim Kubacki <ra...@sun.com>.
remm@apache.org wrote:
> remm 2003/05/22 16:04:19
>
> Modified: catalina/src/share/org/apache/catalina/core
> ContainerBase.java StandardContext.java
> StandardEngine.java StandardHost.java
> StandardServer.java
> Log:
> - Refactor the host deployer, session manager, webapp reloading threads
> into one (potentially) thread at the engine level.
> - The thread code is in StandardEngine, but can be refactored into
> StandardServer, in case we want to be able to have one thread for the whole
> server. The main adavantage of putting the code in container is that additional
> threads can be associated to branches of the container tree (ex: associate
> one thread per host, one thread for a specific context, etc ...).
> - The container's CL (if present) will be set as the context classloader before
> invoking the execute method, and will be restored afterwards.
> - I couldn't come up with good neams for the new field and the thread name.
> Can you help ?
> - By default, the engine will have a thread with a 10s delay.
>
>
> 1.58 +25 -1 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.57
> retrieving revision 1.58
> diff -u -r1.57 -r1.58
> --- StandardContext.java 22 May 2003 18:20:03 -0000 1.57
> +++ StandardContext.java 22 May 2003 23:04:18 -0000 1.58
> @@ -4392,6 +4392,30 @@
> }
>
>
> + /**
> + * Execute a periodic task, such as reloading, etc. This method will be
> + * invoked inside the classloading context of this container. Unexpected
> + * throwables will be caught and logged.
> + */
> + public void execute() {
> +
> + if (!started)
> + return;
> +
> + if ((getManager() != null)
> + && (getManager() instanceof StandardManager)) {
> + ((StandardManager) getManager()).processExpires();
> + }
> +
Didn't you forget to commit change to StandardManager to make
processExpires public?
Radim
> + if (reloadable && (getLoader() != null)) {
> + if (getLoader().modified()) {
> + reload();
> + }
> + }
> +
> + }
> +
> +
> // ------------------------------------------------------ Protected Methods
>
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org