Index: POP3Server.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/pop3server/POP3Server.java,v
retrieving revision 1.11
diff -u -r1.11 POP3Server.java
--- POP3Server.java	2 Oct 2002 06:12:02 -0000	1.11
+++ POP3Server.java	13 Oct 2002 17:53:23 -0000
@@ -6,14 +6,21 @@
  * the LICENSE file.
  */
 package org.apache.james.pop3server;
+
 import org.apache.avalon.cornerstone.services.connection.AbstractService;
 import org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory;
 import org.apache.avalon.cornerstone.services.connection.DefaultHandlerFactory;
+import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.component.Component;
+import org.apache.avalon.framework.component.Composable;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler;
+import org.apache.avalon.framework.component.ComponentException;
+import org.apache.avalon.framework.component.ComponentManager;
+
 /**
  * <p>Accepts POP3 connections on a server socket and dispatches them to POP3Handlers.</p>
  *
@@ -23,20 +30,56 @@
  * @author  Federico Barbieri <scoobie@pop.systemy.it>
  * @author  <a href="mailto:danny@apache.org">Danny Angus</a>
  */
-public class POP3Server extends AbstractService implements Component {
+public class POP3Server extends AbstractService implements Component, Composable {
 
     /**
      * Whether this service is enabled
      */
     private volatile boolean enabled = true;
 
+    /** 
+     * The scheduler is used schedule handler/server events. for
+     * example timeout monitor for connections.  there is a single
+     * scheduler for each server.  This provides a very lightweight
+     * mechanism. 
+     */
+    protected TimeScheduler scheduler; 
+
+    /** helps generate handler unique identifier. int operations are atomic */
+    private static int handlerIDCounter;
+
     /**
      * Creates a subclass specific handler factory for use by the superclass.
      *
      * @return a ConnectionHandlerFactory that produces POP3Handlers
      */
-    protected ConnectionHandlerFactory createFactory() {
-        return new DefaultHandlerFactory(POP3Handler.class);
+    protected final ConnectionHandlerFactory createFactory() {
+        return new DefaultHandlerFactory(POP3Handler.class) {
+                /**
+                 * Avalon does not expose an overridable create
+                 * handler method. If it did, this class would not be
+                 * needed.
+                 * 
+                 * TODO: ask avalon folks to provide an easy override
+                 * mechanism
+                 */
+                 protected ConnectionHandler newHandler()
+                    throws Exception
+                {
+                    ConnectionHandler handler = super.newHandler();
+                    configureHandler(handler);
+                    return handler;
+                }
+            };
+    }
+
+    /** pass server configuration to handler. Handlers may have server
+     * specific configuration */
+    protected void configureHandler(ConnectionHandler connHandler) {
+        POP3Handler handler = (POP3Handler)connHandler;
+        handler.setScheduler(scheduler);
+        handler.setID(m_port+":"+(handlerIDCounter++));
+        //System.out.println("POP3 handler: "+handler.getID());
     }
 
     /**
@@ -60,6 +103,17 @@
             }
             super.configure(configuration.getChild("handler"));
         }
+    }
+
+    /**
+     * @see org.apache.avalon.framework.component.Composable#compose(ComponentManager)
+     */
+    public void compose( final ComponentManager componentManager )
+        throws ComponentException 
+    {
+        super.compose(componentManager);
+        scheduler = (TimeScheduler)componentManager.
+            lookup( "org.apache.avalon.cornerstone.services.scheduler.TimeScheduler" );
     }
 
     /**
