tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/loader WebappLoader.java
Date Thu, 22 May 2003 23:04:48 GMT
remm        2003/05/22 16:04:48

  Modified:    catalina/src/share/org/apache/catalina/loader
                        WebappLoader.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.16      +2 -222    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/loader/WebappLoader.java
  
  Index: WebappLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/loader/WebappLoader.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- WebappLoader.java	24 Apr 2003 22:13:32 -0000	1.15
  +++ WebappLoader.java	22 May 2003 23:04:48 -0000	1.16
  @@ -132,7 +132,7 @@
    */
   
   public class WebappLoader
  -    implements Lifecycle, Loader, PropertyChangeListener, Runnable, MBeanRegistration 
{
  +    implements Lifecycle, Loader, PropertyChangeListener, MBeanRegistration  {
   
       // ----------------------------------------------------------- Constructors
   
  @@ -164,13 +164,6 @@
   
   
       /**
  -     * The number of seconds between checks for modified classes, if
  -     * automatic reloading is enabled.
  -     */
  -    private int checkInterval = 15;
  -
  -
  -    /**
        * The class loader being managed by this Loader component.
        */
       private WebappClassLoader classLoader = null;
  @@ -260,24 +253,6 @@
       protected PropertyChangeSupport support = new PropertyChangeSupport(this);
   
   
  -    /**
  -     * The background thread.
  -     */
  -    private Thread thread = null;
  -
  -
  -    /**
  -     * The background thread completion semaphore.
  -     */
  -    private boolean threadDone = false;
  -
  -
  -    /**
  -     * Name to register for the background thread.
  -     */
  -    private String threadName = "WebappLoader";
  -
  -
       // Classpath set in the loader
       private String classpath=null;
   
  @@ -287,32 +262,6 @@
   
   
       /**
  -     * Return the check interval for this Loader.
  -     */
  -    public int getCheckInterval() {
  -
  -        return (this.checkInterval);
  -
  -    }
  -
  -
  -    /**
  -     * Set the check interval for this Loader.
  -     *
  -     * @param checkInterval The new check interval
  -     */
  -    public void setCheckInterval(int checkInterval) {
  -
  -        int oldCheckInterval = this.checkInterval;
  -        this.checkInterval = checkInterval;
  -        support.firePropertyChange("checkInterval",
  -                                   new Integer(oldCheckInterval),
  -                                   new Integer(this.checkInterval));
  -
  -    }
  -
  -
  -    /**
        * Return the Java class loader to be used by this Container.
        */
       public ClassLoader getClassLoader() {
  @@ -492,14 +441,6 @@
                                      new Boolean(oldReloadable),
                                      new Boolean(this.reloadable));
   
  -        // Start or stop our background thread if required
  -        if (!started)
  -            return;
  -        if (!oldReloadable && this.reloadable)
  -            threadStart();
  -        else if (oldReloadable && !this.reloadable)
  -            threadStop();
  -
       }
   
   
  @@ -772,16 +713,6 @@
               throw new LifecycleException("start: ", t);
           }
   
  -        // Start our background thread if we are reloadable
  -        if (reloadable) {
  -            log.info(sm.getString("webappLoader.reloading"));
  -            try {
  -                threadStart();
  -            } catch (IllegalStateException e) {
  -                throw new LifecycleException(e);
  -            }
  -        }
  -
       }
   
   
  @@ -801,10 +732,6 @@
           lifecycle.fireLifecycleEvent(STOP_EVENT, null);
           started = false;
   
  -        // Stop our background thread if we are reloadable
  -        if (reloadable)
  -            threadStop();
  -
           // Remove context attributes as appropriate
           if (container instanceof Context) {
               ServletContext servletContext =
  @@ -929,17 +856,6 @@
   
   
       /**
  -     * Notify our Context that a reload is appropriate.
  -     */
  -    private void notifyContext() {
  -
  -        WebappContextNotifier notifier = new WebappContextNotifier();
  -        (new Thread(notifier)).start();
  -
  -    }
  -
  -
  -    /**
        * Configure associated class loader permissions.
        */
       private void setPermissions() {
  @@ -1337,142 +1253,6 @@
   
       }
   
  -
  -    /**
  -     * Sleep for the duration specified by the <code>checkInterval</code>
  -     * property.
  -     */
  -    private void threadSleep() {
  -
  -        try {
  -            Thread.sleep(checkInterval * 1000L);
  -        } catch (InterruptedException e) {
  -            ;
  -        }
  -
  -    }
  -
  -
  -    /**
  -     * Start the background thread that will periodically check for
  -     * session timeouts.
  -     *
  -     * @exception IllegalStateException if we should not be starting
  -     *  a background thread now
  -     */
  -    private void threadStart() {
  -
  -        // Has the background thread already been started?
  -        if (thread != null)
  -            return;
  -
  -        // Validate our current state
  -        if (!reloadable)
  -            throw new IllegalStateException
  -                (sm.getString("webappLoader.notReloadable"));
  -        if (!(container instanceof Context))
  -            throw new IllegalStateException
  -                (sm.getString("webappLoader.notContext"));
  -
  -        // Start the background thread
  -        if (log.isDebugEnabled())
  -            log.debug(" Starting background thread");
  -        // XXX ONE TREAD PER WEBAPP IS _WRONG_ - IT DOESN'T SCALE
  -        threadDone = false;
  -        threadName = "WebappLoader[" + container.getName() + "]";
  -        thread = new Thread(this, threadName);
  -        thread.setDaemon(true);
  -        thread.start();
  -
  -    }
  -
  -
  -    /**
  -     * Stop the background thread that is periodically checking for
  -     * modified classes.
  -     */
  -    private void threadStop() {
  -
  -        if (thread == null)
  -            return;
  -
  -        if (log.isDebugEnabled())
  -            log.debug(" Stopping background thread");
  -        threadDone = true;
  -        thread.interrupt();
  -        try {
  -            thread.join();
  -        } catch (InterruptedException e) {
  -            ;
  -        }
  -
  -        thread = null;
  -
  -    }
  -
  -
  -    // ------------------------------------------------------ Background Thread
  -
  -
  -    /**
  -     * The background thread that checks for session timeouts and shutdown.
  -     */
  -    public void run() {
  -
  -        if (log.isDebugEnabled())
  -            log.debug("BACKGROUND THREAD Starting");
  -
  -        // Loop until the termination semaphore is set
  -        while (!threadDone) {
  -
  -            // Wait for our check interval
  -            threadSleep();
  -
  -            if (!started)
  -                break;
  -
  -            try {
  -                // Perform our modification check
  -                if (!classLoader.modified())
  -                    continue;
  -            } catch (Exception e) {
  -                log.error(sm.getString("webappLoader.failModifiedCheck"), e);
  -                continue;
  -            }
  -
  -            // Handle a need for reloading
  -            notifyContext();
  -            break;
  -
  -        }
  -
  -        if (log.isDebugEnabled())
  -            log.debug("BACKGROUND THREAD Stopping");
  -
  -    }
  -
  -
  -    // -------------------------------------- WebappContextNotifier Inner Class
  -
  -
  -    /**
  -     * Private thread class to notify our associated Context that we have
  -     * recognized the need for a reload.
  -     */
  -    protected class WebappContextNotifier implements Runnable {
  -
  -
  -        /**
  -         * Perform the requested notification.
  -         */
  -        public void run() {
  -
  -            ((Context) container).reload();
  -
  -        }
  -
  -
  -    }
   
       private static org.apache.commons.logging.Log log=
           org.apache.commons.logging.LogFactory.getLog( WebappLoader.class );
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message