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 bt...@apache.org on 2019/11/13 03:06:53 UTC

[james-project] 04/21: [Refactoring] Remove unused methods from protocols-netty

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit e402b151047ca709e5870d9126352c38ec71d58d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Nov 8 16:41:12 2019 +0700

    [Refactoring] Remove unused methods from protocols-netty
    
     - ExecutionHandler is never effectively used
     - Dynamic changes in connection limits are never used
---
 .../james/protocols/netty/AbstractAsyncServer.java |  8 -----
 .../netty/AbstractChannelPipelineFactory.java      |  6 ----
 .../netty/ConnectionLimitUpstreamHandler.java      | 10 +-----
 .../netty/ConnectionPerIpLimitUpstreamHandler.java | 19 ++--------
 .../apache/james/protocols/netty/NettyServer.java  | 41 ----------------------
 .../james/imapserver/netty/OioIMAPServer.java      |  8 -----
 .../james/lmtpserver/netty/OioLMTPServer.java      | 11 ------
 .../james/pop3server/netty/OioPOP3Server.java      |  9 -----
 .../james/smtpserver/netty/OioSMTPServer.java      |  9 -----
 9 files changed, 3 insertions(+), 118 deletions(-)

diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java
index a7aef3c..036699e 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractAsyncServer.java
@@ -74,14 +74,6 @@ public abstract class AbstractAsyncServer implements ProtocolServer {
         }
         this.ioWorker = ioWorker;
     }
