Index: SMTPServer.java
===================================================================
RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.java,v
retrieving revision 1.13
diff -u -r1.13 SMTPServer.java
--- SMTPServer.java	2 Oct 2002 06:12:03 -0000	1.13
+++ SMTPServer.java	13 Oct 2002 18:02:46 -0000
@@ -14,10 +14,15 @@
 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 org.apache.mailet.MailetContext;
 import org.apache.james.Constants;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import org.apache.avalon.cornerstone.services.scheduler.TimeScheduler;
+import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
+import org.apache.avalon.framework.component.ComponentException;
+import org.apache.avalon.framework.component.ComponentManager;
 /**
  * <p>Accepts SMTP connections on a server socket and dispatches them to SMTPHandlers.</p>
  *
@@ -33,7 +38,7 @@
  * IMPORTANT: SMTPServer extends AbstractService.  If you implement ANY
  * lifecycle methods, you MUST call super.<method> as well.
  */
-public class SMTPServer extends AbstractService implements Component {
+public class SMTPServer extends AbstractService implements Component, Composable {
     /**
      * The mailet context - we access it here to set the hello name for the Mailet API
      */
@@ -44,8 +49,35 @@
      */
     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;
+
     protected ConnectionHandlerFactory createFactory() {
-        return new DefaultHandlerFactory(SMTPHandler.class);
+        return new DefaultHandlerFactory(SMTPHandler.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;
+                }
+            };
     }
 
     /**
@@ -54,6 +86,17 @@
     public void compose(final ComponentManager componentManager) throws ComponentException {
         super.compose(componentManager);
         mailetcontext = (MailetContext) componentManager.lookup("org.apache.mailet.MailetContext");
+        scheduler = (TimeScheduler)componentManager.
+            lookup( "org.apache.avalon.cornerstone.services.scheduler.TimeScheduler" );
+    }
+
+    /** pass server configuration to handler. Handlers may have server
+     * specific configuration */
+    protected void configureHandler(ConnectionHandler connHandler) {
+        SMTPHandler handler = (SMTPHandler)connHandler;
+        handler.setScheduler(scheduler);
+        handler.setID(m_port+":"+(handlerIDCounter++));
+        //System.out.println("SMTP handler: "+handler.getID());
     }
 
     /**
