Index: SMTPServer.java
===================================================================
RCS file: /home/cvspublic/jakarta-james/src/java/org/apache/james/smtpserver/SMTPServer.java,v
retrieving revision 1.4
diff -u -r1.4 SMTPServer.java
--- SMTPServer.java	1 Mar 2002 15:58:40 -0000	1.4
+++ SMTPServer.java	3 Jun 2002 16:03:47 -0000
@@ -2,78 +2,97 @@
  * Copyright (C) The Apache Software Foundation. All rights reserved.
  *
  * This software is published under the terms of the Apache Software License
- * version 1.1, a copy of which has been included with this distribution in
+ * version 1.1, a copy of which has been included  with this distribution in
  * the LICENSE file.
  */
+
 package org.apache.james.smtpserver;
 
-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.framework.component.Composable;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.configuration.Configurable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 
-import java.net.InetAddress;
-import java.net.UnknownHostException;
+import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
+
+import org.apache.james.core.AbstractServer;
 
 /**
+ * This is SMTPServer which task is to prepare properly connection handler, 
+ * SMTPHandler, to handle incoming connections.
  *
- * @version 1.1.0, 06/02/2001
- * @author  Federico Barbieri <scoobie@pop.systemy.it>
- * @author  Matthew Pangaro <mattp@lokitech.com>
- * @author  <a href="mailto:donaldp@apache.org">Peter Donald</a>
+ * @author Andrei Ivanov <myfam@surfeu.fi>
  */
-public class SMTPServer
-    extends AbstractService {
+public class SMTPServer extends AbstractServer {
 
-    protected ConnectionHandlerFactory createFactory()
-    {
-        return new DefaultHandlerFactory( SMTPHandler.class );
-    }
-
-    public void configure( final Configuration configuration )
-        throws ConfigurationException {
-
-        m_port = configuration.getChild( "port" ).getValueAsInteger( 25 );
-
-        try
-        {
-            final String bindAddress = configuration.getChild( "bind" ).getValue( null );
-            if( null != bindAddress )
-            {
-                m_bindTo = InetAddress.getByName( bindAddress );
-            }
-        }
-        catch( final UnknownHostException unhe )
-        {
-            throw new ConfigurationException( "Malformed bind parameter", unhe );
-        }
-
-        final boolean useTLS = configuration.getChild("useTLS").getValueAsBoolean( false );
-        if( useTLS ) {
-            m_serverSocketType = "ssl";
-        }
-
-       super.configure( configuration.getChild( "handler" ) );
-    }
-
-    public void initialize() throws Exception {
-        getLogger().info("SMTPServer init...");
-        super.initialize();
-        getLogger().info("SMTPServer ...init end");
-        System.out.println("Started SMTP Server "+m_connectionName);
-    }
+  public static final String AUTHREQ_NAME = "authRequired";
+  public static final String VERIFID_NAME = "verifyIdentity";   
+  public static final String MSGSIZE_NAME = "maxmessagesize";
+  public static final String LENRES_NAME = "lengthReset";
+  
+  /** Creates a new instance of SMTPServer */
+  public SMTPServer() {
+  }
+  
+  /**
+   * Pass the <code>Configuration</code> to the <code>Configurable</code>
+   * class. This method must always be called after the constructor
+   * and before any other method.
+   *
+   * @param configuration the class configurations.
+   * @throws ConfigurationException if an error occurs
+   */
+  public void configure(Configuration conf) throws ConfigurationException {  
+    super.configure(conf);
+    if (!this.enabled) return;    
+    this.configured = false;
+
+    boolean authRequired = conf.getChild(AUTHREQ_NAME).getValueAsBoolean(false);
+    handlerConf.setAttribute(AUTHREQ_NAME, authRequired + "");
+    
+    boolean verifyIdentity = conf.getChild(VERIFID_NAME).getValueAsBoolean(false);
+    handlerConf.setAttribute(VERIFID_NAME, verifyIdentity + "");    
+                   
+    // get the message size limit from the conf file and multiply
+    // by 1024, to put it in bytes
+    long maxmessagesize = conf.getChild(MSGSIZE_NAME).getValueAsLong(0)*1024;
+    handlerConf.setAttribute(MSGSIZE_NAME, maxmessagesize + "");        
+    getLogger().info("Max message size is: " + maxmessagesize);
+
+    //how many bytes to read before updating the timer that data is being transfered
+    int lengthReset = conf.getChild(LENRES_NAME).getValueAsInteger(20000);
+    handlerConf.setAttribute(LENRES_NAME, lengthReset + "");        
+    getLogger().info("Timer update length: " + lengthReset);
     
-    public void dispose()
-    {
-    	getLogger().info( "SMTPServer dispose..." );
-    	getLogger().info( "SMTPServer dispose..." + m_connectionName);
-    	super.dispose();
-       
-        // This is needed to make sure sockets are promptly closed on Windows 2000
-	System.gc();
-	
-	getLogger().info( "SMTPServer ...dispose end" );
-    }
+    this.configured = true;    
+  }
+    
+  /**
+   * Construct an appropriate ConnectionHandler.
+   *
+   * @return the new ConnectionHandler
+   * @exception Exception if an error occurs
+   */
+  public ConnectionHandler createConnectionHandler() throws Exception {
+    final SMTPHandler handler = new SMTPHandler();
+    setupLogger(handler);    
+    
+    if(handler instanceof Contextualizable) {
+      ((Contextualizable) handler).contextualize(context);
+    }    
+    if(handler instanceof Composable) {
+      ((Composable) handler).compose(compMgr);
+    }    
+    if(handler instanceof Configurable) {
+      ((Configurable) handler).configure(handlerConf);
+    }    
+    if(handler instanceof Initializable) {
+      ((Initializable) handler).initialize();
+    }    
+    return handler;
+  }
+  
 }
-
