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 2010/06/09 21:56:10 UTC

svn commit: r953133 - in /james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl: AbstractAsyncServer.java AbstractChannelPipelineFactory.java AbstractSSLAwareChannelPipelineFactory.java ChannelGroupHandler.java

Author: norman
Date: Wed Jun  9 19:56:10 2010
New Revision: 953133

URL: http://svn.apache.org/viewvc?rev=953133&view=rev
Log:
We need to add the ChannelGroupHandler in the factory so it is added on each connection. This should fix the waiting connections (JAMES-1014)

Added:
    james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/ChannelGroupHandler.java
Modified:
    james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractAsyncServer.java
    james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelPipelineFactory.java
    james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractSSLAwareChannelPipelineFactory.java

Modified: james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractAsyncServer.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractAsyncServer.java?rev=953133&r1=953132&r2=953133&view=diff
==============================================================================
--- james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractAsyncServer.java (original)
+++ james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractAsyncServer.java Wed Jun  9 19:56:10 2010
@@ -23,11 +23,7 @@ import java.util.concurrent.Executors;
 
 import org.jboss.netty.bootstrap.ServerBootstrap;
 import org.jboss.netty.channel.Channel;
-import org.jboss.netty.channel.ChannelHandlerContext;
-import org.jboss.netty.channel.ChannelPipelineCoverage;
 import org.jboss.netty.channel.ChannelPipelineFactory;
-import org.jboss.netty.channel.ChannelStateEvent;
-import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
 import org.jboss.netty.channel.group.ChannelGroup;
 import org.jboss.netty.channel.group.DefaultChannelGroup;
 import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
@@ -86,11 +82,8 @@ public abstract class AbstractAsyncServe
         if (port < 1) throw new RuntimeException("Please specify a port to which the server should get bound!");
 
         bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
-        ChannelPipelineFactory factory = createPipelineFactory();
+        ChannelPipelineFactory factory = createPipelineFactory(channels);
         
-        // add the channel group handler
-        factory.getPipeline().addFirst("channelGroupHandler", new ChannelGroupHandler());
-
         // Configure the pipeline factory.
         bootstrap.setPipelineFactory(factory);
 
@@ -145,7 +138,7 @@ public abstract class AbstractAsyncServe
      * 
      * @return factory
      */
-    protected abstract ChannelPipelineFactory createPipelineFactory();
+    protected abstract ChannelPipelineFactory createPipelineFactory(ChannelGroup group);
 
     /**
      * Set the read/write timeout for the server. This will throw a {@link IllegalStateException} if the
@@ -185,17 +178,4 @@ public abstract class AbstractAsyncServe
         return timeout;
     }
 
-    /**
-     * Add channels to the channel group after the channel was opened
-     *
-     */
-    @ChannelPipelineCoverage("all")
-    private final class ChannelGroupHandler extends SimpleChannelUpstreamHandler {
-        public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) {
-            // Add all open channels to the global group so that they are
-            // closed on shutdown.
-            channels.add(e.getChannel());
-        }
-
-    }
 }

Modified: james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelPipelineFactory.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelPipelineFactory.java?rev=953133&r1=953132&r2=953133&view=diff
==============================================================================
--- james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelPipelineFactory.java (original)
+++ james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractChannelPipelineFactory.java Wed Jun  9 19:56:10 2010
@@ -18,13 +18,13 @@
  ****************************************************************/
 package org.apache.james.protocols.impl;
 
-import static org.jboss.netty.channel.Channels.*;
-
+import static org.jboss.netty.channel.Channels.pipeline;
 
 import org.apache.james.protocols.api.Response;
 import org.jboss.netty.channel.ChannelPipeline;
 import org.jboss.netty.channel.ChannelPipelineFactory;
 import org.jboss.netty.channel.ChannelUpstreamHandler;
+import org.jboss.netty.channel.group.ChannelGroup;
 import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
 import org.jboss.netty.handler.codec.frame.Delimiters;
 import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
