Author: norman
Date: Fri Oct  7 13:59:57 2011
New Revision: 1180041

URL: http://svn.apache.org/viewvc?rev=1180041&view=rev
Log:
Introduce an AbstractServerFactory which is used to create the configured 
AbstractConfigurableAsyncServer subtypes. This allows users to easily start 
more then one instance of a specific server (for example one for smtp and one 
for smtps) without the need to worry about spring xml files. See JAMES-1214

Added:
    
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/IMAPServerFactory.java
   (with props)
    
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/OioIMAPServerFactory.java
   (with props)
    
james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/LMTPServerFactory.java
   (with props)
    
james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServerFactory.java
   (with props)
    
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/OioPOP3ServerFactory.java
   (with props)
    
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ServerFactory.java
   (with props)
    
james/server/trunk/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractServerFactory.java
   (with props)
    
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServerFactory.java
   (with props)
    
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPServerFactory.java
   (with props)
Modified:
    
james/server/trunk/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
    
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java

Added: 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/IMAPServerFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/IMAPServerFactory.java?rev=1180041&view=auto
==============================================================================
--- 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/IMAPServerFactory.java
 (added)
+++ 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/IMAPServerFactory.java
 Fri Oct  7 13:59:57 2011
@@ -0,0 +1,88 @@
+/****************************************************************
+ * 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.imapserver.netty;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.imap.api.process.ImapProcessor;
+import org.apache.james.imap.decode.ImapDecoder;
+import org.apache.james.imap.encode.ImapEncoder;
+import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
+import org.apache.james.protocols.lib.netty.AbstractServerFactory;
+import org.slf4j.Logger;
+
+public class IMAPServerFactory extends AbstractServerFactory{
+
+    private FileSystem fileSystem;
+    private ImapDecoder decoder;
+    private ImapEncoder encoder;
+    private ImapProcessor processor;
+
+    
+    @Resource(name = "filesystem")
+    public final void setFileSystem(FileSystem filesystem) {
+        this.fileSystem = filesystem;
+    }
+    
+    @Resource(name = "imapDecoder")
+    public void setImapDecoder(ImapDecoder decoder) {
+        this.decoder = decoder;
+    }
+
+    @Resource(name = "imapEncoder")
+    public void setImapEncoder(ImapEncoder encoder) {
+        this.encoder = encoder;
+    }
+
+    @Resource(name = "imapProcessor")
+    public void setImapProcessor(ImapProcessor processor) {
+        this.processor = processor;
+    }
+    
+    protected IMAPServer createServer() {
+       return new IMAPServer();
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    protected List<AbstractConfigurableAsyncServer> createServers(Logger log, 
HierarchicalConfiguration config) throws Exception{
+        List<AbstractConfigurableAsyncServer> servers = new 
ArrayList<AbstractConfigurableAsyncServer>();
+        List<HierarchicalConfiguration> configs = 
config.configurationsAt("imapserver");
+        
+        for (HierarchicalConfiguration serverConfig: configs) {
+            IMAPServer server = createServer();
+            server.setLog(log);
+            server.setFileSystem(fileSystem);
+            server.setImapDecoder(decoder);
+            server.setImapEncoder(encoder);
+            server.setImapProcessor(processor);
+            server.configure(serverConfig);
+            servers.add(server);
+        }
+
+        return servers;
+    }
+
+
+}

Propchange: 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/IMAPServerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/OioIMAPServerFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/OioIMAPServerFactory.java?rev=1180041&view=auto
==============================================================================
--- 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/OioIMAPServerFactory.java
 (added)
+++ 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/OioIMAPServerFactory.java
 Fri Oct  7 13:59:57 2011
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.imapserver.netty;
+
+public class OioIMAPServerFactory extends IMAPServerFactory{
+
+    @Override
+    protected IMAPServer createServer() {
+        return new OioIMAPServer();
+    }
+
+}

Propchange: 
james/server/trunk/imapserver/src/main/java/org/apache/james/imapserver/netty/OioIMAPServerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/LMTPServerFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/LMTPServerFactory.java?rev=1180041&view=auto
==============================================================================
--- 
james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/LMTPServerFactory.java
 (added)
+++ 
james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/LMTPServerFactory.java
 Fri Oct  7 13:59:57 2011
@@ -0,0 +1,69 @@
+/****************************************************************
+ * 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.lmtpserver.netty;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.protocols.api.handler.ProtocolHandlerLoader;
+import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
+import org.apache.james.protocols.lib.netty.AbstractServerFactory;
+import org.slf4j.Logger;
+
+public class LMTPServerFactory extends AbstractServerFactory{
+
+    private ProtocolHandlerLoader loader;
+    private FileSystem fileSystem;
+
+    @Resource(name = "protocolhandlerloader")
+    public void setProtocolHandlerLoader(ProtocolHandlerLoader loader) {
+        this.loader = loader;
+    }
+    
+    @Resource(name = "filesystem")
+    public final void setFileSystem(FileSystem filesystem) {
+        this.fileSystem = filesystem;
+    }
+    
+    protected LMTPServer createServer() {
+       return new LMTPServer();
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    protected List<AbstractConfigurableAsyncServer> createServers(Logger log, 
HierarchicalConfiguration config) throws Exception{
+        List<AbstractConfigurableAsyncServer> servers = new 
ArrayList<AbstractConfigurableAsyncServer>();
+        List<HierarchicalConfiguration> configs = 
config.configurationsAt("lmtpserver");
+        
+        for (HierarchicalConfiguration serverConfig: configs) {
+            LMTPServer server = createServer();
+            server.setFileSystem(fileSystem);
+            server.setProtocolHandlerLoader(loader);
+            server.setLog(log);
+            server.configure(serverConfig);
+            servers.add(server);
+        }
+
+        return servers;
+    }
+}

Propchange: 
james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/LMTPServerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServerFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServerFactory.java?rev=1180041&view=auto
==============================================================================
--- 
james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServerFactory.java
 (added)
+++ 
james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServerFactory.java
 Fri Oct  7 13:59:57 2011
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.lmtpserver.netty;
+
+public class OioLMTPServerFactory extends LMTPServerFactory{
+
+    @Override
+    protected LMTPServer createServer() {
+        return new OioLMTPServer();
+    }
+
+}

Propchange: 
james/server/trunk/lmtpserver/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/OioPOP3ServerFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/OioPOP3ServerFactory.java?rev=1180041&view=auto
==============================================================================
--- 
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/OioPOP3ServerFactory.java
 (added)
+++ 
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/OioPOP3ServerFactory.java
 Fri Oct  7 13:59:57 2011
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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.netty;
+
+public class OioPOP3ServerFactory extends POP3ServerFactory{
+
+    @Override
+    protected POP3Server createServer() {
+        return new OioPOP3Server();
+    }
+
+}

Propchange: 
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/OioPOP3ServerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ServerFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ServerFactory.java?rev=1180041&view=auto
==============================================================================
--- 
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ServerFactory.java
 (added)
+++ 
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ServerFactory.java
 Fri Oct  7 13:59:57 2011
@@ -0,0 +1,54 @@
+package org.apache.james.pop3server.netty;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.protocols.api.handler.ProtocolHandlerLoader;
+import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
+import org.apache.james.protocols.lib.netty.AbstractServerFactory;
+import org.slf4j.Logger;
+
+public class POP3ServerFactory extends AbstractServerFactory{
+
+
+    private ProtocolHandlerLoader loader;
+    private FileSystem fileSystem;
+    
+    @Resource(name = "protocolhandlerloader")
+    public void setProtocolHandlerLoader(ProtocolHandlerLoader loader) {
+        this.loader = loader;
+    }
+    
+    @Resource(name = "filesystem")
+    public final void setFileSystem(FileSystem filesystem) {
+        this.fileSystem = filesystem;
+    }
+    
+    protected POP3Server createServer() {
+       return new POP3Server();
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    protected List<AbstractConfigurableAsyncServer> createServers(Logger log, 
HierarchicalConfiguration config) throws Exception{
+        List<AbstractConfigurableAsyncServer> servers = new 
ArrayList<AbstractConfigurableAsyncServer>();
+        List<HierarchicalConfiguration> configs = 
config.configurationsAt("pop3server");
+        
+        for (HierarchicalConfiguration serverConfig: configs) {
+            POP3Server server = createServer();
+            server.setProtocolHandlerLoader(loader);
+            server.setLog(log);
+            server.setFileSystem(fileSystem);
+            server.configure(serverConfig);
+            servers.add(server);
+        }
+
+        return servers;
+    }
+    
+
+}

Propchange: 
james/server/trunk/pop3server/src/main/java/org/apache/james/pop3server/netty/POP3ServerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
james/server/trunk/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java?rev=1180041&r1=1180040&r2=1180041&view=diff
==============================================================================
--- 
james/server/trunk/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
 (original)
+++ 
james/server/trunk/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
 Fri Oct  7 13:59:57 2011
@@ -19,6 +19,7 @@
 package org.apache.james.protocols.lib.netty;
 
 import java.io.FileInputStream;
+import java.lang.management.ManagementFactory;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
@@ -30,6 +31,8 @@ import java.util.concurrent.Executor;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.annotation.Resource;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
 import javax.net.ssl.KeyManagerFactory;
 import javax.net.ssl.SSLContext;
 
@@ -109,6 +112,8 @@ public abstract class AbstractConfigurab
 
     private int maxExecutorThreads;
 
+    private MBeanServer mbeanServer;
+
     @Resource(name = "filesystem")
     public final void setFileSystem(FileSystem filesystem) {
         this.fileSystem = filesystem;
@@ -121,6 +126,30 @@ public abstract class AbstractConfigurab
         this.logger = logger;
     }
 
+    protected void registerMBean() {
+
+        try {
+            mbeanServer.registerMBean(this, new ObjectName(getMBeanName()));
+
+        } catch (Exception e) {
+            throw new RuntimeException("Unable to register mbean", e);
+        }
+
+    }
+
+    protected void unregisterMBean() {
+        try {
+            mbeanServer.unregisterMBean(new ObjectName(getMBeanName()));
+        } catch (Exception e) {
+            throw new RuntimeException("Unable to unregister mbean", e);
+        }
+
+    }
+    
+    private String getMBeanName() {
+        return  "org.apache.james:type=server,name=" + jmxName;
+    }
+    
     /**
      * @see
      * org.apache.james.lifecycle.api.Configurable
@@ -234,10 +263,14 @@ public abstract class AbstractConfigurab
     @PostConstruct
     public final void init() throws Exception {
         if (isEnabled()) {
+
             buildSSLContext();
             preInit();
             executionHandler = createExecutionHander();
             bind();
+
+            mbeanServer = ManagementFactory.getPlatformMBeanServer();
+            registerMBean();
             
             getLogger().info("Init " + getServiceType() + " done");
 
@@ -254,7 +287,8 @@ public abstract class AbstractConfigurab
             if (executionHandler != null) {
                 executionHandler.releaseExternalResources();
             }
-            
+
+            unregisterMBean();
         }
         getLogger().info("Dispose " + getServiceType() + " done");
 

Added: 
james/server/trunk/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractServerFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractServerFactory.java?rev=1180041&view=auto
==============================================================================
--- 
james/server/trunk/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractServerFactory.java
 (added)
+++ 
james/server/trunk/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractServerFactory.java
 Fri Oct  7 13:59:57 2011
@@ -0,0 +1,98 @@
+/****************************************************************
+ * 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.protocols.lib.netty;
+
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.lifecycle.api.Configurable;
+import org.apache.james.lifecycle.api.LogEnabled;
+import org.slf4j.Logger;
+
+/**
+ * Abstract base class for Factories that need to create {@link 
AbstractConfigurableAsyncServer}'s via configuration files
+ * 
+ *
+ */
+public abstract class AbstractServerFactory implements Configurable, 
LogEnabled{
+
+    private Logger log;
+    private List<AbstractConfigurableAsyncServer> servers;
+    private HierarchicalConfiguration config;
+
+
+    /**
+     * Create {@link AbstractConfigurableAsyncServer} servers, inject 
dependencies and configure them before return all fo them in a {@link List}
+     * 
+     * @param log
+     * @param config
+     * @return servers
+     * @throws Exception
+     */
+    protected abstract List<AbstractConfigurableAsyncServer> 
createServers(Logger log, HierarchicalConfiguration config) throws Exception;
+    
+    
+    
+    @Override
+    public void configure(HierarchicalConfiguration config) throws 
ConfigurationException {
+        this.config = config;
+    }
+
+
+
+    @Override
+    public void setLog(Logger log) {
+        this.log = log;
+    }
+
+
+
+    @PostConstruct
+    public void init() throws Exception {
+        servers = createServers(log, config);
+        for (AbstractConfigurableAsyncServer server: servers) {
+            server.init();
+        }
+    }
+    
+    
+    /**
+     * Return all {@link AbstractConfigurableAsyncServer} instances that was 
create via this Factory
+     * @return
+     */
+    public List<AbstractConfigurableAsyncServer> getServers() {
+        return servers;
+    }
+    
+    
+    @PreDestroy
+    public void destroy() {
+        for (AbstractConfigurableAsyncServer server: servers) {
+            server.destroy();
+        }
+    }
+    
+ 
+    
+}

