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 no...@apache.org on 2009/11/25 22:17:14 UTC

svn commit: r884278 [1/2] - in /james/server/trunk: avalon-socket-library/src/main/java/org/apache/james/socket/ imapserver-function/src/main/java/org/apache/james/imapserver/ nntpserver-function/src/main/java/org/apache/james/nntpserver/ nntpserver-fu...

Author: norman
Date: Wed Nov 25 21:17:13 2009
New Revision: 884278

URL: http://svn.apache.org/viewvc?rev=884278&view=rev
Log:
Refactor server implementations to not extends AbstractProtocolServer anymore. The implementations are not aware of avalon anymore and are more decoupled

Added:
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServerProtocolHandlerFactory.java
      - copied, changed from r833892, james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java
    james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServerMBeanImpl.java
    james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServerProtocolHandlerFactory.java
      - copied, changed from r833856, james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServer.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3ServerMBeanImpl.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3ServerProtocolServerHandlerFactory.java
      - copied, changed from r833856, james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java
    james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerMBeanImpl.java
    james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerProtocolHandlerFactory.java
      - copied, changed from r833856, james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManager.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServerMBeanImpl.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServerProtocolHandlerFactory.java
      - copied, changed from r833856, james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java
    james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/AbstractProtocolHandlerFactory.java
    james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/AbstractSupportLoaderProtocolHandlerFactory.java
Removed:
    james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractProtocolServer.java
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java
    james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServer.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java
    james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManager.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServerComposed.java
    james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerComposedTest.java
Modified:
    james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AvalonProtocolServer.java
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/AvalonImapServer.java
    james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/AvalonNNTPServer.java
    james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/NNTPServerTest.java
    james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/AvalonPOP3Server.java
    james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
    james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/AvalonRemoteManager.java
    james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTest.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/AvalonSMTPServer.java
    james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
    james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/ProtocolHandlerFactory.java
    james/server/trunk/socket-api/src/main/java/org/apache/james/socket/api/ProtocolServer.java

Modified: james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AvalonProtocolServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AvalonProtocolServer.java?rev=884278&r1=884277&r2=884278&view=diff
==============================================================================
--- james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AvalonProtocolServer.java (original)
+++ james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AvalonProtocolServer.java Wed Nov 25 21:17:13 2009
@@ -91,10 +91,6 @@
      */
     private static final String BACKLOG_NAME = "connectionBacklog";
 
-    /**
-     * The name of the parameter defining the service hello name.
-     */
-    private static final String HELLO_NAME = "helloName";
 
     /**
      * The ConnectionManager that spawns and manages service connections.
@@ -158,11 +154,6 @@
     private int backlog;
 
     /**
-     * The hello name for the service.
-     */
-    private String helloName;
-
-    /**
      * Whether this service is enabled.
      */
     private volatile boolean enabled;
@@ -368,8 +359,6 @@
             throw new ConfigurationException( "Malformed bind parameter in configuration of service " + protocolHandlerFactory.getServiceType(), unhe );
         }
 
-        configureHelloName(handlerConfiguration);
-
         timeout = handlerConfiguration.getInteger(TIMEOUT_NAME, DEFAULT_TIMEOUT);
 
         infoBuffer =
@@ -486,42 +475,6 @@
         this.streamDumpDir = streamdumpDir;
     }
     
-    private void configureHelloName(HierarchicalConfiguration handlerConfiguration) {
-        StringBuilder infoBuffer;
-        String hostName = null;
-        try {
-            hostName = dnsService.getHostName(dnsService.getLocalHost());
-        } catch (UnknownHostException ue) {
-            hostName = "localhost";
-        }
-
-        infoBuffer =
-            new StringBuilder(64)
-                    .append(protocolHandlerFactory.getServiceType())
-                    .append(" is running on: ")
-                    .append(hostName);
-        getLog().info(infoBuffer.toString());
-
-        
- 
-        if (handlerConfiguration.getKeys(HELLO_NAME).hasNext()) {
-            boolean autodetect = handlerConfiguration.getBoolean(HELLO_NAME +".[@autodetect]", true);
-            if (autodetect) {
-                helloName = hostName;
-            } else {
-                // Should we use the defaultdomain here ?
-                helloName = handlerConfiguration.getString(HELLO_NAME, "localhost");
-            }
-        } else {
-            helloName = null;
-        }
-        infoBuffer =
-            new StringBuilder(64)
-                    .append(protocolHandlerFactory.getServiceType())
-                    .append(" handler hello name is: ")
-                    .append(helloName);
-        getLog().info(infoBuffer.toString());
-    }
 
 
     @Override
@@ -540,16 +493,18 @@
         if (serviceManager == null) {
             serviceManager = new DefaultServiceManager();
         }
-        ContainerUtil.service(this, serviceManager);
+       
         // parse configuration
         configure();
 
+
+        
         if (!isEnabled()) {
             getLog().info(protocolHandlerFactory.getServiceType() + " Disabled");
             return;
         }      
         
