Author: bago
Date: Sat Sep 17 00:31:36 2011
New Revision: 1171877

URL: http://svn.apache.org/viewvc?rev=1171877&view=rev
Log:
Created a Protocol interface (maybe temporarily) and an SMTPProtocol definition.
NettyServer now does not anymore depend on SMTP and simply takes SMTPProtocol 
as an argument to start a server implementing that protocol.

Added:
    
james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/Protocol.java
   (with props)
    
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPProtocol.java
   (with props)
Modified:
    
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/NettyServer.java
    
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPServer.java

Added: 
james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/Protocol.java
URL: 
http://svn.apache.org/viewvc/james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/Protocol.java?rev=1171877&view=auto
==============================================================================
--- 
james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/Protocol.java
 (added)
+++ 
james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/Protocol.java
 Sat Sep 17 00:31:36 2011
@@ -0,0 +1,35 @@
+/****************************************************************
+ * 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.api;
+
+/**
+ * Define a protocol
+ */
+public interface Protocol {
+
+    ProtocolHandlerChain getProtocolChain();
+
+    ProtocolSessionFactory getProtocolSessionFactory();
+
+    boolean isStartTLSSupported();
+
+    Class<? extends Response> getResponseClass();
+
+}

Propchange: 
james/protocols/trunk/api/src/main/java/org/apache/james/protocols/api/Protocol.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/NettyServer.java
URL: 
http://svn.apache.org/viewvc/james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/NettyServer.java?rev=1171877&r1=1171876&r2=1171877&view=diff
==============================================================================
--- 
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/NettyServer.java
 (original)
+++ 
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/NettyServer.java
 Sat Sep 17 00:31:36 2011
@@ -23,17 +23,11 @@ import java.nio.charset.Charset;
 
 import javax.net.ssl.SSLContext;
 
-import org.apache.james.protocols.api.ProtocolHandlerChain;
-import org.apache.james.protocols.api.ProtocolSession;
-import org.apache.james.protocols.api.ProtocolSessionFactory;
-import org.apache.james.protocols.api.ProtocolTransport;
+import org.apache.james.protocols.api.Protocol;
 import org.apache.james.protocols.impl.AbstractAsyncServer;
 import org.apache.james.protocols.impl.AbstractResponseEncoder;
 import org.apache.james.protocols.impl.AbstractSSLAwareChannelPipelineFactory;
 import org.apache.james.protocols.impl.BasicChannelUpstreamHandler;
-import org.apache.james.protocols.smtp.SMTPConfiguration;
-import org.apache.james.protocols.smtp.SMTPResponse;
-import org.apache.james.protocols.smtp.SMTPSessionImpl;
 import org.jboss.netty.channel.ChannelPipelineFactory;
 import org.jboss.netty.channel.ChannelUpstreamHandler;
 import org.jboss.netty.channel.group.ChannelGroup;
