james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r1221145 - in /james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty: ConnectionLimitUpstreamHandler.java ConnectionPerIpLimitUpstreamHandler.java NettyServer.java
Date Tue, 20 Dec 2011 08:40:43 GMT
Author: norman
Date: Tue Dec 20 08:40:43 2011
New Revision: 1221145

URL: http://svn.apache.org/viewvc?rev=1221145&view=rev
Log:
Allow to set maximal current connections in NettyServer. See PROTOCOLS-57

Modified:
    james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/ConnectionLimitUpstreamHandler.java
    james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/ConnectionPerIpLimitUpstreamHandler.java
    james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java

Modified: james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/ConnectionLimitUpstreamHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/ConnectionLimitUpstreamHandler.java?rev=1221145&r1=1221144&r2=1221145&view=diff
==============================================================================
--- james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/ConnectionLimitUpstreamHandler.java
(original)
+++ james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/ConnectionLimitUpstreamHandler.java
Tue Dec 20 08:40:43 2011
@@ -37,7 +37,7 @@ import org.jboss.netty.channel.SimpleCha
 public class ConnectionLimitUpstreamHandler extends SimpleChannelUpstreamHandler{
 
     private final AtomicInteger connections = new AtomicInteger(0);
-    private int maxConnections;
+    private volatile int maxConnections = -1;
     
     public ConnectionLimitUpstreamHandler(int maxConnections) {
         this.maxConnections = maxConnections;

Modified: james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/ConnectionPerIpLimitUpstreamHandler.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/ConnectionPerIpLimitUpstreamHandler.java?rev=1221145&r1=1221144&r2=1221145&view=diff
==============================================================================
--- james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/ConnectionPerIpLimitUpstreamHandler.java
(original)
+++ james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/ConnectionPerIpLimitUpstreamHandler.java
Tue Dec 20 08:40:43 2011
@@ -40,7 +40,7 @@ import org.jboss.netty.channel.SimpleCha
 public class ConnectionPerIpLimitUpstreamHandler extends SimpleChannelUpstreamHandler{
 
     private final ConcurrentMap<String, AtomicInteger> connections = new ConcurrentHashMap<String,
AtomicInteger>();    
-    private int maxConnectionsPerIp;
+    private volatile int maxConnectionsPerIp = -1;
     
     public ConnectionPerIpLimitUpstreamHandler(int maxConnectionsPerIp) {
         this.maxConnectionsPerIp = maxConnectionsPerIp;

Modified: james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java
URL: http://svn.apache.org/viewvc/james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java?rev=1221145&r1=1221144&r2=1221145&view=diff
==============================================================================
--- james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java
(original)
+++ james/protocols/trunk/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java
Tue Dec 20 08:40:43 2011
@@ -23,6 +23,8 @@ import javax.net.ssl.SSLContext;
 
 import org.apache.james.protocols.api.Protocol;
 import org.apache.james.protocols.api.Encryption;
+import org.apache.james.protocols.api.handler.ProtocolHandler;
+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;
@@ -32,7 +34,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Generic NettyServer
+ * Generic NettyServer 
  */
 public class NettyServer extends AbstractAsyncServer {
 
@@ -46,6 +48,11 @@ public class NettyServer extends Abstrac
 
     protected final Encryption secure;
 
+    private final ConnectionLimitUpstreamHandler connLimit = new ConnectionLimitUpstreamHandler(-1);
+
+    
+    private final ConnectionPerIpLimitUpstreamHandler connPerIPLimit =  new ConnectionPerIpLimitUpstreamHandler(-1);
+   
     public NettyServer(Protocol protocol) {
         this(protocol, null);
     }
@@ -62,6 +69,12 @@ public class NettyServer extends Abstrac
     }
     
     
+    /**
+     * Set true if an ExecutionHandler should be used to hand over the tasks. This should
be done if you have some {@link ProtocolHandler}'s which need to full fill some blocking operation.
+     * 
+     * @param useHandler <code>true</code> if an ExecutionHandler should be used
+     * @param size the thread count to use
+     */
     public void setUseExecutionHandler(boolean useHandler, int size) {
         if (isBound()) throw new IllegalStateException("Server running already");
         if (useHandler) {
@@ -74,7 +87,13 @@ public class NettyServer extends Abstrac
         }
     }
     
+    public void setMaxConcurrentConnections(int maxCurConnections) {
+        connLimit.setMaxConnections(maxCurConnections);
+    }
   
+    public void setMaxConcurrentConnectionsPerIP(int maxCurConnectionsPerIP) {
+        connPerIPLimit.setMaxConnectionsPerIp(maxCurConnectionsPerIP);
+    }
     protected ChannelUpstreamHandler createCoreHandler() {
         return new BasicChannelUpstreamHandler(protocol, logger, secure);
     }
@@ -88,7 +107,17 @@ public class NettyServer extends Abstrac
 
     @Override
     protected ChannelPipelineFactory createPipelineFactory(ChannelGroup group) {
+
         return new AbstractSSLAwareChannelPipelineFactory(getTimeout(), 0, getBacklog(),
group, eHandler) {
+            
+            @Override
+            public ChannelPipeline getPipeline() throws Exception {
+                ChannelPipeline cp =  super.getPipeline();
+                cp.addFirst(HandlerConstants.CONNECTION_PER_IP_LIMIT_HANDLER, connPerIPLimit);
+                cp.addFirst(HandlerConstants.CONNECTION_LIMIT_HANDLER, connLimit);
+                
+                return cp;
+            }
 
             @Override
             protected ChannelUpstreamHandler createHandler() {



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