-    
-    /**
-     * Return the IO worker thread count to use
-     */
-    public int getIoWorkerCount() {
-        return ioWorker;
-    }
-    
 
     @Override
     public synchronized void bind() throws Exception {
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractChannelPipelineFactory.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractChannelPipelineFactory.java
index 5f242e7..fb3554f 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractChannelPipelineFactory.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractChannelPipelineFactory.java
@@ -41,12 +41,6 @@ public abstract class AbstractChannelPipelineFactory implements ChannelPipelineF
     private final int timeout;
     private final ExecutionHandler eHandler;
     private final ChannelHandlerFactory frameHandlerFactory;
-
-    public AbstractChannelPipelineFactory(int timeout, int maxConnections, int maxConnectsPerIp, ChannelGroup channels,
-                                          HashedWheelTimer hashedWheelTimer) {
-        this(timeout, maxConnections, maxConnectsPerIp, channels, null,
-            new LineDelimiterBasedChannelHandlerFactory(MAX_LINE_LENGTH), hashedWheelTimer);
-    }
     
     public AbstractChannelPipelineFactory(int timeout, int maxConnections, int maxConnectsPerIp, ChannelGroup channels,
                                           ExecutionHandler eHandler, ChannelHandlerFactory frameHandlerFactory,
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/ConnectionLimitUpstreamHandler.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/ConnectionLimitUpstreamHandler.java
index 73c71d0..9478a1d 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/ConnectionLimitUpstreamHandler.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/ConnectionLimitUpstreamHandler.java
@@ -42,15 +42,7 @@ public class ConnectionLimitUpstreamHandler extends SimpleChannelUpstreamHandler
     public ConnectionLimitUpstreamHandler(int maxConnections) {
         this.maxConnections = maxConnections;
     }
-    
-    public int getConnections() {
-        return connections.get();
-    }
-    
-    public void setMaxConnections(int maxConnections) {
-        this.maxConnections = maxConnections;
-    }
-    
+
     @Override
     public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
         if (maxConnections > 0) {
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/ConnectionPerIpLimitUpstreamHandler.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/ConnectionPerIpLimitUpstreamHandler.java
index eab1314..191493d 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/ConnectionPerIpLimitUpstreamHandler.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/ConnectionPerIpLimitUpstreamHandler.java
@@ -40,29 +40,14 @@ import org.jboss.netty.channel.SimpleChannelUpstreamHandler;
 public class ConnectionPerIpLimitUpstreamHandler extends SimpleChannelUpstreamHandler {
 
     private final ConcurrentMap<String, AtomicInteger> connections = new ConcurrentHashMap<>();
-    private volatile int maxConnectionsPerIp = -1;
+    private final int maxConnectionsPerIp;
     
     public ConnectionPerIpLimitUpstreamHandler(int maxConnectionsPerIp) {
         this.maxConnectionsPerIp = maxConnectionsPerIp;
     }
-    
-    public int getConnections(String ip) {
-        AtomicInteger count = connections.get(ip);
-        if (count == null) {
-            return 0;
-        } else {
-            return count.get();
-        }
-    }
-    
-    public void setMaxConnectionsPerIp(int maxConnectionsPerIp) {
-        this.maxConnectionsPerIp = maxConnectionsPerIp;
-    }
-    
-    
+
     @Override
     public void channelOpen(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
-
         if (maxConnectionsPerIp > 0) {
             InetSocketAddress remoteAddress = (InetSocketAddress) ctx.getChannel().getRemoteAddress();
             String remoteIp = remoteAddress.getAddress().getHostAddress();
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java
index ed8dea6..2912faf 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyServer.java
@@ -25,12 +25,10 @@ import javax.net.ssl.SSLContext;
 
 import org.apache.james.protocols.api.Encryption;
 import org.apache.james.protocols.api.Protocol;
-import org.apache.james.protocols.api.handler.ProtocolHandler;
 import org.jboss.netty.channel.ChannelPipelineFactory;
 import org.jboss.netty.channel.ChannelUpstreamHandler;
 import org.jboss.netty.channel.group.ChannelGroup;
 import org.jboss.netty.handler.execution.ExecutionHandler;
-import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
 import org.jboss.netty.util.HashedWheelTimer;
 
 import com.google.common.base.Preconditions;
@@ -101,45 +99,6 @@ public class NettyServer extends AbstractAsyncServer {
         this.hashedWheelTimer = hashedWheelTimer;
     }
     
-    protected ExecutionHandler createExecutionHandler(int size) {
-        return new ExecutionHandler(new OrderedMemoryAwareThreadPoolExecutor(size, 0, 0));
-    }
-    
-    
-    /**
-     * 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) {
-            eHandler = createExecutionHandler(size);
-        } else {
-            if (eHandler != null) {
-                eHandler.releaseExternalResources();
-            }
-            eHandler = null;
-        }
-    }
-    
-    public void setMaxConcurrentConnections(int maxCurConnections) {
-        if (isBound()) {
-            throw new IllegalStateException("Server running already");
-        }
-        this.maxCurConnections = maxCurConnections;
-    }
-  
-    public void setMaxConcurrentConnectionsPerIP(int maxCurConnectionsPerIP) {
-        if (isBound()) {
-            throw new IllegalStateException("Server running already");
-        }
-        this.maxCurConnectionsPerIP = maxCurConnectionsPerIP;
-    }
-    
     protected ChannelUpstreamHandler createCoreHandler() {
         return new BasicChannelUpstreamHandler(protocol, secure);
     }
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java
index 90e4d4a..749b8f3 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/OioIMAPServer.java
@@ -41,14 +41,6 @@ public class OioIMAPServer extends IMAPServer {
     }
 
     /**
-     * Return -1 as it is not known
-     */
-    @Override
-    public int getIoWorkerCount() {
-        return -1;
-    }
-
-    /**
      * As OIO use one thread per connection we disable the use of the {@link ExecutionHandler}
      */
     @Override
diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServer.java b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServer.java
index 0653b24..617dfe6 100644
--- a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServer.java
+++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/netty/OioLMTPServer.java
@@ -39,17 +39,6 @@ public class OioLMTPServer extends LMTPServer {
     }
 
     /**
-     * Return -1 as it is not known
-     * 
-     * 
-     */
-    @Override
-    public int getIoWorkerCount() {
-        return -1;
-    }
-
-
-    /**
      * As OIO use one thread per connection we disable the use of the {@link ExecutionHandler}
      * 
      */
diff --git a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/netty/OioPOP3Server.java b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/netty/OioPOP3Server.java
index 42ab618..adae9b7 100644
--- a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/netty/OioPOP3Server.java
+++ b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/netty/OioPOP3Server.java
@@ -34,15 +34,6 @@ public class OioPOP3Server extends POP3Server {
     }
 
     /**
-     * Return -1 as it is not known
-     */
-    @Override
-    public int getIoWorkerCount() {
-        return -1;
-    }
-    
-
-    /**
      * As OIO use one thread per connection we disable the use of the {@link ExecutionHandler}
      * 
      */
diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServer.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServer.java
index 03eb423..b40ad5d 100644
--- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServer.java
+++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/netty/OioSMTPServer.java
@@ -38,15 +38,6 @@ public class OioSMTPServer extends SMTPServer {
     }
 
     /**
-     * Return -1 as it is not known
-     */
-    @Override
-    public int getIoWorkerCount() {
-        return -1;
-    }
-
-
-    /**
      * As OIO use one thread per connection we disable the use of the {@link ExecutionHandler}
      * 
      */


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