@@ -44,11 +44,12 @@ public abstract class AbstractChannelPip
     private final ConnectionLimitUpstreamHandler connectionLimitHandler;
     private final ConnectionPerIpLimitUpstreamHandler connectionPerIpLimitHandler;
     private TimeoutHandler timeoutHandler;
-    
-    public AbstractChannelPipelineFactory(int timeout, int maxConnections, int maxConnectsPerIp) {
+    private ChannelGroupHandler groupHandler;
+    public AbstractChannelPipelineFactory(int timeout, int maxConnections, int maxConnectsPerIp, ChannelGroup channels) {
         timeoutHandler = new TimeoutHandler(new HashedWheelTimer(), timeout, timeout, 0);
         connectionLimitHandler = new ConnectionLimitUpstreamHandler(maxConnections);
         connectionPerIpLimitHandler = new ConnectionPerIpLimitUpstreamHandler(maxConnectsPerIp);
+        groupHandler = new ChannelGroupHandler(channels);
     }
     
     
@@ -60,6 +61,7 @@ public abstract class AbstractChannelPip
         // Create a default pipeline implementation.
         ChannelPipeline pipeline = pipeline();
         
+        pipeline.addLast("groupHandler", groupHandler);
         pipeline.addLast("connectionLimit", connectionLimitHandler);
 
         pipeline.addLast("connectionPerIpLimit", connectionPerIpLimitHandler);
@@ -79,6 +81,9 @@ public abstract class AbstractChannelPip
         return pipeline;
     }
 
+
+
+    
     /**
      * Create the core {@link ChannelUpstreamHandler} to use
      * 

Modified: james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractSSLAwareChannelPipelineFactory.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractSSLAwareChannelPipelineFactory.java?rev=953133&r1=953132&r2=953133&view=diff
==============================================================================
--- james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractSSLAwareChannelPipelineFactory.java (original)
+++ james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/AbstractSSLAwareChannelPipelineFactory.java Wed Jun  9 19:56:10 2010
@@ -21,6 +21,7 @@ package org.apache.james.protocols.impl;
 import javax.net.ssl.SSLContext;
 
 import org.jboss.netty.channel.ChannelPipeline;
+import org.jboss.netty.channel.group.ChannelGroup;
 import org.jboss.netty.handler.ssl.SslHandler;
 
 /**
@@ -32,8 +33,8 @@ public abstract class AbstractSSLAwareCh
 
     
     public AbstractSSLAwareChannelPipelineFactory(int timeout,
-            int maxConnections, int maxConnectsPerIp) {
-        super(timeout, maxConnections, maxConnectsPerIp);
+            int maxConnections, int maxConnectsPerIp, ChannelGroup group) {
+        super(timeout, maxConnections, maxConnectsPerIp, group);
     }
 
     @Override

Added: james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/ChannelGroupHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/ChannelGroupHandler.java?rev=953133&view=auto
==============================================================================
--- james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/ChannelGroupHandler.java (added)
+++ james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/ChannelGroupHandler.java Wed Jun  9 19:56:10 2010
@@ -0,0 +1,45 @@
+/****************************************************************
+ * 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.impl;
+
+import org.jboss.netty.channel.ChannelHandlerContext;
+import org.jboss.netty.channel.ChannelPipelineCoverage;
+import org.jboss.netty.channel.ChannelStateEvent;
+import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
+import org.jboss.netty.channel.group.ChannelGroup;
+
+/**
+ * Add channels to the channel group after the channel was opened
+ *
+ */
+@ChannelPipelineCoverage("all")
+public final class ChannelGroupHandler extends SimpleChannelUpstreamHandler {
+    private ChannelGroup channels;
+    public ChannelGroupHandler(ChannelGroup channels) {
+        this.channels = channels;
+    }
+    
+    public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) {
+        // Add all open channels to the global group so that they are
+        // closed on shutdown.
+        channels.add(e.getChannel());
+    }
+
+}
\ No newline at end of file



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