@@ -48,7 +42,7 @@ import org.slf4j.LoggerFactory;
  */
 public class NettyServer extends AbstractAsyncServer {
 
-    private ProtocolHandlerChain chain;
+    private Protocol protocol;
     
     private Logger logger = LoggerFactory.getLogger(NettyServer.class);
 
@@ -56,25 +50,20 @@ public class NettyServer extends Abstrac
 
     private ExecutionHandler eHandler;
 
-   
-    /**
-     * The configuration data to be passed to the handler
-     */
-    private final SMTPConfiguration theConfigData;
-
-    private final static OneToOneEncoder SMTP_RESPONSE_ENCODER = new 
AbstractResponseEncoder(SMTPResponse.class, Charset.forName("US-ASCII"));
+    private OneToOneEncoder responseEncoder;
+    
     private ChannelUpstreamHandler coreHandler;
 
-    public NettyServer(SMTPConfiguration theConfigData, ProtocolHandlerChain 
chain) {
-        this(theConfigData, chain, null);
+    public NettyServer(Protocol protocol) {
+        this(protocol, null);
     }
     
     
-    public NettyServer(SMTPConfiguration theConfigData, ProtocolHandlerChain 
chain, SSLContext context) {
+    public NettyServer(Protocol protocol, SSLContext context) {
         super();
-        this.chain  = chain;
+        this.protocol = protocol;
         this.context = context;
-        this.theConfigData = theConfigData;
+        this.responseEncoder = new 
AbstractResponseEncoder(protocol.getResponseClass(), 
Charset.forName("US-ASCII"));
     }
     
     protected ExecutionHandler createExecutionHandler(int size) {
@@ -101,12 +90,7 @@ public class NettyServer extends Abstrac
     
     @Override
     public synchronized void bind() throws Exception {
-        coreHandler = new BasicChannelUpstreamHandler(chain, new 
ProtocolSessionFactory() {
-            
-            public ProtocolSession newSession(ProtocolTransport transport) {
-                return new SMTPSessionImpl(theConfigData, logger, transport);
-            }
-        }, logger, context, null);
+        coreHandler = new 
BasicChannelUpstreamHandler(protocol.getProtocolChain(), 
protocol.getProtocolSessionFactory(), logger, context, null);
         super.bind();
     }
 
@@ -122,12 +106,12 @@ public class NettyServer extends Abstrac
 
             @Override
             protected OneToOneEncoder createEncoder() {
-                return SMTP_RESPONSE_ENCODER;
+                return responseEncoder;
             }
 
             @Override
             protected boolean isSSLSocket() {
-                return context != null && !theConfigData.isStartTLSSupported();
+                return context != null && !protocol.isStartTLSSupported();
             }
 
             @Override

Added: 
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPProtocol.java
URL: 
http://svn.apache.org/viewvc/james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPProtocol.java?rev=1171877&view=auto
==============================================================================
--- 
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPProtocol.java
 (added)
+++ 
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPProtocol.java
 Sat Sep 17 00:31:36 2011
@@ -0,0 +1,68 @@
+/****************************************************************
+ * 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.smtp.netty;
+
+import org.apache.james.protocols.api.Protocol;
+import org.apache.james.protocols.api.ProtocolHandlerChain;
+import org.apache.james.protocols.api.ProtocolSession;
+import org.apache.james.protocols.api.ProtocolSessionFactory;
+import org.apache.james.protocols.api.ProtocolTransport;
+import org.apache.james.protocols.api.Response;
+import org.apache.james.protocols.smtp.SMTPConfiguration;
+import org.apache.james.protocols.smtp.SMTPProtocolHandlerChain;
+import org.apache.james.protocols.smtp.SMTPResponse;
+import org.apache.james.protocols.smtp.SMTPSessionImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SMTPProtocol implements Protocol {
+
+    private SMTPProtocolHandlerChain chain;
+    private SMTPConfiguration config;
+    private Logger logger = LoggerFactory.getLogger(SMTPProtocol.class);
+
+
+    public SMTPProtocol(SMTPProtocolHandlerChain chain, SMTPConfiguration 
config) {
+        this.chain = chain;
+        this.config = config;
+    }
+    
+    public ProtocolHandlerChain getProtocolChain() {
+        return chain;
+    }
+
+    public ProtocolSessionFactory getProtocolSessionFactory() {
+        return new ProtocolSessionFactory() {
+            
+            public ProtocolSession newSession(ProtocolTransport transport) {
+                return new SMTPSessionImpl(config, logger, transport);
+            }
+        };
+    }
+
+    public boolean isStartTLSSupported() {
+        return config.isStartTLSSupported();
+    }
+
+    public Class<? extends Response> getResponseClass() {
+        return SMTPResponse.class;
+    }
+
+}

Propchange: 
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPProtocol.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPServer.java
URL: 
http://svn.apache.org/viewvc/james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPServer.java?rev=1171877&r1=1171876&r2=1171877&view=diff
==============================================================================
--- 
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPServer.java
 (original)
+++ 
james/protocols/trunk/smtp-netty/src/main/java/org/apache/james/protocols/smtp/netty/SMTPServer.java
 Sat Sep 17 00:31:36 2011
@@ -38,7 +38,7 @@ public class SMTPServer extends NettySer
     
     
     public SMTPServer(SMTPConfiguration theConfigData, 
SMTPProtocolHandlerChain chain, SSLContext context, boolean starttls) {
-        super(new StartTLSSMTPConfiguration(theConfigData, starttls), chain, 
context);
+        super(new SMTPProtocol(chain, new 
StartTLSSMTPConfiguration(theConfigData, starttls)), context);
         this.starttls = starttls;
     }
     



---------------------------------------------------------------------
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