You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by pg...@apache.org on 2002/10/28 20:38:37 UTC

cvs commit: jakarta-james/src/java/org/apache/james/util/watchdog SchedulerWatchdogFactory.java

pgoldstein    2002/10/28 11:38:37

  Modified:    src/java/org/apache/james/nntpserver NNTPServer.java
               src/java/org/apache/james/pop3server POP3Server.java
               src/java/org/apache/james/core AbstractJamesService.java
               src/java/org/apache/james/remotemanager RemoteManager.java
               src/java/org/apache/james/smtpserver SMTPServer.java
                        SMTPServer.xinfo
               src/java/org/apache/james/util/watchdog
                        SchedulerWatchdogFactory.java
  Log:
  Moved WatchdogFactory creation up to AbstractJamesService - Thanks to Noel Bergman
  Corrected SchedulerWatchdogFactory
  Added comments on how to implement a Scheduler based Watchdog in a service - Thanks to Noel
  
  Revision  Changes    Path
  1.13      +2 -5      jakarta-james/src/java/org/apache/james/nntpserver/NNTPServer.java
  
  Index: NNTPServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/NNTPServer.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- NNTPServer.java	26 Oct 2002 04:15:29 -0000	1.12
  +++ NNTPServer.java	28 Oct 2002 19:38:37 -0000	1.13
  @@ -27,7 +27,6 @@
   import org.apache.james.nntpserver.repository.NNTPRepository;
   import org.apache.james.services.UsersRepository;
   import org.apache.james.services.UsersStore;
  -import org.apache.james.util.watchdog.ThreadPerWatchdogFactory;
   import org.apache.james.util.watchdog.Watchdog;
   import org.apache.james.util.watchdog.WatchdogFactory;
   import org.apache.james.util.watchdog.WatchdogTarget;
  @@ -94,6 +93,7 @@
   
           repo = (NNTPRepository)componentManager
               .lookup("org.apache.james.nntpserver.repository.NNTPRepository");
  +
       }
   
       /**
  @@ -140,10 +140,7 @@
               ((Initializable)theHandlerPool).initialize();
           }
   
  -        theWatchdogFactory = new ThreadPerWatchdogFactory(threadPool, timeout);
  -        if (theWatchdogFactory instanceof LogEnabled) {
  -            ((LogEnabled)theWatchdogFactory).enableLogging(getLogger());
  -        }
  +        theWatchdogFactory = getWatchdogFactory();
       }
   
       /**
  
  
  
  1.13      +1 -5      jakarta-james/src/java/org/apache/james/pop3server/POP3Server.java
  
  Index: POP3Server.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/pop3server/POP3Server.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- POP3Server.java	26 Oct 2002 04:15:30 -0000	1.12
  +++ POP3Server.java	28 Oct 2002 19:38:37 -0000	1.13
  @@ -27,7 +27,6 @@
   import org.apache.james.services.MailServer;
   import org.apache.james.services.UsersRepository;
   import org.apache.james.services.UsersStore;
  -import org.apache.james.util.watchdog.ThreadPerWatchdogFactory;
   import org.apache.james.util.watchdog.Watchdog;
   import org.apache.james.util.watchdog.WatchdogFactory;
   import org.apache.james.util.watchdog.WatchdogTarget;
  @@ -139,10 +138,7 @@
               ((Initializable)theHandlerPool).initialize();
           }
   
  -        theWatchdogFactory = new ThreadPerWatchdogFactory(threadPool, timeout);
  -        if (theWatchdogFactory instanceof LogEnabled) {
  -            ((LogEnabled)theWatchdogFactory).enableLogging(getLogger());
  -        }
  +        theWatchdogFactory = getWatchdogFactory();
       }
   
       /**
  
  
  
  1.2       +20 -0     jakarta-james/src/java/org/apache/james/core/AbstractJamesService.java
  
  Index: AbstractJamesService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/core/AbstractJamesService.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractJamesService.java	26 Oct 2002 04:15:30 -0000	1.1
  +++ AbstractJamesService.java	28 Oct 2002 19:38:37 -0000	1.2
  @@ -26,6 +26,9 @@
   import org.apache.avalon.cornerstone.services.sockets.SocketManager;
   
   import org.apache.james.util.connection.SimpleConnectionManager;
  +import org.apache.james.util.watchdog.ThreadPerWatchdogFactory;
  +import org.apache.james.util.watchdog.Watchdog;
  +import org.apache.james.util.watchdog.WatchdogFactory;
   
   /**
    * Server which creates connection handlers. All new James servers must
  @@ -364,6 +367,23 @@
       
           getLogger().debug(getServiceType() + " ...dispose end");
       }
  +
  +    /**
  +     * This constructs the WatchdogFactory that will be used to guard
  +     * against runaway or stuck behavior.  Should only be called once
  +     * by a subclass in its initialize() method.
  +     *
  +     * @return the WatchdogFactory to be employed by subclasses.
  +     */
  +    protected WatchdogFactory getWatchdogFactory() {
  +        WatchdogFactory theWatchdogFactory = null;
  +        theWatchdogFactory = new ThreadPerWatchdogFactory(threadPool, timeout);
  +        if (theWatchdogFactory instanceof LogEnabled) {
  +            ((LogEnabled)theWatchdogFactory).enableLogging(getLogger());
  +        }
  +        return theWatchdogFactory;
  +     }
  +
   
       /**
        * Describes whether this service is enabled by configuration.
  
  
  
  1.12      +1 -5      jakarta-james/src/java/org/apache/james/remotemanager/RemoteManager.java
  
  Index: RemoteManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/remotemanager/RemoteManager.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- RemoteManager.java	26 Oct 2002 04:15:30 -0000	1.11
  +++ RemoteManager.java	28 Oct 2002 19:38:37 -0000	1.12
  @@ -25,7 +25,6 @@
   
   import org.apache.james.core.AbstractJamesService;
   import org.apache.james.services.*;
  -import org.apache.james.util.watchdog.ThreadPerWatchdogFactory;
   import org.apache.james.util.watchdog.Watchdog;
   import org.apache.james.util.watchdog.WatchdogFactory;
   import org.apache.james.util.watchdog.WatchdogTarget;
  @@ -148,10 +147,7 @@
               ((Initializable)theHandlerPool).initialize();
           }
   
  -        theWatchdogFactory = new ThreadPerWatchdogFactory(threadPool, timeout);
  -        if (theWatchdogFactory instanceof LogEnabled) {
  -            ((LogEnabled)theWatchdogFactory).enableLogging(getLogger());
  -        }
  +        theWatchdogFactory = getWatchdogFactory();
       }
   
       /**
  
  
  
  1.16      +1 -5      jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.java
  
  Index: SMTPServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SMTPServer.java	26 Oct 2002 17:33:03 -0000	1.15
  +++ SMTPServer.java	28 Oct 2002 19:38:37 -0000	1.16
  @@ -27,7 +27,6 @@
   import org.apache.james.services.MailServer;
   import org.apache.james.services.UsersRepository;
   import org.apache.james.services.UsersStore;
  -import org.apache.james.util.watchdog.ThreadPerWatchdogFactory;
   import org.apache.james.util.watchdog.Watchdog;
   import org.apache.james.util.watchdog.WatchdogFactory;
   import org.apache.james.util.watchdog.WatchdogTarget;
  @@ -193,10 +192,7 @@
               ((Initializable)theHandlerPool).initialize();
           }
   
  -        theWatchdogFactory = new ThreadPerWatchdogFactory(threadPool, timeout);
  -        if (theWatchdogFactory instanceof LogEnabled) {
  -            ((LogEnabled)theWatchdogFactory).enableLogging(getLogger());
  -        }
  +        theWatchdogFactory = getWatchdogFactory();
       }
   
       /**
  
  
  
  1.5       +1 -1      jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.xinfo
  
  Index: SMTPServer.xinfo
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.xinfo,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SMTPServer.xinfo	26 Oct 2002 04:15:30 -0000	1.4
  +++ SMTPServer.xinfo	28 Oct 2002 19:38:37 -0000	1.5
  @@ -35,5 +35,5 @@
       <dependency>
         <service name="org.apache.avalon.cornerstone.services.threads.ThreadManager" version="1.0"/>
       </dependency>
  -  </dependencies>  
  +  </dependencies>
   </blockinfo>
  
  
  
  1.2       +33 -2     jakarta-james/src/java/org/apache/james/util/watchdog/SchedulerWatchdogFactory.java
  
  Index: SchedulerWatchdogFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/util/watchdog/SchedulerWatchdogFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SchedulerWatchdogFactory.java	26 Oct 2002 04:15:31 -0000	1.1
  +++ SchedulerWatchdogFactory.java	28 Oct 2002 19:38:37 -0000	1.2
  @@ -15,6 +15,31 @@
    * This class is a factory to produce Watchdogs, each of which is associated
    * with a single TimeScheduler Target and a TimeScheduler object.
    *
  + * This could be used in James by adding a server configuration
  + * parameter:
  + *
  + *     schedulerWatchdogs = conf.getChild("useSchedulerWatchdogs").getValueAsBoolean(false);
  + *
  + * getting the TimeScheduler component:
  + *
  + *     scheduler = (TimeScheduler) compMgr.lookup(TimeScheduler.ROLE);
  + *
  + * and changing AbstractJamesService.getWatchdogFactory to look
  + * something like: 
  + *
  + *     protected WatchdogFactory getWatchdogFactory() {
  + *        WatchdogFactory theWatchdogFactory = null;
  + *        if (schedulerWatchdogs) {
  + *             theWatchdogFactory = new SchedulerWatchdogFactory(scheduler, timeout);
  + *           } else {
  + *             theWatchdogFactory = new ThreadPerWatchdogFactory(threadPool, timeout);
  + *           }
  + *        if (theWatchdogFactory instanceof LogEnabled) {
  + *             ((LogEnabled)theWatchdogFactory).enableLogging(getLogger());
  + *        }
  + *        return theWatchdogFactory;
  + *     }
  + *
    * @author Peter M. Goldstein <fa...@alum.mit.edu>
    */
   public class SchedulerWatchdogFactory implements WatchdogFactory {
  @@ -27,9 +52,15 @@
       private long timeout = -1;
   
       /**
  -     * Sets the TimeScheduler used to generate Watchdogs.
  +     * Creates the factory and sets the TimeScheduler used to implement
  +     * the watchdogs.
  +     *
  +     * @param theTimeScheduler the scheduler that manages Watchdog triggering
  +     *                         for Watchdogs produced by this factory
  +     * @param timeout the timeout for Watchdogs produced by this factory
        */
  -    public void setTimeScheduler(TimeScheduler theTimeScheduler) {
  +    public SchedulerWatchdogFactory(TimeScheduler theTimeScheduler, long timeout) {
  +        this.timeout = timeout;
           myTimeScheduler = theTimeScheduler;
       }
   
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>