james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r951509 - /james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java
Date Fri, 04 Jun 2010 17:54:34 GMT
Author: norman
Date: Fri Jun  4 17:54:33 2010
New Revision: 951509

URL: http://svn.apache.org/viewvc?rev=951509&view=rev
Log:
Close open channels on shutdown. See JAMES-1014

Modified:
    james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java

Modified: james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java?rev=951509&r1=951508&r2=951509&view=diff
==============================================================================
--- james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java
(original)
+++ james/server/trunk/netty-socket/src/main/java/org/apache/james/socket/netty/AbstractAsyncServer.java
Fri Jun  4 17:54:33 2010
@@ -41,7 +41,13 @@ import org.apache.james.lifecycle.LogEna
 import org.apache.james.services.FileSystem;
 import org.apache.james.services.MailServer;
 import org.jboss.netty.bootstrap.ServerBootstrap;
+import org.jboss.netty.channel.Channel;
+import org.jboss.netty.channel.ChannelHandlerContext;
 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;
 
 /**
@@ -111,8 +117,9 @@ public abstract class AbstractAsyncServe
 
     private SSLContext context;
 
-    private ServerBootstrap bootstrap;  
+    private ServerBootstrap bootstrap;
 
+    private ChannelGroup channels = new DefaultChannelGroup();
     @Resource(name="dnsserver")
     public final void setDNSService(DNSService dns) {
         this.dns = dns;
@@ -272,22 +279,23 @@ public abstract class AbstractAsyncServe
                                                    Executors.newCachedThreadPool(),
                                            Executors.newCachedThreadPool()));
             // Configure the pipeline factory.
+            ChannelPipelineFactory factory = createPipelineFactory();
+            factory.getPipeline().addFirst("channelGroupHandler", new ChannelGroupHandler());
             bootstrap.setPipelineFactory(createPipelineFactory());
          
             // Bind and start to accept incoming connections.
             bootstrap.setOption("backlog",backlog);
             bootstrap.setOption("reuseAddress",true);
 
-            //acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, timeout );
-            //acceptor.setHandler(createIoHandler());
-            bootstrap.bind(new InetSocketAddress(bindTo,port));
+            Channel serverChannel = bootstrap.bind(new InetSocketAddress(bindTo,port));
+            channels.add(serverChannel);
         }
     }
 
     @PreDestroy
     public final void destroy() {
         getLogger().info("Dispose " + getServiceType());
-        
+        channels.close().awaitUninterruptibly();
         bootstrap.releaseExternalResources();
     }
     
@@ -485,4 +493,18 @@ public abstract class AbstractAsyncServe
     protected SSLContext getSSLContext() {
         return context;
     }
+    
+    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());
+        }
+
+        @Override
+        public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws
Exception {
+           channels.remove(ctx.getChannel());
+        }
+
+    }
 }



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


Mime
View raw message