-        protocolHandlerFactory.prepare(this);
+        service(serviceManager);
 
         if (useStartTLS) {
         	initStartTLS();
@@ -568,9 +523,6 @@
         ContainerUtil.initialize(theHandlerPool);
 
         theWatchdogFactory = getWatchdogFactory();
-
-        // Allow subclasses to perform initialisation
-        protocolHandlerFactory.doInit();
     }
     
     private void initStartTLS() throws Exception {
@@ -850,7 +802,7 @@
     * 
     * @return String The network interface name     
     */  
-    public String  getNetworkInterface() {
+    public String getNetworkInterface() {
         if (bindTo == null) {
             return "All";
         } else {
@@ -859,10 +811,8 @@
     }
     
     /**
-    * Returns the server socket type, plain or SSL 
-    * 
-    * @return String The socket type, plain or SSL     
-    */  
+     * @see org.apache.james.socket.api.ProtocolServer#getSocketType()
+     */
     public String  getSocketType() {
         return serverSocketType;
     }
@@ -916,15 +866,5 @@
     public Class getCreatedClass() {
         return JamesConnectionBridge.class;
     }
-
-
-    public boolean useStartTLS() {
-    	return useStartTLS;
-    }
-    
-    public String getHelloName() {
-        return helloName;
-    }
-
 }
 

Modified: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/AvalonImapServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/AvalonImapServer.java?rev=884278&r1=884277&r2=884278&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/AvalonImapServer.java (original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/AvalonImapServer.java Wed Nov 25 21:17:13 2009
@@ -38,8 +38,10 @@
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.services.FileSystem;
 import org.apache.james.services.MailServer;
+import org.apache.james.socket.AvalonProtocolServer;
 import org.apache.james.socket.JamesConnectionManager;
 import org.apache.james.socket.api.ProtocolHandlerFactory;
+import org.apache.james.socket.api.ProtocolServer;
 import org.apache.james.util.ConfigurationAdapter;
 import org.apache.james.bridge.GuiceInjected;
 import org.apache.jsieve.mailet.Poster;
@@ -48,8 +50,6 @@
 
 import com.google.inject.AbstractModule;
 import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.Provider;
 import com.google.inject.name.Names;
 
 public class AvalonImapServer implements GuiceInjected, Poster, Initializable, Serviceable, Configurable, LogEnabled {
@@ -58,11 +58,10 @@
     private DNSService dns;
     private Log logger;
     private org.apache.commons.configuration.HierarchicalConfiguration config;
-    private Injector injector;
     private UsersRepository userRepos;
     private JamesConnectionManager connectionManager;
     private SocketManager socketManager;
-    private ImapServer imapserver = new ImapServer();
+    private Poster poster;
     private ThreadManager threadManager;
 
 
@@ -88,16 +87,13 @@
         socketManager = (SocketManager) manager.lookup(SocketManager.ROLE);
         connectionManager = (JamesConnectionManager) manager.lookup(JamesConnectionManager.ROLE);     
         threadManager = (ThreadManager) manager.lookup(ThreadManager.ROLE);
-        // thats needed because of used excalibur socket components
-        imapserver.service(manager);
     }
 
     /**
      * @see org.apache.avalon.framework.activity.Initializable#initialize()
      */
     public void initialize() throws Exception {
-        injector = Guice.createInjector(new IMAPServerModule(), new Jsr250Module());
-        injector.injectMembers(imapserver);
+        poster = Guice.createInjector(new IMAPServerModule(), new Jsr250Module()).getInstance(ImapServerProtocolHandlerFactory.class);
     }
                  
     /**
@@ -117,13 +113,8 @@
             bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
             bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(filesystem);
             bind(UsersRepository.class).annotatedWith(Names.named("org.apache.james.api.user.UsersRepository")).toInstance(userRepos);
-            bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).toProvider(new Provider<ProtocolHandlerFactory>() {
-
-                public ProtocolHandlerFactory get() {
-                    return imapserver;
-                }
-                
-            });
+            bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).to(ImapServerProtocolHandlerFactory.class);
+            bind(ProtocolServer.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolServer")).to(AvalonProtocolServer.class);
             bind(SocketManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.sockets.SocketManager")).toInstance(socketManager);
             bind(JamesConnectionManager.class).annotatedWith(Names.named("org.apache.james.socket.JamesConnectionManager")).toInstance(connectionManager);
             bind(ThreadManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.threads.ThreadManager")).toInstance(threadManager);
@@ -132,7 +123,7 @@
     }
 
     public void post(String url, MimeMessage mail) throws MessagingException {
-        imapserver.post(url, mail);
+        poster.post(url, mail);
     }
 
 }

Copied: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServerProtocolHandlerFactory.java (from r833892, james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServerProtocolHandlerFactory.java?p2=james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServerProtocolHandlerFactory.java&p1=james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java&r1=833892&r2=884278&rev=884278&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java (original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServerProtocolHandlerFactory.java Wed Nov 25 21:17:13 2009
@@ -37,7 +37,8 @@
 import org.apache.james.imap.mailbox.MailboxManager;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.main.ImapRequestHandler;
-import org.apache.james.socket.AbstractProtocolServer;
+import org.apache.james.services.FileSystem;
+import org.apache.james.socket.api.AbstractProtocolHandlerFactory;
 import org.apache.james.socket.api.ProtocolHandler;
 import org.apache.jsieve.mailet.Poster;
 
@@ -49,7 +50,7 @@
  *
  * <p>Also responsible for loading and parsing IMAP specific configuration.</p>
  */
-public class ImapServer extends AbstractProtocolServer implements ImapConstants, Poster
+public class ImapServerProtocolHandlerFactory extends AbstractProtocolHandlerFactory implements ImapConstants, Poster
 {
     private static final String softwaretype = "JAMES "+VERSION+" Server " + Constants.SOFTWARE_VERSION;
      
@@ -60,10 +61,18 @@
     private UsersRepository usersRepos;
     private HierarchicalConfiguration configuration;
 
+    private FileSystem fSystem;
+
     @Resource(name="org.apache.james.api.user.UsersRepository")
     public void setUsersRepository(UsersRepository usersRepos) {
         this.usersRepos = usersRepos;
     }
+    
+    @Resource(name="org.apache.james.services.FileSystem")
+    public void setFileSystem(FileSystem fSystem) {
+        this.fSystem = fSystem;
+    }
+    
 
     @PostConstruct
     @Override
@@ -72,9 +81,9 @@
     }
 
     @Override
-    public  void doInit() throws Exception {
-        getLog().debug("Initialising...");
-        factory = new DefaultImapFactory(getFileSystem(), usersRepos, getLog());
+    public  void onInit() throws Exception {
+        getLogger().debug("Initialising...");
+        factory = new DefaultImapFactory(fSystem, usersRepos, getLogger());
         factory.configure(configuration);
 
         factory.init();
@@ -110,7 +119,7 @@
     {  
         final ImapRequestHandler handler = factory.createHandler();
         final ImapHandler imapHandler = new ImapHandler(handler, hello); 
-        getLog().debug("Create handler instance");
+        getLogger().debug("Create handler instance");
         return imapHandler;
     }
     
@@ -146,7 +155,7 @@
                             urlPath = url.substring(endOfHost, length);
                         }
                         final MailboxManager mailboxManager = factory.getMailbox();
-                        final MailboxSession session = mailboxManager.createSystemSession(user, getLog());
+                        final MailboxSession session = mailboxManager.createSystemSession(user, getLogger());
                         // This allows Sieve scripts to use a standard delimiter regardless of mailbox implementation
                         final String mailbox = urlPath.replace('/', session.getPersonalSpace().getDeliminator());
                         postToMailbox(user, mail, mailbox, session, mailboxManager);

Modified: james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/AvalonNNTPServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/AvalonNNTPServer.java?rev=884278&r1=884277&r2=884278&view=diff
==============================================================================
--- james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/AvalonNNTPServer.java (original)
+++ james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/AvalonNNTPServer.java Wed Nov 25 21:17:13 2009
@@ -38,8 +38,10 @@
 import org.apache.james.nntpserver.repository.NNTPRepository;
 import org.apache.james.services.FileSystem;
 import org.apache.james.services.MailServer;
+import org.apache.james.socket.AvalonProtocolServer;
 import org.apache.james.socket.JamesConnectionManager;
 import org.apache.james.socket.api.ProtocolHandlerFactory;
+import org.apache.james.socket.api.ProtocolServer;
 import org.apache.james.util.ConfigurationAdapter;
 import org.guiceyfruit.jsr250.Jsr250Module;
 
@@ -59,24 +61,24 @@
     private UsersRepository userRepos;
     private JamesConnectionManager connectionManager;
     private SocketManager socketManager;
-    private NNTPServer nntpserver = new NNTPServer();
+    private NNTPServerMBean mbean;
     private NNTPRepository nntpRepos;
     private ThreadManager threadManager;
     
     public String getNetworkInterface() {
-        return nntpserver.getNetworkInterface();
+        return mbean.getNetworkInterface();
     }
 
     public int getPort() {
-        return nntpserver.getPort();
+        return mbean.getPort();
     }
 
     public String getSocketType() {
-        return nntpserver.getSocketType();
+        return mbean.getSocketType();
     }
 
     public boolean isEnabled() {
-        return nntpserver.isEnabled();
+        return mbean.isEnabled();
     }
 
     /**
@@ -108,7 +110,7 @@
      * @see org.apache.avalon.framework.activity.Initializable#initialize()
      */
     public void initialize() throws Exception {
-        nntpserver = Guice.createInjector(new NNTPServerModule(), new Jsr250Module()).getInstance(NNTPServer.class);
+        mbean = Guice.createInjector(new NNTPServerModule(), new Jsr250Module()).getInstance(NNTPServerMBeanImpl.class);
     }
                  
     /**
@@ -128,17 +130,12 @@
             bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
             bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(filesystem);
             bind(UsersRepository.class).annotatedWith(Names.named("org.apache.james.api.user.UsersRepository")).toInstance(userRepos);
-            bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).toProvider(new Provider<ProtocolHandlerFactory>() {
-
-                public ProtocolHandlerFactory get() {
-                    return nntpserver;
-                }
-                
-            });
+            bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).to(NNTPServerProtocolHandlerFactory.class);
             bind(SocketManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.sockets.SocketManager")).toInstance(socketManager);
             bind(JamesConnectionManager.class).annotatedWith(Names.named("org.apache.james.socket.JamesConnectionManager")).toInstance(connectionManager);
             bind(ThreadManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.threads.ThreadManager")).toInstance(threadManager);
             bind(NNTPRepository.class).annotatedWith(Names.named("org.apache.james.nntpserver.repository.NNTPRepository")).toInstance(nntpRepos);
+            bind(ProtocolServer.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolServer")).to(AvalonProtocolServer.class);
             // we bind the LoaderService to an Provider to get sure everything is there when the SMTPLoaderService get created.
             bind(LoaderService.class).annotatedWith(Names.named("org.apache.james.LoaderService")).toProvider(new Provider<LoaderService>() {
 

Added: james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServerMBeanImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServerMBeanImpl.java?rev=884278&view=auto
==============================================================================
--- james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServerMBeanImpl.java (added)
+++ james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServerMBeanImpl.java Wed Nov 25 21:17:13 2009
@@ -0,0 +1,66 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+package org.apache.james.nntpserver;
+
+import javax.annotation.Resource;
+
+import org.apache.james.socket.api.ProtocolServer;
+
+public class NNTPServerMBeanImpl implements NNTPServerMBean{
+
+
+    private ProtocolServer server;
+
+    @Resource(name="org.apache.james.socket.api.ProtocolServer")
+    public void setProtocolServer(ProtocolServer server) {
+        this.server = server;
+    }
+    
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getNetworkInterface()
+     */
+    public String getNetworkInterface() {
+        return server.getNetworkInterface();
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getPort()
+     */
+    public int getPort() {
+        return server.getPort();
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getSocketType()
+     */
+    public String getSocketType() {
+        return server.getSocketType();
+    }
+
+    /**
+     * (non-Javadoc)
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#isEnabled()
+     */
+    public boolean isEnabled() {
+        return server.isEnabled();
+    }
+
+}

Copied: james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServerProtocolHandlerFactory.java (from r833856, james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServer.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServerProtocolHandlerFactory.java?p2=james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServerProtocolHandlerFactory.java&p1=james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServer.java&r1=833856&r2=884278&rev=884278&view=diff
==============================================================================
--- james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServer.java (original)
+++ james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServerProtocolHandlerFactory.java Wed Nov 25 21:17:13 2009
@@ -29,14 +29,14 @@
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.nntpserver.repository.NNTPRepository;
 import org.apache.james.services.MailServer;
-import org.apache.james.socket.AbstractProtocolServer;
+import org.apache.james.socket.api.AbstractProtocolHandlerFactory;
 import org.apache.james.socket.api.ProtocolHandler;
 
 /**
  * NNTP Server
  *
  */
-public class NNTPServer extends AbstractProtocolServer implements NNTPServerMBean {
+public class NNTPServerProtocolHandlerFactory extends AbstractProtocolHandlerFactory {
 
     /**
      * Whether authentication is required to access this NNTP server
@@ -95,16 +95,15 @@
     }
 
     protected void onConfigure(final HierarchicalConfiguration configuration) throws ConfigurationException {
-        if (isEnabled()) {
-            authRequired = configuration.getBoolean("handler.authRequired", false);
-            if (getLog().isDebugEnabled()) {
-                if (authRequired) {
-                    getLog().debug("NNTP Server requires authentication.");
-                } else {
-                    getLog().debug("NNTP Server doesn't require authentication.");
-                }
+        authRequired = configuration.getBoolean("handler.authRequired", false);
+        if (getLogger().isDebugEnabled()) {
+            if (authRequired) {
+                getLogger().debug("NNTP Server requires authentication.");
+            } else {
+                getLogger().debug("NNTP Server doesn't require authentication.");
             }
         }
+
     }
 
     /**
@@ -139,10 +138,10 @@
          * @see org.apache.james.nntpserver.NNTPHandlerConfigurationData#getHelloName()
          */
         public String getHelloName() {
-            if (NNTPServer.this.getHelloName() == null) {
-                return NNTPServer.this.mailServer.getHelloName();
+            if (NNTPServerProtocolHandlerFactory.this.getHelloName() == null) {
+                return NNTPServerProtocolHandlerFactory.this.mailServer.getHelloName();
             } else {
-                return NNTPServer.this.getHelloName();
+                return NNTPServerProtocolHandlerFactory.this.getHelloName();
             }
         }
 
@@ -150,22 +149,21 @@
          * @see org.apache.james.nntpserver.NNTPHandlerConfigurationData#isAuthRequired()
          */
         public boolean isAuthRequired() {
-            return NNTPServer.this.authRequired;
+            return NNTPServerProtocolHandlerFactory.this.authRequired;
         }
 
         /**
          * @see org.apache.james.nntpserver.NNTPHandlerConfigurationData#getUsersRepository()
          */
         public UsersRepository getUsersRepository() {
-            return NNTPServer.this.userRepository;
+            return NNTPServerProtocolHandlerFactory.this.userRepository;
         }
 
         /**
          * @see org.apache.james.nntpserver.NNTPHandlerConfigurationData#getNNTPRepository()
          */
         public NNTPRepository getNNTPRepository() {
-            return NNTPServer.this.nntpRepository;
+            return NNTPServerProtocolHandlerFactory.this.nntpRepository;
         }
-
     }
 }

Modified: james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/NNTPServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/NNTPServerTest.java?rev=884278&r1=884277&r2=884278&view=diff
==============================================================================
--- james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/NNTPServerTest.java (original)
+++ james/server/trunk/nntpserver-function/src/test/java/org/apache/james/nntpserver/NNTPServerTest.java Wed Nov 25 21:17:13 2009
@@ -43,6 +43,7 @@
 import org.apache.james.nntpserver.repository.NNTPRepositoryImpl;
 import org.apache.james.services.FileSystem;
 import org.apache.james.services.MailServer;
+import org.apache.james.socket.AvalonProtocolServer;
 import org.apache.james.socket.JamesConnectionManager;
 import org.apache.james.socket.SimpleConnectionManager;
 import org.apache.james.test.mock.avalon.MockLogger;
@@ -57,7 +58,8 @@
 public class NNTPServerTest extends TestCase {
 	protected int m_nntpListenerPort = Util.getNonPrivilegedPort();
 
-	private NNTPServer m_nntpServer;
+	private NNTPServerProtocolHandlerFactory m_nntpServer;
+	private AvalonProtocolServer protoserver;
 	protected FakeLoader serviceManager;
 
 	private MockUsersRepository m_usersRepository;
@@ -78,31 +80,40 @@
     private DNSService dnsService;
 
     protected void setUp() throws Exception {
-        m_nntpServer = new NNTPServer();
         setUpServiceManager();
 
-        ContainerUtil.service(m_nntpServer, serviceManager);
-
-        ContainerUtil.enableLogging(m_nntpServer, new MockLogger());
-
+        m_nntpServer = new NNTPServerProtocolHandlerFactory();
         m_nntpServer.setLog(new SimpleLog("MockLog"));
-        m_nntpServer.setConnectionManager(connectionManager);
         m_nntpServer.setDNSService(dnsService);
-        m_nntpServer.setFileSystem(new MockFileSystem());
-        m_nntpServer.setMailServer(m_mailServer);
         m_nntpServer.setUserRepository(m_usersRepository);
-        m_nntpServer.setProtocolHandlerFactory(m_nntpServer);
-        m_nntpServer.setSocketManager(socketManager);
-        m_nntpServer.setThreadManager(threadManager);
+        m_nntpServer.setMailServer(m_mailServer);
         m_nntpServer.setNNTPRepository(nntpRepos);
+
+
+        //ContainerUtil.service(m_nntpServer, serviceManager);
+
+        //ContainerUtil.enableLogging(m_nntpServer, new MockLogger());
+        protoserver = new AvalonProtocolServer();
+        protoserver.setConnectionManager(connectionManager);
+        protoserver.setFileSystem(new MockFileSystem());
+        protoserver.setProtocolHandlerFactory(m_nntpServer);
+        protoserver.setSocketManager(socketManager);
+        protoserver.setThreadManager(threadManager);
+        protoserver.setDNSService(dnsService);
+        protoserver.setLog(new SimpleLog("MockLog"));
+
         m_testConfiguration = new NNTPTestConfiguration(m_nntpListenerPort);
     }
 
     protected void finishSetUp(NNTPTestConfiguration testConfiguration)
 			throws Exception {
 		testConfiguration.init();
-		m_nntpServer.setConfiguration(new ConfigurationAdapter(testConfiguration));
+		ConfigurationAdapter conf = new ConfigurationAdapter(testConfiguration);
+		m_nntpServer.setConfiguration(conf);
 		m_nntpServer.init();
+		
+		protoserver.setConfiguration(conf);
+		protoserver.init();
 	}
 
     protected void setUpServiceManager() throws ServiceException {
@@ -167,9 +178,7 @@
 		if (m_nntpProtocol != null) {
 			m_nntpProtocol.sendCommand("quit");
 			m_nntpProtocol.disconnect();
-		}
-		m_nntpServer.dispose();
-		
+		}		
 		ContainerUtil.dispose(m_mailServer);
 
 		super.tearDown();

Modified: james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java?rev=884278&r1=884277&r2=884278&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java (original)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java Wed Nov 25 21:17:13 2009
@@ -48,6 +48,7 @@
 import org.apache.james.api.user.UsersRepository;
 import org.apache.james.core.MailImpl;
 import org.apache.james.services.MailServer;
+import org.apache.james.socket.AvalonProtocolServer;
 import org.apache.james.socket.JamesConnectionManager;
 import org.apache.james.socket.SimpleConnectionManager;
 import org.apache.james.test.mock.avalon.MockLogger;
@@ -153,7 +154,9 @@
     private int m_smtpListenerPort = Util.getNonPrivilegedPort();
     private MockMailServer m_mailServer;
     private SMTPTestConfiguration m_testConfiguration;
-    private SMTPServer m_smtpServer;
+    private SMTPServerProtocolHandlerFactory m_smtpServer;
+    private AvalonProtocolServer protoserver;
+    
     private MockUsersRepository m_usersRepository = new MockUsersRepository();
     private SimpleConnectionManager connectionManager;
     private FakeMailContext mailetContext;
@@ -184,20 +187,25 @@
     }
     
     protected void setUp() throws Exception {
-        m_smtpServer = new SMTPServer();
+        m_smtpServer = new SMTPServerProtocolHandlerFactory();
         ContainerUtil.enableLogging(m_smtpServer,new MockLogger());
         m_serviceManager = setUpServiceManager();
         ContainerUtil.service(m_smtpServer, m_serviceManager);
         m_smtpServer.setLoader(m_serviceManager);
-        m_smtpServer.setConnectionManager(connectionManager);
         m_smtpServer.setDNSService(m_dnsServer);
-        m_smtpServer.setFileSystem(new MockFileSystem());
         m_smtpServer.setLog(new SimpleLog("Test"));
         m_smtpServer.setMailServer(m_mailServer);
         m_smtpServer.setMailetContext(mailetContext);
-        m_smtpServer.setProtocolHandlerFactory(m_smtpServer);
-        m_smtpServer.setSocketManager(socketManager);
-        m_smtpServer.setThreadManager(threadManager);
+        
+        protoserver = new AvalonProtocolServer();
+        protoserver.setConnectionManager(connectionManager);
+        protoserver.setFileSystem(new MockFileSystem());
+        protoserver.setProtocolHandlerFactory(m_smtpServer);
+        protoserver.setSocketManager(socketManager);
+        protoserver.setThreadManager(threadManager);
+        protoserver.setDNSService(m_dnsServer);
+        protoserver.setLog(new SimpleLog("Test"));
+
         m_testConfiguration = new SMTPTestConfiguration(m_smtpListenerPort);
     }
 
@@ -208,8 +216,12 @@
 
     private void finishSetUp(SMTPTestConfiguration testConfiguration) throws Exception {
         testConfiguration.init();
-        m_smtpServer.setConfiguration(new ConfigurationAdapter(testConfiguration));
+        ConfigurationAdapter conf = new ConfigurationAdapter(testConfiguration);
+        m_smtpServer.setConfiguration(conf);
         m_smtpServer.init();
+        
+        protoserver.setConfiguration(conf);
+        protoserver.init();
         m_mailServer.setMaxMessageSizeBytes(m_testConfiguration.getMaxMessageSize()*1024);
     }
 

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/AvalonPOP3Server.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/AvalonPOP3Server.java?rev=884278&r1=884277&r2=884278&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/AvalonPOP3Server.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/AvalonPOP3Server.java Wed Nov 25 21:17:13 2009
@@ -37,8 +37,10 @@
 import org.apache.james.bridge.GuiceInjected;
 import org.apache.james.services.FileSystem;
 import org.apache.james.services.MailServer;
+import org.apache.james.socket.AvalonProtocolServer;
 import org.apache.james.socket.JamesConnectionManager;
 import org.apache.james.socket.api.ProtocolHandlerFactory;
+import org.apache.james.socket.api.ProtocolServer;
 import org.apache.james.util.ConfigurationAdapter;
 import org.guiceyfruit.jsr250.Jsr250Module;
 
@@ -58,23 +60,23 @@
     private UsersRepository userRepos;
     private JamesConnectionManager connectionManager;
     private SocketManager socketManager;
-    private POP3Server pop3server = new POP3Server();
     private ThreadManager threadManager;
+    private POP3ServerMBean mbean;
     
     public String getNetworkInterface() {
-        return pop3server.getNetworkInterface();
+        return mbean.getNetworkInterface();
     }
 
     public int getPort() {
-        return pop3server.getPort();
+        return mbean.getPort();
     }
 
     public String getSocketType() {
-        return pop3server.getSocketType();
+        return mbean.getSocketType();
     }
 
     public boolean isEnabled() {
-        return pop3server.isEnabled();
+        return mbean.isEnabled();
     }
 
     /**
@@ -105,7 +107,7 @@
      * @see org.apache.avalon.framework.activity.Initializable#initialize()
      */
     public void initialize() throws Exception {
-        pop3server = Guice.createInjector(new POP3ServerModule(), new Jsr250Module()).getInstance(POP3Server.class);
+        mbean = Guice.createInjector(new POP3ServerModule(), new Jsr250Module()).getInstance(POP3ServerMBeanImpl.class);
     }
                  
     /**
@@ -125,13 +127,9 @@
             bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
             bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(filesystem);
             bind(UsersRepository.class).annotatedWith(Names.named("org.apache.james.api.user.UsersRepository")).toInstance(userRepos);
-            bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).toProvider(new Provider<ProtocolHandlerFactory>() {
+            bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).to(POP3ServerProtocolServerHandlerFactory.class);
+            bind(ProtocolServer.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolServer")).to(AvalonProtocolServer.class);
 
-                public ProtocolHandlerFactory get() {
-                    return pop3server;
-                }
-                
-            });
             bind(SocketManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.sockets.SocketManager")).toInstance(socketManager);
             bind(JamesConnectionManager.class).annotatedWith(Names.named("org.apache.james.socket.JamesConnectionManager")).toInstance(connectionManager);
             bind(ThreadManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.threads.ThreadManager")).toInstance(threadManager);

Added: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3ServerMBeanImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3ServerMBeanImpl.java?rev=884278&view=auto
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3ServerMBeanImpl.java (added)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3ServerMBeanImpl.java Wed Nov 25 21:17:13 2009
@@ -0,0 +1,66 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+package org.apache.james.pop3server;
+
+import javax.annotation.Resource;
+
+import org.apache.james.socket.api.ProtocolServer;
+
+public class POP3ServerMBeanImpl implements POP3ServerMBean{
+
+
+    private ProtocolServer server;
+
+    @Resource(name="org.apache.james.socket.api.ProtocolServer")
+    public void setProtocolServer(ProtocolServer server) {
+        this.server = server;
+    }
+    
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getNetworkInterface()
+     */
+    public String getNetworkInterface() {
+        return server.getNetworkInterface();
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getPort()
+     */
+    public int getPort() {
+        return server.getPort();
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getSocketType()
+     */
+    public String getSocketType() {
+        return server.getSocketType();
+    }
+
+    /**
+     * (non-Javadoc)
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#isEnabled()
+     */
+    public boolean isEnabled() {
+        return server.isEnabled();
+    }
+
+}

Copied: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3ServerProtocolServerHandlerFactory.java (from r833856, james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3ServerProtocolServerHandlerFactory.java?p2=james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3ServerProtocolServerHandlerFactory.java&p1=james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java&r1=833856&r2=884278&rev=884278&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3ServerProtocolServerHandlerFactory.java Wed Nov 25 21:17:13 2009
@@ -26,12 +26,10 @@
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.james.api.kernel.LoaderService;
 import org.apache.james.pop3server.core.CoreCmdHandlerLoader;
 import org.apache.james.services.MailServer;
-import org.apache.james.socket.AbstractProtocolServer;
+import org.apache.james.socket.api.AbstractSupportLoaderProtocolHandlerFactory;
 import org.apache.james.socket.api.ProtocolHandler;
-import org.apache.james.socket.shared.ProtocolHandlerChainImpl;
 
 /**
  * <p>Accepts POP3 connections on a server socket and dispatches them to POP3Handlers.</p>
@@ -40,13 +38,7 @@
  *
  * @version 1.0.0, 24/04/1999
  */
-public class POP3Server extends AbstractProtocolServer implements POP3ServerMBean {
-
-    /**
-     * The handler chain - POP3handlers can lookup handlerchain to obtain
-     * Command handlers , Message handlers and connection handlers
-     */
-    private ProtocolHandlerChainImpl handlerChain;
+public class POP3ServerProtocolServerHandlerFactory extends AbstractSupportLoaderProtocolHandlerFactory {
 
     /**
      * The internal mail server service
@@ -68,32 +60,15 @@
         = new POP3HandlerConfigurationDataImpl();
 
 
-    private LoaderService loader;
+    private boolean useStartTLS;
+
 
-    private HierarchicalConfiguration handlerConfiguration;
 
     @Resource(name="org.apache.james.services.MailServer")
     public void setMailServer(MailServer mailServer) {
         this.mailServer = mailServer;
     }
 
-    /**
-     * Gets the current instance loader.
-     * @return the loader
-     */
-    public final LoaderService getLoader() {
-        return loader;
-    }
-
-    /**
-     * Sets the loader to be used for instances.
-     * @param loader the loader to set, not null
-     */
-    @Resource(name="org.apache.james.LoaderService")
-    public final void setLoader(LoaderService loader) {
-        this.loader = loader;
-    }
-
     @PostConstruct
     @Override
     public void init() throws Exception {
@@ -102,36 +77,16 @@
     
     @Override
     protected void onConfigure(final HierarchicalConfiguration configuration) throws ConfigurationException {
-        if (isEnabled()) {
-            HierarchicalConfiguration handlerConfiguration = configuration.configurationAt("handler");
-            lengthReset = handlerConfiguration.getInteger("lengthReset",lengthReset);
-            if (getLog().isInfoEnabled()) {
-                getLog().info("The idle timeout will be reset every " + lengthReset + " bytes.");
-            }
-            
-            this.handlerConfiguration = handlerConfiguration;
+        super.onConfigure(configuration);
+        HierarchicalConfiguration handlerConfiguration = configuration.configurationAt("handler");
+        lengthReset = handlerConfiguration.getInteger("lengthReset", lengthReset);
+        if (getLogger().isInfoEnabled()) {
+            getLogger().info("The idle timeout will be reset every " + lengthReset + " bytes.");
         }
-    }
-    
-    private void prepareHandlerChain() throws Exception {
-
-        handlerChain = loader.load(ProtocolHandlerChainImpl.class);
-        
-        //set the logger
-        handlerChain.setLog(getLog());
         
-        //read from the XML configuration and create and configure each of the handlers
-        HierarchicalConfiguration jamesConfiguration = handlerConfiguration.configurationAt("handlerchain");
-        if (jamesConfiguration.getString("[@coreHandlersPackage]") == null)
-            jamesConfiguration.addProperty("[@coreHandlersPackage]", CoreCmdHandlerLoader.class.getName());
-        handlerChain.configure(jamesConfiguration);
-    }
-
-    @Override
-    protected void prepareInit() throws Exception {
-        prepareHandlerChain();
+        // TODO: does this belong here ?
+        useStartTLS = configuration.getBoolean("startTLS.[@enable]", false);
     }
-
     /**
      * @see org.apache.james.socket.AbstractProtocolServer#getDefaultPort()
      */
@@ -152,7 +107,7 @@
      */
     public ProtocolHandler newProtocolHandlerInstance() {
         //pass the handler chain to every POP3handler
-        POP3Handler protocolHandler = new POP3Handler(theConfigData, handlerChain);
+        POP3Handler protocolHandler = new POP3Handler(theConfigData, getProtocolHandlerChain());
         return protocolHandler;
     }
 
@@ -165,10 +120,10 @@
          * @see org.apache.james.pop3server.POP3HandlerConfigurationData#getHelloName()
          */
         public String getHelloName() {
-            if (POP3Server.this.getHelloName() == null) {
-                return POP3Server.this.mailServer.getHelloName();
+            if (POP3ServerProtocolServerHandlerFactory.this.getHelloName() == null) {
+                return POP3ServerProtocolServerHandlerFactory.this.mailServer.getHelloName();
             } else {
-                return POP3Server.this.getHelloName();
+                return POP3ServerProtocolServerHandlerFactory.this.getHelloName();
             }
         }
 
@@ -176,7 +131,7 @@
          * @see org.apache.james.pop3server.POP3HandlerConfigurationData#getResetLength()
          */
         public int getResetLength() {
-            return POP3Server.this.lengthReset;
+            return POP3ServerProtocolServerHandlerFactory.this.lengthReset;
         }
 
 
@@ -184,7 +139,12 @@
          * @see org.apache.james.pop3server.POP3HandlerConfigurationData#isStartTLSSupported()
          */
 		public boolean isStartTLSSupported() {
-			return POP3Server.this.useStartTLS();
+			return POP3ServerProtocolServerHandlerFactory.this.useStartTLS;
 		}
     }
+
+    @Override
+    protected Class<?> getHandlersPackage() {
+        return CoreCmdHandlerLoader.class;
+    }
 }

Modified: james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/POP3ServerTest.java?rev=884278&r1=884277&r2=884278&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/POP3ServerTest.java (original)
+++ james/server/trunk/pop3server-function/src/test/java/org/apache/james/pop3server/POP3ServerTest.java Wed Nov 25 21:17:13 2009
@@ -34,6 +34,7 @@
 import org.apache.james.core.MailImpl;
 import org.apache.james.services.MailRepository;
 import org.apache.james.services.MailServer;
+import org.apache.james.socket.AvalonProtocolServer;
 import org.apache.james.socket.JamesConnectionManager;
 import org.apache.james.test.mock.avalon.MockLogger;
 import org.apache.james.test.mock.avalon.MockSocketManager;
@@ -71,8 +72,9 @@
 
     protected POP3TestConfiguration m_testConfiguration;
 
-    private POP3Server m_pop3Server;
-
+    private POP3ServerProtocolServerHandlerFactory m_pop3Server;
+    private AvalonProtocolServer protoserver;
+    
     private MockUsersRepository m_usersRepository = new MockUsersRepository();
     private POP3Client m_pop3Protocol = null;
 
@@ -95,28 +97,35 @@
     }
 
     protected void setUp() throws Exception {
-        m_pop3Server = new POP3Server();
+        m_pop3Server = new POP3ServerProtocolServerHandlerFactory();
         setUpServiceManager();
         
-        ContainerUtil.service(m_pop3Server, serviceManager);
-        ContainerUtil.enableLogging(m_pop3Server, new MockLogger());
         m_pop3Server.setLoader(serviceManager);
-        m_pop3Server.setConnectionManager(connectionManager);
         m_pop3Server.setDNSService(dnsservice);
-        m_pop3Server.setFileSystem(fSystem);
         m_pop3Server.setMailServer(m_mailServer);
-        m_pop3Server.setProtocolHandlerFactory(m_pop3Server);
-        m_pop3Server.setSocketManager(socketManager);
-        m_pop3Server.setThreadManager(threadManager);
         m_pop3Server.setLog(new SimpleLog("MockLog"));
+        
+        protoserver = new AvalonProtocolServer();
+        protoserver.setConnectionManager(connectionManager);
+        protoserver.setFileSystem(fSystem);
+        protoserver.setProtocolHandlerFactory(m_pop3Server);
+        protoserver.setSocketManager(socketManager);
+        protoserver.setThreadManager(threadManager);
+        protoserver.setLog(new SimpleLog("MockLog"));
+        protoserver.setDNSService(dnsservice);
+
         m_testConfiguration = new POP3TestConfiguration(m_pop3ListenerPort);
     }
 
     protected void finishSetUp(POP3TestConfiguration testConfiguration)
             throws Exception {
         testConfiguration.init();
-        m_pop3Server.setConfiguration(new ConfigurationAdapter(testConfiguration));
+        ConfigurationAdapter conf = new ConfigurationAdapter(testConfiguration);
+        m_pop3Server.setConfiguration(conf);
         m_pop3Server.init();
+        
+        protoserver.setConfiguration(conf);
+        protoserver.init();
     }
 
     protected void setUpServiceManager() throws ServiceException {

Modified: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/AvalonRemoteManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/AvalonRemoteManager.java?rev=884278&r1=884277&r2=884278&view=diff
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/AvalonRemoteManager.java (original)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/AvalonRemoteManager.java Wed Nov 25 21:17:13 2009
@@ -43,8 +43,10 @@
 import org.apache.james.management.SpoolManagementService;
 import org.apache.james.services.FileSystem;
 import org.apache.james.services.MailServer;
+import org.apache.james.socket.AvalonProtocolServer;
 import org.apache.james.socket.JamesConnectionManager;
 import org.apache.james.socket.api.ProtocolHandlerFactory;
+import org.apache.james.socket.api.ProtocolServer;
 import org.apache.james.util.ConfigurationAdapter;
 import org.guiceyfruit.jsr250.Jsr250Module;
 
@@ -63,7 +65,7 @@
     private org.apache.commons.configuration.HierarchicalConfiguration config;
     private JamesConnectionManager connectionManager;
     private SocketManager socketManager;
-    private RemoteManager server = new RemoteManager();
+    private RemoteManagerMBean mbean;
     private ThreadManager threadManager;
     private SpoolManagementService spoolService;
     private BayesianAnalyzerManagementService bayesianServer;
@@ -74,19 +76,19 @@
     private Store store;
     
     public String getNetworkInterface() {
-        return server.getNetworkInterface();
+        return mbean.getNetworkInterface();
     }
 
     public int getPort() {
-        return server.getPort();
+        return mbean.getPort();
     }
 
     public String getSocketType() {
-        return server.getSocketType();
+        return mbean.getSocketType();
     }
 
     public boolean isEnabled() {
-        return server.isEnabled();
+        return mbean.isEnabled();
     }
 
     /**
@@ -123,7 +125,8 @@
      * @see org.apache.avalon.framework.activity.Initializable#initialize()
      */
     public void initialize() throws Exception {
-        server = Guice.createInjector(new RemoteManagerModule(), new Jsr250Module()).getInstance(RemoteManager.class);
+        Injector injector = Guice.createInjector(new RemoteManagerModule(), new Jsr250Module());
+        mbean = injector.getInstance(RemoteManagerMBeanImpl.class);
     }
                  
     /**
@@ -142,13 +145,6 @@
             bind(org.apache.commons.configuration.HierarchicalConfiguration.class).annotatedWith(Names.named("org.apache.commons.configuration.Configuration")).toInstance(config);
             bind(Log.class).annotatedWith(Names.named("org.apache.commons.logging.Log")).toInstance(logger);
             bind(FileSystem.class).annotatedWith(Names.named("org.apache.james.services.FileSystem")).toInstance(filesystem);
-            bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).toProvider(new Provider<ProtocolHandlerFactory>() {
-
-                public ProtocolHandlerFactory get() {
-                    return server;
-                }
-                
-            });
             bind(SocketManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.sockets.SocketManager")).toInstance(socketManager);
             bind(JamesConnectionManager.class).annotatedWith(Names.named("org.apache.james.socket.JamesConnectionManager")).toInstance(connectionManager);
             bind(ThreadManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.threads.ThreadManager")).toInstance(threadManager);
@@ -159,6 +155,9 @@
             bind(VirtualUserTableManagementService.class).annotatedWith(Names.named("org.apache.james.api.vut.management.VirtualUserTableManagementService")).toInstance(vutService);
             bind(DomainListManagementService.class).annotatedWith(Names.named("org.apache.james.management.DomainListManagementService")).toInstance(domainService);
             bind(Store.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.store.Store")).toInstance(store);
+            
+            bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).to(RemoteManagerProtocolHandlerFactory.class);
+            bind(ProtocolServer.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolServer")).to(AvalonProtocolServer.class);
             // we bind the LoaderService to an Provider to get sure everything is there when the SMTPLoaderService get created.
             bind(LoaderService.class).annotatedWith(Names.named("org.apache.james.LoaderService")).toProvider(new Provider<LoaderService>() {
 

Added: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerMBeanImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerMBeanImpl.java?rev=884278&view=auto
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerMBeanImpl.java (added)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerMBeanImpl.java Wed Nov 25 21:17:13 2009
@@ -0,0 +1,63 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.remotemanager;
+
+import javax.annotation.Resource;
+
+import org.apache.james.socket.api.ProtocolServer;
+
+public class RemoteManagerMBeanImpl implements RemoteManagerMBean{
+
+    private ProtocolServer server;
+
+    @Resource(name="org.apache.james.socket.api.ProtocolServer")
+    public void setProtocolServer(ProtocolServer server) {
+        this.server = server;
+    }
+    
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getNetworkInterface()
+     */
+    public String getNetworkInterface() {
+        return server.getNetworkInterface();
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getPort()
+     */
+    public int getPort() {
+        return server.getPort();
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getSocketType()
+     */
+    public String getSocketType() {
+        return server.getSocketType();
+    }
+
+    /**
+     * (non-Javadoc)
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#isEnabled()
+     */
+    public boolean isEnabled() {
+        return server.isEnabled();
+    }
+
+}

Copied: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerProtocolHandlerFactory.java (from r833856, james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManager.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerProtocolHandlerFactory.java?p2=james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerProtocolHandlerFactory.java&p1=james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManager.java&r1=833856&r2=884278&rev=884278&view=diff
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManager.java (original)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerProtocolHandlerFactory.java Wed Nov 25 21:17:13 2009
@@ -30,19 +30,17 @@
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.james.api.kernel.LoaderService;
 import org.apache.james.remotemanager.core.CoreCmdHandlerLoader;
 import org.apache.james.services.MailServer;
-import org.apache.james.socket.AbstractProtocolServer;
+import org.apache.james.socket.api.AbstractSupportLoaderProtocolHandlerFactory;
 import org.apache.james.socket.api.ProtocolHandler;
-import org.apache.james.socket.shared.ProtocolHandlerChainImpl;
 
 /**
  * Provides a really rude network interface to administer James.
  */
-public class RemoteManager
-    extends AbstractProtocolServer implements RemoteManagerMBean {
+public class RemoteManagerProtocolHandlerFactory extends AbstractSupportLoaderProtocolHandlerFactory {
 
+    
     /**
      * A Map of (user id, passwords) for James administrators
      */
@@ -54,109 +52,48 @@
      */
     private String prompt = "";
 
-    /**
-     * The reference to the internal MailServer service
-     */
-    private MailServer mailServer;
-
 
-    /**
-     * Set the MailServer 
-     * 
-     * @param mailServer the MailServer
-     */
+    
     @Resource(name="org.apache.james.services.MailServer")
-    public void setMailServer(MailServer mailServer) {
+    public final void setMailServer(MailServer mailServer) {
         this.mailServer = mailServer;
     }
 
+    
     /**
      * The configuration data to be passed to the handler
      */
     private RemoteManagerHandlerConfigurationData theConfigData
         = new RemoteManagerHandlerConfigurationDataImpl();
 
+    private MailServer mailServer;
 
-    /**
-     * The chain to use
-     */
-    private ProtocolHandlerChainImpl handlerChain;
-
-
-    /**
-     * The loader
-     */
-    private LoaderService loader;
-
-
-    /**
-     * The configuration
-     */
-    private HierarchicalConfiguration handlerConfiguration;
     
-    /**
-     * Gets the current instance loader.
-     * @return the loader
-     */
-    public final LoaderService getLoader() {
-        return loader;
-    }
-
-    /**
-     * Sets the loader to be used for instances.
-     * @param loader the loader to set, not null
-     */
-    @Resource(name="org.apache.james.LoaderService")
-    public final void setLoader(LoaderService loader) {
-        this.loader = loader;
-    }
-
-
-    @Override
     @PostConstruct
     public void init() throws Exception {
         super.init();
     }
 
     @SuppressWarnings("unchecked")
-    public void onConfigure( final HierarchicalConfiguration configuration )
+    public void onConfigure(HierarchicalConfiguration configuration)
         throws ConfigurationException {
-        if (isEnabled()) {
-            HierarchicalConfiguration handlerConfiguration = configuration.configurationAt("handler");
-            List<HierarchicalConfiguration> accounts = handlerConfiguration.configurationsAt( "administrator_accounts.account" );
-            for ( int i = 0; i < accounts.size(); i++ ) {
-                adminAccounts.put( accounts.get(i).getString("[@login]" ),
-                                   accounts.get(i).getString( "[@password]" ) );
-            }
-            prompt =handlerConfiguration.getString("prompt", null);
-            
-            if (prompt == null) prompt = ""; 
-            else if (!prompt.equals("") && !prompt.endsWith(" ")) prompt += " "; 
-           
-            this.handlerConfiguration = handlerConfiguration;
+        super.onConfigure(configuration);
+        HierarchicalConfiguration handlerConfiguration = configuration.configurationAt("handler");
+        List<HierarchicalConfiguration> accounts = handlerConfiguration.configurationsAt("administrator_accounts.account");
+        for (int i = 0; i < accounts.size(); i++) {
+            adminAccounts.put(accounts.get(i).getString("[@login]"), accounts.get(i).getString("[@password]"));
         }
-    }
-    
-    private void prepareHandlerChain() throws Exception {
+        prompt = handlerConfiguration.getString("prompt", null);
 
-        handlerChain = loader.load(ProtocolHandlerChainImpl.class);
-        
-        //set the logger
-        handlerChain.setLog(getLog());
-        
-        //read from the XML configuration and create and configure each of the handlers
-        HierarchicalConfiguration jamesConfiguration = handlerConfiguration.configurationAt("handlerchain");
-        if (jamesConfiguration.getString("[@coreHandlersPackage]") == null)
-            jamesConfiguration.addProperty("[@coreHandlersPackage]", CoreCmdHandlerLoader.class.getName());
-        handlerChain.configure(jamesConfiguration);
+        if (prompt == null)
+            prompt = "";
+        else if (!prompt.equals("") && !prompt.endsWith(" "))
+            prompt += " ";
+                
     }
     
 
-    @Override
-    protected void prepareInit() throws Exception {
-        prepareHandlerChain();
-    }
-    
+
     /**
      * @see org.apache.james.socket.AbstractProtocolServer#getDefaultPort()
      */
@@ -175,7 +112,7 @@
      * @see org.apache.james.socket.AbstractProtocolServer#newProtocolHandlerInstance()
      */
     public ProtocolHandler newProtocolHandlerInstance() {
-        return new RemoteManagerHandler(theConfigData, handlerChain);
+        return new RemoteManagerHandler(theConfigData, getProtocolHandlerChain());
     }
 
     /**
@@ -188,10 +125,10 @@
          * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getHelloName()
          */
         public String getHelloName() {
-            if (RemoteManager.this.getHelloName() == null) {
-                return RemoteManager.this.mailServer.getHelloName();
+            if (getHelloName() == null) {
+                return RemoteManagerProtocolHandlerFactory.this.mailServer.getHelloName();
             } else {
-                return RemoteManager.this.getHelloName();
+                return RemoteManagerProtocolHandlerFactory.this.getHelloName();
             }
         }
         
@@ -199,15 +136,20 @@
          * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getAdministrativeAccountData()
          */
         public Map<String,String> getAdministrativeAccountData() {
-            return RemoteManager.this.adminAccounts;
+            return RemoteManagerProtocolHandlerFactory.this.adminAccounts;
         }
 
         /**
          * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getPrompt()
          */
         public String getPrompt() {
-            return RemoteManager.this.prompt;
+            return RemoteManagerProtocolHandlerFactory.this.prompt;
         }
         
     }
+
+    @Override
+    protected Class<?> getHandlersPackage() {
+        return CoreCmdHandlerLoader.class;
+    }
 }

Modified: james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTest.java?rev=884278&r1=884277&r2=884278&view=diff
==============================================================================
--- james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTest.java (original)
+++ james/server/trunk/remotemanager-function/src/test/java/org/apache/james/remotemanager/RemoteManagerTest.java Wed Nov 25 21:17:13 2009
@@ -45,6 +45,7 @@
 import org.apache.james.management.SpoolManagementException;
 import org.apache.james.management.SpoolManagementService;
 import org.apache.james.services.MailServer;
+import org.apache.james.socket.AvalonProtocolServer;
 import org.apache.james.socket.JamesConnectionManager;
 import org.apache.james.socket.SimpleConnectionManager;
 import org.apache.james.test.mock.avalon.MockLogger;
@@ -88,7 +89,9 @@
 public class RemoteManagerTest extends TestCase {
     
     protected int m_remoteManagerListenerPort = Util.getNonPrivilegedPort();
-    protected RemoteManager m_remoteManager;
+    protected RemoteManagerProtocolHandlerFactory handlerFactory;
+    protected AvalonProtocolServer server;
+    
     protected RemoteManagerTestConfiguration m_testConfiguration;
     protected String m_host = "127.0.0.1";
     protected BufferedReader m_reader;
@@ -104,20 +107,26 @@
     private DNSService dnsservice;
     private MockFileSystem filesystem;
     private MockVirtualUserTableManagementService vutManagement;
-
+    private AvalonProtocolServer protoserver;
+    
     protected void setUp() throws Exception {
-        m_remoteManager = new RemoteManager();
+        handlerFactory = new RemoteManagerProtocolHandlerFactory();
         setUpServiceManager();
-        m_remoteManager.setLoader(serviceManager);
-        m_remoteManager.setConnectionManager(connectionManager);
-        m_remoteManager.setFileSystem(filesystem);
-        m_remoteManager.setDNSService(dnsservice);
-        m_remoteManager.setLog(new SimpleLog("MockLog"));
-        m_remoteManager.setMailServer(mailServer);
-        m_remoteManager.setProtocolHandlerFactory(m_remoteManager);
-        m_remoteManager.setSocketManager(socketManager);
-        m_remoteManager.setThreadManager(threadManager);
-        ContainerUtil.service(m_remoteManager, serviceManager);
+        
+        handlerFactory.setLoader(serviceManager);
+        handlerFactory.setLog(new SimpleLog("MockLog"));
+        handlerFactory.setMailServer(mailServer);
+        handlerFactory.setDNSService(dnsservice);
+        
+        protoserver = new AvalonProtocolServer();
+        protoserver.setLog(new SimpleLog("ProtoServerLog"));
+        protoserver.setConnectionManager(connectionManager);
+        protoserver.setFileSystem(filesystem);
+        protoserver.setDNSService(dnsservice);
+        protoserver.setProtocolHandlerFactory(handlerFactory);
+        protoserver.setSocketManager(socketManager);
+        protoserver.setThreadManager(threadManager);
+        //ContainerUtil.service(m_remoteManager, serviceManager);
         m_testConfiguration = new RemoteManagerTestConfiguration(m_remoteManagerListenerPort);
     }
 
@@ -129,8 +138,12 @@
     protected void finishSetUp(RemoteManagerTestConfiguration testConfiguration) throws Exception {
         testConfiguration.init();
         try {
-            m_remoteManager.setConfiguration(new ConfigurationAdapter(testConfiguration));
-            m_remoteManager.init();
+            ConfigurationAdapter conf = new ConfigurationAdapter(testConfiguration);
+            protoserver.setConfiguration(conf);
+            handlerFactory.setConfiguration(conf);
+            handlerFactory.init();
+            protoserver.init();
+            
         } catch (Exception e) {
             throw new RuntimeException(e);
         }

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/AvalonSMTPServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/AvalonSMTPServer.java?rev=884278&r1=884277&r2=884278&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/AvalonSMTPServer.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/AvalonSMTPServer.java Wed Nov 25 21:17:13 2009
@@ -40,8 +40,10 @@
 import org.apache.james.services.FileSystem;
 import org.apache.james.services.MailServer;
 import org.apache.james.smtpserver.protocol.SMTPServerMBean;
+import org.apache.james.socket.AvalonProtocolServer;
 import org.apache.james.socket.JamesConnectionManager;
 import org.apache.james.socket.api.ProtocolHandlerFactory;
+import org.apache.james.socket.api.ProtocolServer;
 import org.apache.james.util.ConfigurationAdapter;
 import org.apache.mailet.MailetContext;
 import org.guiceyfruit.jsr250.Jsr250Module;
@@ -52,7 +54,7 @@
 import com.google.inject.Provider;
 import com.google.inject.name.Names;
 
-public class AvalonSMTPServer implements GuiceInjected, Initializable, Serviceable, Configurable, LogEnabled, SMTPServerMBean{
+public class AvalonSMTPServer implements GuiceInjected, Initializable, Serviceable, Configurable, LogEnabled, SMTPServerMBean {
     
     private FileSystem filesystem;
     private MailServer mailserver;
@@ -66,23 +68,23 @@
     private org.apache.james.smtpserver.protocol.DNSService dnsServiceAdapter;
     private JamesConnectionManager connectionManager;
     private SocketManager socketManager;
-    private SMTPServer smtpserver;
     private ThreadManager threadManager;
+    private SMTPServerMBean mbean;
     
     public String getNetworkInterface() {
-        return smtpserver.getNetworkInterface();
+        return mbean.getNetworkInterface();
     }
 
     public int getPort() {
-        return smtpserver.getPort();
+        return mbean.getPort();
     }
 
     public String getSocketType() {
-        return smtpserver.getSocketType();
+        return mbean.getSocketType();
     }
 
     public boolean isEnabled() {
-        return smtpserver.isEnabled();
+        return mbean.isEnabled();
     }
 
     /**
@@ -117,7 +119,7 @@
      * @see org.apache.avalon.framework.activity.Initializable#initialize()
      */
     public void initialize() throws Exception {
-        smtpserver = Guice.createInjector(new SMTPServerModule(), new Jsr250Module()).getInstance(SMTPServer.class);
+        mbean = Guice.createInjector(new SMTPServerModule(), new Jsr250Module()).getInstance(SMTPServerMBeanImpl.class);
     }
                  
     /**
@@ -141,13 +143,8 @@
             bind(UsersRepository.class).annotatedWith(Names.named("org.apache.james.api.user.UsersRepository")).toInstance(userRepos);
             bind(DataSourceSelector.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.datasources.DataSourceSelector")).toInstance(dselector);
             bind(VirtualUserTableStore.class).annotatedWith(Names.named("org.apache.james.api.vut.VirtualUserTableStore")).toInstance(vutStore);
-            bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).toProvider(new Provider<ProtocolHandlerFactory>() {
-
-                public ProtocolHandlerFactory get() {
-                    return smtpserver;
-                }
-                
-            });
+            bind(ProtocolHandlerFactory.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolHandlerFactory")).to(SMTPServerProtocolHandlerFactory.class);
+            bind(ProtocolServer.class).annotatedWith(Names.named("org.apache.james.socket.api.ProtocolServer")).to(AvalonProtocolServer.class);
             bind(SocketManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.sockets.SocketManager")).toInstance(socketManager);
             bind(JamesConnectionManager.class).annotatedWith(Names.named("org.apache.james.socket.JamesConnectionManager")).toInstance(connectionManager);
             bind(ThreadManager.class).annotatedWith(Names.named("org.apache.avalon.cornerstone.services.threads.ThreadManager")).toInstance(threadManager);

Added: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServerMBeanImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServerMBeanImpl.java?rev=884278&view=auto
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServerMBeanImpl.java (added)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServerMBeanImpl.java Wed Nov 25 21:17:13 2009
@@ -0,0 +1,64 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.smtpserver;
+
+import javax.annotation.Resource;
+
+import org.apache.james.smtpserver.protocol.SMTPServerMBean;
+import org.apache.james.socket.api.ProtocolServer;
+
+public class SMTPServerMBeanImpl implements SMTPServerMBean{
+
+    private ProtocolServer server;
+
+    @Resource(name="org.apache.james.socket.api.ProtocolServer")
+    public void setProtocolServer(ProtocolServer server) {
+        this.server = server;
+    }
+    
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getNetworkInterface()
+     */
+    public String getNetworkInterface() {
+        return server.getNetworkInterface();
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getPort()
+     */
+    public int getPort() {
+        return server.getPort();
+    }
+
+    /**
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#getSocketType()
+     */
+    public String getSocketType() {
+        return server.getSocketType();
+    }
+
+    /**
+     * (non-Javadoc)
+     * @see org.apache.james.remotemanager.RemoteManagerMBean#isEnabled()
+     */
+    public boolean isEnabled() {
+        return server.isEnabled();
+    }
+
+}



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