Propchange: 
james/server/trunk/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractServerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServerFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServerFactory.java?rev=1180041&view=auto
==============================================================================
--- 
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServerFactory.java
 (added)
+++ 
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServerFactory.java
 Fri Oct  7 13:59:57 2011
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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.netty;
+
+public class OioSMTPServerFactory extends SMTPServerFactory{
+
+    @Override
+    protected SMTPServer createServer() {
+        return new OioSMTPServer();
+    }
+
+}

Propchange: 
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java?rev=1180041&r1=1180040&r2=1180041&view=diff
==============================================================================
--- 
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
 (original)
+++ 
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPServer.java
 Fri Oct  7 13:59:57 2011
@@ -19,7 +19,10 @@
 package org.apache.james.smtpserver.netty;
 
 
+import java.lang.management.ManagementFactory;
+
 import javax.annotation.Resource;
+import javax.management.ObjectName;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.HierarchicalConfiguration;
@@ -35,7 +38,6 @@ import org.apache.james.smtpserver.CoreC
 import org.apache.james.smtpserver.ExtendedSMTPSession;
 import org.apache.james.smtpserver.jmx.JMXHandlersLoader;
 import org.jboss.netty.channel.ChannelUpstreamHandler;
-import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
 
 /**
  * NIO SMTPServer which use Netty
@@ -98,6 +100,8 @@ public class SMTPServer extends Abstract
         this.dns = dns;
     }
     
+    
+    
     @Override
     protected void preInit() throws Exception {
         super.preInit();

Added: 
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPServerFactory.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPServerFactory.java?rev=1180041&view=auto
==============================================================================
--- 
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPServerFactory.java
 (added)
+++ 
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPServerFactory.java
 Fri Oct  7 13:59:57 2011
@@ -0,0 +1,81 @@
+/****************************************************************
+ * 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.netty;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.james.dnsservice.api.DNSService;
+import org.apache.james.filesystem.api.FileSystem;
+import org.apache.james.protocols.api.handler.ProtocolHandlerLoader;
+import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
+import org.apache.james.protocols.lib.netty.AbstractServerFactory;
+import org.slf4j.Logger;
+
+public class SMTPServerFactory extends AbstractServerFactory{
+
+
+    private DNSService dns;
+    private ProtocolHandlerLoader loader;
+    private FileSystem fileSystem;
+
+    @Resource(name = "dnsservice")
+    public void setDNSService(DNSService dns) {
+        this.dns = dns;
+    }
+    
+    @Resource(name = "protocolhandlerloader")
+    public void setProtocolHandlerLoader(ProtocolHandlerLoader loader) {
+        this.loader = loader;
+    }
+    
+
+    @Resource(name = "filesystem")
+    public final void setFileSystem(FileSystem filesystem) {
+        this.fileSystem = filesystem;
+    }
+
+    protected SMTPServer createServer() {
+       return new SMTPServer();
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Override
+    protected List<AbstractConfigurableAsyncServer> createServers(Logger log, 
HierarchicalConfiguration config) throws Exception{
+        List<AbstractConfigurableAsyncServer> servers = new 
ArrayList<AbstractConfigurableAsyncServer>();
+        List<HierarchicalConfiguration> configs = 
config.configurationsAt("smtpserver");
+        
+        for (HierarchicalConfiguration serverConfig: configs) {
+            SMTPServer server = createServer();
+            server.setDNSService(dns);
+            server.setProtocolHandlerLoader(loader);
+            server.setLog(log);
+            server.setFileSystem(fileSystem);
+            server.configure(serverConfig);
+            servers.add(server);
+        }
+
+        return servers;
+    }
+
+}

Propchange: 
james/server/trunk/smtpserver/src/main/java/org/apache/james/smtpserver/netty/SMTPServerFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



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

Reply via email to