You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by bt...@apache.org on 2022/04/04 05:45:09 UTC

[james-project] branch master updated (23f6d3c56c -> 1b3c66c07d)

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

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


    from 23f6d3c56c JAMES-3739 Allow IndexCreation factory to use custom analyzers and tokenizers (#946)
     new 9244a32027 JAMES-3715 ManageSieveServer: apply maxLineLength
     new 3eccd03c4c JAMES-3715 Apply NETTY-311 suggestions
     new a17d3ca388 JAMES-3715 ConnectionCountHandler state was unused by production code
     new 981c699b9a JAMES-3715 Fix some small sonarlint related issues in protocols/netty
     new 50f43a922c JAMES-3715 ConnectionPerIpLimitUpstreamHandler: counter not incremented upon insert conflict
     new 6a9fd712e0 JAMES-3715 AbstractConfigurableAsyncServer: Remove unused file input stream
     new 269d2260f4 JAMES-3715 Fix various Sonar warnings in protocol-library
     new 50a67b8ef6 JAMES-3715 Remove unused class JMXEnabledOrderedMemoryAwareThreadPoolExecutorMBean
     new ce87d835df JAMES-3715 Fix small warnings in AbstractServerFactory
     new fa2e561b7d JAMES-3715 AllButStartTlsLineChannelHandlerFactory maxFrameLength may be final
     new b8e61fc5c5 JAMES-3715 SwitchableLineBasedFrameDecoderFactory: maxLineLength can be final
     new ed2f6ade13 JAMES-3715 HandlerConstants: remove unused constants
     new 9e780efd44 JAMES-3715 NettyImapRequestLineReader: Avoid allocating an int for each IMAP char
     new 02ecc33bd1 JAMES-3715 IMAP avoid writing stacktrace for NotEnoughDataException
     new 406b15f597 JAMES-3715 Apply NETTY-311 suggestions
     new cc10ba2b37 JAMES-3715 ManageSieve: Avoid chuncking byte arrays
     new befc8ddc78 JAMES-3715 Call GhostMailbox logger only if needed
     new d2cfcad616 JAMES-3715 Fix a checkstyle issue
     new 1b3c66c07d JAMES-3715 Configure bootstrap before binding it...

The 19 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../james/mailbox/cassandra/GhostMailbox.java      |  4 +
 .../cassandra/mail/CassandraMailboxPathV3DAO.java  | 16 ++--
 .../james/protocols/netty/AbstractAsyncServer.java |  6 +-
 .../netty/AbstractChannelPipelineFactory.java      | 16 ++--
 .../AbstractSSLAwareChannelPipelineFactory.java    |  3 +-
 .../AllButStartTlsLineChannelHandlerFactory.java   |  2 +-
 .../netty/BasicChannelInboundHandler.java          |  4 +-
 .../netty/ConnectionLimitUpstreamHandler.java      | 26 +++---
 .../netty/ConnectionPerIpLimitUpstreamHandler.java | 46 ++++++-----
 .../james/protocols/netty/HandlerConstants.java    | 10 +--
 .../protocols/netty/NettyProtocolTransport.java    | 23 +++---
 .../protocols/netty/ProtocolMDCContextFactory.java |  4 +-
 .../apache/james/imapserver/netty/IMAPServer.java  | 12 ++-
 .../james/imapserver/netty/NettyConstants.java     |  3 -
 .../netty/NettyImapRequestLineReader.java          | 15 ++--
 .../SwitchableLineBasedFrameDecoderFactory.java    |  3 +-
 .../james/protocols/lib/POP3BeforeSMTPHelper.java  | 31 ++-----
 .../protocols/lib/ProtocolHandlerChainImpl.java    |  2 +-
 .../protocols/lib/jmx/ConnectHandlerStats.java     |  2 +-
 .../james/protocols/lib/jmx/LineHandlerStats.java  |  2 +-
 .../james/protocols/lib/jmx/ServerMBean.java       | 10 ---
 .../lib/netty/AbstractConfigurableAsyncServer.java | 95 ++++++++--------------
 ...bstractExecutorAwareChannelPipelineFactory.java | 49 -----------
 .../protocols/lib/netty/AbstractServerFactory.java |  8 +-
 .../lib/netty/ConnectionCountHandler.java          | 68 ----------------
 ...dOrderedMemoryAwareThreadPoolExecutorMBean.java | 25 ------
 .../lib/AbstractConfigurableAsyncServerTest.java   | 27 +++---
 .../netty/ChannelManageSieveResponseWriter.java    |  7 +-
 .../netty/ManageSieveChannelUpstreamHandler.java   | 18 ++--
 .../managesieveserver/netty/ManageSieveServer.java | 32 ++++++--
 .../apache/james/smtpserver/SMTPServerTest.java    | 11 +--
 31 files changed, 200 insertions(+), 380 deletions(-)
 delete mode 100644 server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractExecutorAwareChannelPipelineFactory.java
 delete mode 100644 server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/ConnectionCountHandler.java
 delete mode 100644 server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/JMXEnabledOrderedMemoryAwareThreadPoolExecutorMBean.java


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


[james-project] 14/19: JAMES-3715 IMAP avoid writing stacktrace for NotEnoughDataException

Posted by bt...@apache.org.
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 02ecc33bd1ab42665d4f0c6c02d786ed4dad8549
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Mar 22 11:03:05 2022 +0700

    JAMES-3715 IMAP avoid writing stacktrace for NotEnoughDataException
    
    This stacktrace is never used...
---
 .../apache/james/imapserver/netty/NettyImapRequestLineReader.java   | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java
index e7a2d246db..a2255e2f20 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java
@@ -122,11 +122,15 @@ public class NettyImapRequestLineReader extends AbstractNettyImapRequestLineRead
      * readable in the underlying {@link ByteBuf}
      */
     public static final class NotEnoughDataException extends RuntimeException {
-
         public static final int UNKNOWN_SIZE = -1;
+        private static final String NO_MESSAGE = null;
+        private static final Throwable NO_CAUSE = null;
+        private static final boolean DISABLE_SUPPRESSION = false;
+
         private final int size;
 
         public NotEnoughDataException(int size) {
+            super(NO_MESSAGE, NO_CAUSE, DISABLE_SUPPRESSION, false);
             this.size = size;
         }
 


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


[james-project] 04/19: JAMES-3715 Fix some small sonarlint related issues in protocols/netty

Posted by bt...@apache.org.
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 981c699b9a7095a18fcd806d5ae8c575d4c060d3
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 3 12:11:07 2022 +0700

    JAMES-3715 Fix some small sonarlint related issues in protocols/netty
---
 .../AbstractSSLAwareChannelPipelineFactory.java    |  3 +--
 .../netty/BasicChannelInboundHandler.java          |  4 +--
 .../protocols/netty/NettyProtocolTransport.java    | 23 +++++++---------
 .../protocols/netty/ProtocolMDCContextFactory.java |  4 +--
 .../james/protocols/lib/POP3BeforeSMTPHelper.java  | 31 +++++-----------------
 .../lib/AbstractConfigurableAsyncServerTest.java   | 27 ++++++++++---------
 6 files changed, 36 insertions(+), 56 deletions(-)

diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
index 2203efd5f8..2292c28401 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AbstractSSLAwareChannelPipelineFactory.java
@@ -56,9 +56,8 @@ public abstract class AbstractSSLAwareChannelPipelineFactory<C extends SocketCha
     public void initChannel(C channel) throws Exception {
         super.initChannel(channel);
 
-        ChannelPipeline pipeline = channel.pipeline();
-
         if (isSSLSocket()) {
+            ChannelPipeline pipeline = channel.pipeline();
             // We need to set clientMode to false.
             // See https://issues.apache.org/jira/browse/JAMES-1025
             SSLEngine engine = secure.createSSLEngine();
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
index 7fc2fbcbf9..3db739e422 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/BasicChannelInboundHandler.java
@@ -162,10 +162,10 @@ public class BasicChannelInboundHandler extends ChannelInboundHandlerAdapter imp
             LinkedList<ProtocolHandlerResultHandler> resultHandlers = chain.getHandlers(ProtocolHandlerResultHandler.class);
 
 
-            if (lineHandlers.size() > 0) {
+            if (!lineHandlers.isEmpty()) {
 
                 ByteBuf buf = (ByteBuf) msg;
-                LineHandler lHandler = (LineHandler) lineHandlers.getLast();
+                LineHandler lHandler = lineHandlers.getLast();
                 long start = System.currentTimeMillis();
                 Response response = lHandler.onLine(pSession, buf.nioBuffer());
                 long executionTime = System.currentTimeMillis() - start;
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java
index c5cc824c0e..c7509383ea 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/NettyProtocolTransport.java
@@ -33,7 +33,6 @@ import org.apache.james.protocols.api.handler.LineHandler;
 
 import io.netty.buffer.Unpooled;
 import io.netty.channel.Channel;
-import io.netty.channel.ChannelFuture;
 import io.netty.channel.ChannelFutureListener;
 import io.netty.channel.DefaultFileRegion;
 import io.netty.handler.ssl.SslHandler;
@@ -96,7 +95,7 @@ public class NettyProtocolTransport extends AbstractProtocolTransport {
             prepareStartTLS();
         }
 
-        ChannelFuture future = channel.writeAndFlush(Unpooled.wrappedBuffer(bytes));
+        channel.writeAndFlush(Unpooled.wrappedBuffer(bytes));
     }
 
     @Override
@@ -110,18 +109,16 @@ public class NettyProtocolTransport extends AbstractProtocolTransport {
         if (startTLS) {
             prepareStartTLS();
         }
-        if (!isTLSStarted()) {
-            if (in instanceof FileInputStream) {
-                FileChannel fChannel = ((FileInputStream) in).getChannel();
-                try {
-                    channel.writeAndFlush(new DefaultFileRegion(fChannel, 0, fChannel.size()));
-
-                } catch (IOException e) {
-                    // We handle this later
-                    channel.writeAndFlush(new ChunkedStream(new ExceptionInputStream(e)));
-                }
-                return;
+        if (!isTLSStarted() && in instanceof FileInputStream) {
+            FileChannel fChannel = ((FileInputStream) in).getChannel();
+            try {
+                channel.writeAndFlush(new DefaultFileRegion(fChannel, 0, fChannel.size()));
+
+            } catch (IOException e) {
+                // We handle this later
+                channel.writeAndFlush(new ChunkedStream(new ExceptionInputStream(e)));
             }
+            return;
         }
         channel.writeAndFlush(new ChunkedStream(in));
     }
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/ProtocolMDCContextFactory.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/ProtocolMDCContextFactory.java
index 62ecd22168..d116cd766a 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/ProtocolMDCContextFactory.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/ProtocolMDCContextFactory.java
@@ -81,8 +81,8 @@ public interface ProtocolMDCContextFactory {
 
     static MDCBuilder from(Object o) {
         return Optional.ofNullable(o)
-            .filter(object -> object instanceof ProtocolSession)
-            .map(object -> (ProtocolSession) object)
+            .filter(ProtocolSession.class::isInstance)
+            .map(ProtocolSession.class::cast)
             .map(ProtocolMDCContextFactory::forSession)
             .orElse(MDCBuilder.create());
     }
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/POP3BeforeSMTPHelper.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/POP3BeforeSMTPHelper.java
index 2ed8d237a3..497c3c666b 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/POP3BeforeSMTPHelper.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/POP3BeforeSMTPHelper.java
@@ -32,13 +32,10 @@ import java.util.Map;
  */
 public class POP3BeforeSMTPHelper {
 
-    private POP3BeforeSMTPHelper() {
-    }
-
     /**
      * The map in which the ipAddresses and timestamp stored
      */
-    public static final Map<String, Instant> ipMap = Collections.synchronizedMap(new HashMap<>());
+    public static final Map<String, Instant> IP_MAP = Collections.synchronizedMap(new HashMap<>());
 
     /**
      * Default expire time in ms (60 hour)
@@ -53,7 +50,7 @@ public class POP3BeforeSMTPHelper {
      * @return true if authorized. Else false
      */
     public static boolean isAuthorized(String ipAddress) {
-        return ipMap.containsKey(ipAddress);
+        return IP_MAP.containsKey(ipAddress);
     }
 
     /**
@@ -63,14 +60,7 @@ public class POP3BeforeSMTPHelper {
      *            The ipAddress
      */
     public static void addIPAddress(String ipAddress) {
-        ipMap.put(ipAddress, Instant.now());
-    }
-
-    /**
-     * @see #removeExpiredIP(Duration)
-     */
-    public static void removeExpiredIP() {
-        removeExpiredIP(EXPIRE_TIME);
+        IP_MAP.put(ipAddress, Instant.now());
     }
 
     /**
@@ -82,12 +72,12 @@ public class POP3BeforeSMTPHelper {
      *            handled as expired
      */
     public static void removeExpiredIP(Duration clearTime) {
-        synchronized (ipMap) {
-            Iterator<String> storedIP = ipMap.keySet().iterator();
+        synchronized (IP_MAP) {
+            Iterator<String> storedIP = IP_MAP.keySet().iterator();
 
             while (storedIP.hasNext()) {
                 String key = storedIP.next();
-                Instant storedTime = ipMap.get(key);
+                Instant storedTime = IP_MAP.get(key);
 
                 // remove the ip from the map when it is expired
                 if (Instant.now().minus(clearTime).isAfter(storedTime)) {
@@ -96,16 +86,9 @@ public class POP3BeforeSMTPHelper {
                     // a ConcurrentModificationException
                     storedIP.remove();
 
-                    ipMap.remove(key);
+                    IP_MAP.remove(key);
                 }
             }
         }
     }
-
-    /**
-     * Remove all ipAddresses from the authorized map
-     */
-    public static void clearIP() {
-        ipMap.clear();
-    }
 }
diff --git a/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java b/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java
index 0ab2d81731..b12b7a046e 100644
--- a/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java
+++ b/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/AbstractConfigurableAsyncServerTest.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.protocols.lib;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -36,13 +38,12 @@ import org.apache.james.protocols.api.Encryption;
 import org.apache.james.protocols.lib.mock.ConfigLoader;
 import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
 import org.apache.james.protocols.netty.ChannelHandlerFactory;
-import io.netty.channel.ChannelInboundHandlerAdapter;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-import static org.assertj.core.api.Assertions.assertThat;
+import io.netty.channel.ChannelInboundHandlerAdapter;
 
-public class AbstractConfigurableAsyncServerTest {
+class AbstractConfigurableAsyncServerTest {
 
     private static class MemoryFileSystem implements FileSystem {
 
@@ -139,18 +140,18 @@ public class AbstractConfigurableAsyncServerTest {
     private TestableConfigurableAsyncServer testServer;
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         memoryFileSystem = new MemoryFileSystem();
     }
 
     @Test
-    public void testServerDisabled() throws Exception {
+    void testServerDisabled() throws Exception {
         initTestServer("testServerDisabled.xml");
         assertThat(testServer.isEnabled()).isFalse();
     }
 
     @Test
-    public void testEmpty() throws Exception {
+    void testEmpty() throws Exception {
         initTestServer("testServerDefaults.xml");
         assertThat(testServer.isEnabled()).isTrue();
 
@@ -163,15 +164,15 @@ public class AbstractConfigurableAsyncServerTest {
         assertThat(testServer.getTimeout()).isEqualTo(AbstractConfigurableAsyncServer.DEFAULT_TIMEOUT);
         assertThat(testServer.getBacklog()).isEqualTo(AbstractConfigurableAsyncServer.DEFAULT_BACKLOG);
 
-        assertThat(testServer.getMaximumConcurrentConnections()).isEqualTo(0); // no default limit
-        assertThat(testServer.getConnPerIp()).isEqualTo(0); // no default limit
+        assertThat(testServer.getMaximumConcurrentConnections()).isZero(); // no default limit
+        assertThat(testServer.getConnPerIp()).isZero(); // no default limit
 
         testServer.buildSSLContext();
         assertThat(testServer.getEncryption()).isNull(); // no TLS by default
     }
 
     @Test
-    public void testServerPlain() throws Exception {
+    void testServerPlain() throws Exception {
         initTestServer("testServerPlain.xml");
         assertThat(testServer.isEnabled()).isTrue();
 
@@ -192,7 +193,7 @@ public class AbstractConfigurableAsyncServerTest {
     }
 
     @Test
-    public void testServerTLS() throws Exception {
+    void testServerTLS() throws Exception {
         memoryFileSystem.put("file://conf/keystore", "keystore");
 
         initTestServer("testServerTLS.xml");
@@ -206,7 +207,7 @@ public class AbstractConfigurableAsyncServerTest {
     }
 
     @Test
-    public void testServerStartTLS() throws Exception {
+    void testServerStartTLS() throws Exception {
         memoryFileSystem.put("file://conf/keystore", "keystore");
 
         initTestServer("testServerStartTLS.xml");
@@ -220,7 +221,7 @@ public class AbstractConfigurableAsyncServerTest {
     }
 
     @Test
-    public void testServerTLSNeedClientAuth() throws Exception {
+    void testServerTLSNeedClientAuth() throws Exception {
         memoryFileSystem.put("file://conf/keystore", "keystore");
         memoryFileSystem.put("file://conf/truststore", "keystore");
 
@@ -233,7 +234,7 @@ public class AbstractConfigurableAsyncServerTest {
     }
 
     @Test
-    public void testServerTLSDefaultClientAuth() throws Exception {
+    void testServerTLSDefaultClientAuth() throws Exception {
         memoryFileSystem.put("file://conf/keystore", "keystore");
         // memoryFileSystem.put("file://conf/truststore", "keystore");
 


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


[james-project] 17/19: JAMES-3715 Call GhostMailbox logger only if needed

Posted by bt...@apache.org.
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 befc8ddc78288ebc8b6d1fce3f1ecc5657e15049
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Mar 22 11:30:47 2022 +0700

    JAMES-3715 Call GhostMailbox logger only if needed
    
    Building MDC for this takes 0.37% of CPU even when nothing is logged on the
    sample IMAP benchmarks I run, and account for 2.6% of overall memory allocation,
    even if nothing is ever logged.
    
    Even on JMAP scenario this account for 0.2% of CPU time.
    
    Easy fix... Do the MDC stuff only if needed...
---
 .../org/apache/james/mailbox/cassandra/GhostMailbox.java |  4 ++++
 .../cassandra/mail/CassandraMailboxPathV3DAO.java        | 16 ++++++++++------
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/GhostMailbox.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/GhostMailbox.java
index fbf38caf92..85c4506eb5 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/GhostMailbox.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/GhostMailbox.java
@@ -35,6 +35,10 @@ public class GhostMailbox {
     public static final String TYPE = "type";
     public static final String MAILBOX_ID = "mailboxId";
 
+    public static boolean isDebugEnabled() {
+        return LOGGER.isDebugEnabled();
+    }
+
     public static MDCStructuredLogger logger() {
         return MDCStructuredLogger.forLogger(LOGGER);
     }
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxPathV3DAO.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxPathV3DAO.java
index d8435d62fc..f0c3d6e9d2 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxPathV3DAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxPathV3DAO.java
@@ -161,10 +161,12 @@ public class CassandraMailboxPathV3DAO {
     }
 
     public void logGhostMailboxFailure(MailboxPath mailboxPath) {
-        GhostMailbox.logger()
+        if (GhostMailbox.isDebugEnabled()) {
+            GhostMailbox.logger()
                 .field(GhostMailbox.MAILBOX_NAME, mailboxPath.asString())
                 .field(TYPE, "readMiss")
                 .log(logger -> logger.debug("Read mailbox missed"));
+        }
     }
 
     /**
@@ -174,11 +176,13 @@ public class CassandraMailboxPathV3DAO {
      * or log history might have been dropped)
      */
     private void logReadSuccess(Mailbox mailbox) {
-        GhostMailbox.logger()
-            .field(GhostMailbox.MAILBOX_NAME, mailbox.generateAssociatedPath().asString())
-            .field(TYPE, "readSuccess")
-            .field(GhostMailbox.MAILBOX_ID, mailbox.getMailboxId().serialize())
-            .log(logger -> logger.debug("Read mailbox succeeded"));
+        if (GhostMailbox.isDebugEnabled()) {
+            GhostMailbox.logger()
+                .field(GhostMailbox.MAILBOX_NAME, mailbox.generateAssociatedPath().asString())
+                .field(TYPE, "readSuccess")
+                .field(GhostMailbox.MAILBOX_ID, mailbox.getMailboxId().serialize())
+                .log(logger -> logger.debug("Read mailbox succeeded"));
+        }
     }
 
     private Mailbox fromRowToCassandraIdAndPath(Row row) {


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


[james-project] 19/19: JAMES-3715 Configure bootstrap before binding it...

Posted by bt...@apache.org.
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 1b3c66c07d30b958be13afed4ee2fbd6769bf9bf
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Mar 22 12:56:49 2022 +0700

    JAMES-3715 Configure bootstrap before binding it...
---
 .../java/org/apache/james/protocols/netty/AbstractAsyncServer.java    | 4 ++--
 1 file changed, 2 insertions(+), 2 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 6767dd20cd..d58ab40319 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
@@ -102,13 +102,13 @@ public abstract class AbstractAsyncServer implements ProtocolServer {
         // Configure the pipeline factory.
         bootstrap.childHandler(factory);
 
+        configureBootstrap(bootstrap);
+
         for (InetSocketAddress address : addresses) {
             Channel channel = bootstrap.bind(address).sync().channel();
             channels.add(channel);
         }
 
-        configureBootstrap(bootstrap);
-
         started = true;
     }
 


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


[james-project] 10/19: JAMES-3715 AllButStartTlsLineChannelHandlerFactory maxFrameLength may be final

Posted by bt...@apache.org.
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 fa2e561b7d5ae913d83c1106aa3e663596db2997
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 3 12:41:36 2022 +0700

    JAMES-3715 AllButStartTlsLineChannelHandlerFactory maxFrameLength may be final
---
 .../james/protocols/netty/AllButStartTlsLineChannelHandlerFactory.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AllButStartTlsLineChannelHandlerFactory.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AllButStartTlsLineChannelHandlerFactory.java
index 884c6bbda3..92b1181942 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/AllButStartTlsLineChannelHandlerFactory.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/AllButStartTlsLineChannelHandlerFactory.java
@@ -23,7 +23,7 @@ import io.netty.channel.ChannelPipeline;
 
 public class AllButStartTlsLineChannelHandlerFactory implements ChannelHandlerFactory {
     private final String pattern;
-    private int maxFrameLength;
+    private final int maxFrameLength;
 
     public AllButStartTlsLineChannelHandlerFactory(String pattern, int maxFrameLength) {
         this.pattern = pattern;


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


[james-project] 16/19: JAMES-3715 ManageSieve: Avoid chuncking byte arrays

Posted by bt...@apache.org.
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 cc10ba2b370c757334e8b62bbdc3b7c6541693bf
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Mar 22 11:05:55 2022 +0700

    JAMES-3715 ManageSieve: Avoid chuncking byte arrays
    
    If it fits in memory it is not worth chucking...
---
 .../managesieveserver/netty/ChannelManageSieveResponseWriter.java  | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ChannelManageSieveResponseWriter.java b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ChannelManageSieveResponseWriter.java
index 4bf4240e8d..31aa2874c0 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ChannelManageSieveResponseWriter.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ChannelManageSieveResponseWriter.java
@@ -19,14 +19,12 @@
 
 package org.apache.james.managesieveserver.netty;
 
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
 import java.nio.charset.StandardCharsets;
 
 import org.apache.james.protocols.api.CommandDetectionSession;
 
+import io.netty.buffer.Unpooled;
 import io.netty.channel.Channel;
-import io.netty.handler.stream.ChunkedStream;
 
 public class ChannelManageSieveResponseWriter implements CommandDetectionSession {
     private final Channel channel;
@@ -39,8 +37,7 @@ public class ChannelManageSieveResponseWriter implements CommandDetectionSession
 
     public void write(String response) {
         if (channel.isActive()) {
-            InputStream in = new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8));
-            channel.writeAndFlush(new ChunkedStream(in));
+            channel.writeAndFlush(Unpooled.wrappedBuffer(response.getBytes(StandardCharsets.UTF_8)));
         }
     }
 


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


[james-project] 08/19: JAMES-3715 Remove unused class JMXEnabledOrderedMemoryAwareThreadPoolExecutorMBean

Posted by bt...@apache.org.
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 50a67b8ef6f776e812c7c950d22b8e2f91b44eab
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 3 12:38:50 2022 +0700

    JAMES-3715 Remove unused class JMXEnabledOrderedMemoryAwareThreadPoolExecutorMBean
---
 ...dOrderedMemoryAwareThreadPoolExecutorMBean.java | 25 ----------------------
 1 file changed, 25 deletions(-)

diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/JMXEnabledOrderedMemoryAwareThreadPoolExecutorMBean.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/JMXEnabledOrderedMemoryAwareThreadPoolExecutorMBean.java
deleted file mode 100644
index 817759c5ec..0000000000
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/JMXEnabledOrderedMemoryAwareThreadPoolExecutorMBean.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/****************************************************************
- * 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.lib.netty;
-
-import org.apache.james.util.concurrent.JMXEnabledThreadPoolExecutorMBean;
-
-public interface JMXEnabledOrderedMemoryAwareThreadPoolExecutorMBean extends JMXEnabledThreadPoolExecutorMBean{
-
-}


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


[james-project] 18/19: JAMES-3715 Fix a checkstyle issue

Posted by bt...@apache.org.
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 d2cfcad61622883b056f41a7b86ac5b2971ddfa3
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Mar 22 11:42:38 2022 +0700

    JAMES-3715 Fix a checkstyle issue
---
 .../java/org/apache/james/managesieveserver/netty/ManageSieveServer.java | 1 -
 1 file changed, 1 deletion(-)

diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
index b412947a69..1254bd2420 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
@@ -38,7 +38,6 @@ import org.apache.james.protocols.netty.AllButStartTlsLineChannelHandlerFactory;
 import org.apache.james.protocols.netty.ChannelHandlerFactory;
 import org.apache.james.protocols.netty.ConnectionLimitUpstreamHandler;
 import org.apache.james.protocols.netty.ConnectionPerIpLimitUpstreamHandler;
-import org.apache.james.protocols.netty.HandlerConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 


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


[james-project] 11/19: JAMES-3715 SwitchableLineBasedFrameDecoderFactory: maxLineLength can be final

Posted by bt...@apache.org.
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 b8e61fc5c560b039a725e0b75342305b42245beb
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 3 14:40:03 2022 +0700

    JAMES-3715 SwitchableLineBasedFrameDecoderFactory: maxLineLength can be final
---
 .../james/imapserver/netty/SwitchableLineBasedFrameDecoderFactory.java | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoderFactory.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoderFactory.java
index f497710890..a3baa1df1c 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoderFactory.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/SwitchableLineBasedFrameDecoderFactory.java
@@ -24,8 +24,7 @@ import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelPipeline;
 
 public class SwitchableLineBasedFrameDecoderFactory implements ChannelHandlerFactory {
-
-    private int maxLineLength;
+    private final int maxLineLength;
 
     public SwitchableLineBasedFrameDecoderFactory(int maxLineLength) {
         this.maxLineLength = maxLineLength;


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


[james-project] 15/19: JAMES-3715 Apply NETTY-311 suggestions

Posted by bt...@apache.org.
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 406b15f5977b1ad532108ce59a15d872893857c9
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 4 22:37:19 2022 +0700

    JAMES-3715 Apply NETTY-311 suggestions
---
 .../netty/AbstractChannelPipelineFactory.java      | 14 +++++++-----
 .../netty/ConnectionLimitUpstreamHandler.java      |  8 +++----
 .../netty/ConnectionPerIpLimitUpstreamHandler.java |  8 +++----
 .../james/protocols/netty/HandlerConstants.java    |  4 ++++
 .../apache/james/imapserver/netty/IMAPServer.java  | 11 ++++++---
 .../managesieveserver/netty/ManageSieveServer.java | 26 +++++++++++++++++-----
 6 files changed, 49 insertions(+), 22 deletions(-)

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 6412d41684..e0d054fe5e 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
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.james.protocols.netty;
 
+import java.util.Optional;
+
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelInboundHandlerAdapter;
 import io.netty.channel.ChannelInitializer;
@@ -34,8 +36,8 @@ public abstract class AbstractChannelPipelineFactory<C extends SocketChannel> ex
     public static final int MAX_LINE_LENGTH = 8192;
 
     private final int timeout;
-    private final int maxConnectsPerIp;
-    private final int connectionLimit;
+    private final Optional<ConnectionLimitUpstreamHandler> connectionLimitUpstreamHandler;
+    private final Optional<ConnectionPerIpLimitUpstreamHandler> connectionPerIpLimitUpstreamHandler;
     private final ChannelHandlerFactory frameHandlerFactory;
     private final EventExecutorGroup eventExecutorGroup;
 
@@ -48,8 +50,8 @@ public abstract class AbstractChannelPipelineFactory<C extends SocketChannel> ex
         this.timeout = timeout;
         this.frameHandlerFactory = frameHandlerFactory;
         this.eventExecutorGroup = eventExecutorGroup;
-        this.maxConnectsPerIp = maxConnectsPerIp;
-        this.connectionLimit = maxConnections;
+        this.connectionLimitUpstreamHandler = ConnectionLimitUpstreamHandler.forCount(maxConnections);
+        this.connectionPerIpLimitUpstreamHandler = ConnectionPerIpLimitUpstreamHandler.forCount(maxConnectsPerIp);
     }
     
     
@@ -58,8 +60,8 @@ public abstract class AbstractChannelPipelineFactory<C extends SocketChannel> ex
         // Create a default pipeline implementation.
         ChannelPipeline pipeline = channel.pipeline();
 
-        ConnectionLimitUpstreamHandler.addToPipeline(pipeline, connectionLimit);
-        ConnectionPerIpLimitUpstreamHandler.addToPipeline(pipeline, maxConnectsPerIp);
+        connectionLimitUpstreamHandler.ifPresent(handler -> pipeline.addLast(HandlerConstants.CONNECTION_LIMIT_HANDLER, handler));
+        connectionPerIpLimitUpstreamHandler.ifPresent(handler -> pipeline.addLast(HandlerConstants.CONNECTION_LIMIT_PER_IP_HANDLER, handler));
 
         // Add the text line decoder which limit the max line length, don't strip the delimiter and use CRLF as delimiter
         pipeline.addLast(eventExecutorGroup, HandlerConstants.FRAMER, frameHandlerFactory.create(pipeline));
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 72595e3862..6ab9869b57 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
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.protocols.netty;
 
+import java.util.Optional;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import com.google.common.base.Preconditions;
@@ -35,12 +36,11 @@ import io.netty.channel.ChannelPipeline;
  */
 @ChannelHandler.Sharable
 public class ConnectionLimitUpstreamHandler extends ChannelInboundHandlerAdapter {
-    private static final String CONNECTION_LIMIT_HANDLER = "connectionLimitHandler";
-
-    public static void addToPipeline(ChannelPipeline pipeline, int connPerIP) {
+    public static Optional<ConnectionLimitUpstreamHandler> forCount(int connPerIP) {
         if (connPerIP > 0) {
-            pipeline.addLast(CONNECTION_LIMIT_HANDLER, new ConnectionLimitUpstreamHandler(connPerIP));
+            return Optional.of(new ConnectionLimitUpstreamHandler(connPerIP));
         }
+        return Optional.empty();
     }
 
     private final AtomicInteger connections = new AtomicInteger(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 2a8e642d04..d2bfa9d29e 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
@@ -19,6 +19,7 @@
 package org.apache.james.protocols.netty;
 
 import java.net.InetSocketAddress;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -38,12 +39,11 @@ import io.netty.channel.ChannelPipeline;
  */
 @ChannelHandler.Sharable
 public class ConnectionPerIpLimitUpstreamHandler extends ChannelInboundHandlerAdapter {
-    private static final String CONNECTION_LIMIT_PER_IP_HANDLER = "connectionPerIpLimitHandler";
-
-    public static void addToPipeline(ChannelPipeline pipeline, int connPerIP) {
+    public static Optional<ConnectionPerIpLimitUpstreamHandler> forCount(int connPerIP) {
         if (connPerIP > 0) {
-            pipeline.addLast(CONNECTION_LIMIT_PER_IP_HANDLER, new ConnectionPerIpLimitUpstreamHandler(connPerIP));
+            return Optional.of(new ConnectionPerIpLimitUpstreamHandler(connPerIP));
         }
+        return Optional.empty();
     }
 
     private final ConcurrentMap<String, AtomicInteger> connections = new ConcurrentHashMap<>();
diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/HandlerConstants.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/HandlerConstants.java
index 54c58a6b39..5f699578e5 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/HandlerConstants.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/HandlerConstants.java
@@ -37,4 +37,8 @@ public interface HandlerConstants {
 
     String CHUNK_HANDLER = "chunkHandler";
 
+    String CONNECTION_LIMIT_PER_IP_HANDLER = "connectionPerIpLimitHandler";
+
+    String CONNECTION_LIMIT_HANDLER = "connectionLimitHandler";
+
 }
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
index 4a64635b4b..4e3ce1b928 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
@@ -39,6 +39,7 @@ import org.apache.james.protocols.netty.AbstractChannelPipelineFactory;
 import org.apache.james.protocols.netty.ChannelHandlerFactory;
 import org.apache.james.protocols.netty.ConnectionLimitUpstreamHandler;
 import org.apache.james.protocols.netty.ConnectionPerIpLimitUpstreamHandler;
+import org.apache.james.protocols.netty.HandlerConstants;
 import org.apache.james.util.Size;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -134,6 +135,8 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC
     private int timeout;
     private int literalSizeLimit;
     private AuthenticationConfiguration authenticationConfiguration;
+    private Optional<ConnectionLimitUpstreamHandler> connectionLimitUpstreamHandler = Optional.empty();
+    private Optional<ConnectionPerIpLimitUpstreamHandler> connectionPerIpLimitUpstreamHandler = Optional.empty();
 
     public static final int DEFAULT_MAX_LINE_LENGTH = 65536; // Use a big default
     public static final Size DEFAULT_IN_MEMORY_SIZE_LIMIT = Size.of(10L, Size.Unit.M); // Use 10MB as default
@@ -170,6 +173,8 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC
             throw new ConfigurationException("Minimum timeout of 30 minutes required. See rfc2060 5.4 for details");
         }
         authenticationConfiguration = AuthenticationConfiguration.parse(configuration);
+        connectionLimitUpstreamHandler = ConnectionLimitUpstreamHandler.forCount(connectionLimit);
+        connectionPerIpLimitUpstreamHandler = ConnectionPerIpLimitUpstreamHandler.forCount(connPerIP);
 
         processor.configure(getImapConfiguration(configuration));
     }
@@ -216,12 +221,12 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC
             }
 
             @Override
-            public void initChannel(Channel channel) throws Exception {
+            public void initChannel(Channel channel) {
                 ChannelPipeline pipeline = channel.pipeline();
                 pipeline.addLast(TIMEOUT_HANDLER, new ImapIdleStateHandler(timeout));
 
-                ConnectionLimitUpstreamHandler.addToPipeline(pipeline, connectionLimit);
-                ConnectionPerIpLimitUpstreamHandler.addToPipeline(pipeline, connPerIP);
+                connectionLimitUpstreamHandler.ifPresent(handler -> pipeline.addLast(HandlerConstants.CONNECTION_LIMIT_HANDLER, handler));
+                connectionPerIpLimitUpstreamHandler.ifPresent(handler -> pipeline.addLast(HandlerConstants.CONNECTION_LIMIT_PER_IP_HANDLER, handler));
 
                 // Add the text line decoder which limit the max line length,
                 // don't strip the delimiter and use CRLF as delimiter
diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
index e1753601c4..b412947a69 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
@@ -20,8 +20,16 @@
 package org.apache.james.managesieveserver.netty;
 
 
+import static org.apache.james.protocols.netty.HandlerConstants.CONNECTION_LIMIT_HANDLER;
+import static org.apache.james.protocols.netty.HandlerConstants.CONNECTION_LIMIT_PER_IP_HANDLER;
+
+import java.util.Optional;
+
 import javax.net.ssl.SSLEngine;
 
+import org.apache.commons.configuration2.HierarchicalConfiguration;
+import org.apache.commons.configuration2.ex.ConfigurationException;
+import org.apache.commons.configuration2.tree.ImmutableNode;
 import org.apache.james.managesieve.transcode.ManageSieveProcessor;
 import org.apache.james.protocols.api.Encryption;
 import org.apache.james.protocols.lib.netty.AbstractConfigurableAsyncServer;
@@ -30,6 +38,7 @@ import org.apache.james.protocols.netty.AllButStartTlsLineChannelHandlerFactory;
 import org.apache.james.protocols.netty.ChannelHandlerFactory;
 import org.apache.james.protocols.netty.ConnectionLimitUpstreamHandler;
 import org.apache.james.protocols.netty.ConnectionPerIpLimitUpstreamHandler;
+import org.apache.james.protocols.netty.HandlerConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -49,13 +58,12 @@ public class ManageSieveServer extends AbstractConfigurableAsyncServer implement
     static final String SSL_HANDLER = "sslHandler";
     static final String FRAMER = "framer";
     static final String CORE_HANDLER = "coreHandler";
-    static final String CONNECTION_LIMIT_HANDLER = "connectionLimitHandler";
-    static final String CONNECTION_LIMIT_PER_IP_HANDLER = "connectionPerIpLimitHandler";
-    static final String CONNECTION_COUNT_HANDLER = "connectionCountHandler";
     static final String CHUNK_WRITE_HANDLER = "chunkWriteHandler";
 
     private final int maxLineLength;
     private final ManageSieveProcessor manageSieveProcessor;
+    private Optional<ConnectionLimitUpstreamHandler> connectionLimitUpstreamHandler = Optional.empty();
+    private Optional<ConnectionPerIpLimitUpstreamHandler> connectionPerIpLimitUpstreamHandler = Optional.empty();
 
     public ManageSieveServer(int maxLineLength, ManageSieveProcessor manageSieveProcessor) {
         this.maxLineLength = maxLineLength;
@@ -67,6 +75,14 @@ public class ManageSieveServer extends AbstractConfigurableAsyncServer implement
         return 4190;
     }
 
+    @Override
+    protected void doConfigure(HierarchicalConfiguration<ImmutableNode> config) throws ConfigurationException {
+        super.doConfigure(config);
+
+        connectionLimitUpstreamHandler = ConnectionLimitUpstreamHandler.forCount(connectionLimit);
+        connectionPerIpLimitUpstreamHandler = ConnectionPerIpLimitUpstreamHandler.forCount(connPerIP);
+    }
+
     @Override
     protected String getDefaultJMXName() {
         return "managesieveserver";
@@ -100,8 +116,8 @@ public class ManageSieveServer extends AbstractConfigurableAsyncServer implement
 
                 }
 
-                ConnectionLimitUpstreamHandler.addToPipeline(pipeline, connectionLimit);
-                ConnectionPerIpLimitUpstreamHandler.addToPipeline(pipeline, connPerIP);
+                connectionLimitUpstreamHandler.ifPresent(handler -> pipeline.addLast(CONNECTION_LIMIT_HANDLER, handler));
+                connectionPerIpLimitUpstreamHandler.ifPresent(handler -> pipeline.addLast(CONNECTION_LIMIT_PER_IP_HANDLER, handler));
 
                 // Add the text line decoder which limit the max line length,
                 // don't strip the delimiter and use CRLF as delimiter


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


[james-project] 07/19: JAMES-3715 Fix various Sonar warnings in protocol-library

Posted by bt...@apache.org.
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 269d2260f4cbaab4c6352f43cc6cd97479d0567e
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 3 12:19:01 2022 +0700

    JAMES-3715 Fix various Sonar warnings in protocol-library
---
 .../apache/james/protocols/lib/ProtocolHandlerChainImpl.java |  2 +-
 .../apache/james/protocols/lib/jmx/ConnectHandlerStats.java  |  2 +-
 .../org/apache/james/protocols/lib/jmx/LineHandlerStats.java |  2 +-
 .../protocols/lib/netty/AbstractConfigurableAsyncServer.java | 12 +++++-------
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java
index e1a071208c..944dc6c742 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java
@@ -106,7 +106,7 @@ public class ProtocolHandlerChainImpl implements ProtocolHandlerChain {
     }
 
 
-    private void registerHandlersPackage(HandlersPackage handlersPackage, HierarchicalConfiguration<ImmutableNode> handlerConfig, List<HierarchicalConfiguration<ImmutableNode>> children) throws ConfigurationException {
+    private void registerHandlersPackage(HandlersPackage handlersPackage, HierarchicalConfiguration<ImmutableNode> handlerConfig, List<HierarchicalConfiguration<ImmutableNode>> children) {
         List<String> c = handlersPackage.getHandlers();
 
         for (String cName : c) {
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/ConnectHandlerStats.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/ConnectHandlerStats.java
index 2e8686411e..3d7032b15a 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/ConnectHandlerStats.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/ConnectHandlerStats.java
@@ -81,7 +81,7 @@ public class ConnectHandlerStats extends StandardMBean implements HandlerStatsMB
         try {
             mbeanserver.unregisterMBean(new ObjectName(name));
         } catch (Exception e) {
-            // ignore here;
+            // ignore here
         }
     }
 
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/LineHandlerStats.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/LineHandlerStats.java
index dd08360207..11339cff8f 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/LineHandlerStats.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/LineHandlerStats.java
@@ -83,7 +83,7 @@ public class LineHandlerStats extends StandardMBean implements HandlerStatsMBean
         try {
             mbeanserver.unregisterMBean(new ObjectName(name));
         } catch (Exception e) {
-            // ignore here;
+            // ignore here
         }
     }
 
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
index 410699e9f2..e9342d1ea3 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
@@ -419,13 +419,11 @@ public abstract class AbstractConfigurableAsyncServer extends AbstractAsyncServe
                 sslFactoryBuilder.withIdentityMaterial(keyManager);
             }
 
-            if (clientAuth != null) {
-                if (truststore != null) {
-                    sslFactoryBuilder.withTrustMaterial(
-                        fileSystem.getFile(truststore).toPath(),
-                        truststoreSecret,
-                        truststoreType);
-                }
+            if (clientAuth != null && truststore != null) {
+                sslFactoryBuilder.withTrustMaterial(
+                    fileSystem.getFile(truststore).toPath(),
+                    truststoreSecret,
+                    truststoreType);
             }
 
             SSLContext context = sslFactoryBuilder.build().getSslContext();


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


[james-project] 06/19: JAMES-3715 AbstractConfigurableAsyncServer: Remove unused file input stream

Posted by bt...@apache.org.
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 6a9fd712e03aa806bcd6a5be2c02faa0fd8f59cd
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 3 12:17:25 2022 +0700

    JAMES-3715 AbstractConfigurableAsyncServer: Remove unused file input stream
    
    Was always null...
---
 .../lib/netty/AbstractConfigurableAsyncServer.java | 70 ++++++++++------------
 1 file changed, 31 insertions(+), 39 deletions(-)

diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
index 9ef0e4cc68..410699e9f2 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.james.protocols.lib.netty;
 
-import java.io.FileInputStream;
 import java.lang.management.ManagementFactory;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
@@ -398,50 +397,43 @@ public abstract class AbstractConfigurableAsyncServer extends AbstractAsyncServe
      */
     protected void buildSSLContext() throws Exception {
         if (useStartTLS || useSSL) {
-            FileInputStream fis = null;
             SSLFactory.Builder sslFactoryBuilder = SSLFactory.builder()
                 .withSslContextAlgorithm("TLS");
-            try {
-                if (keystore != null) {
-                    char[] passwordAsCharArray = Optional.ofNullable(secret)
-                        .orElse("")
-                        .toCharArray();
-                    sslFactoryBuilder.withIdentityMaterial(
-                        fileSystem.getFile(keystore).toPath(),
-                        passwordAsCharArray,
-                        passwordAsCharArray,
-                        keystoreType);
-                } else {
-                    X509ExtendedKeyManager keyManager = PemUtils.loadIdentityMaterial(
-                        fileSystem.getResource(certificates),
-                        fileSystem.getResource(privateKey),
-                        Optional.ofNullable(secret)
-                            .map(String::toCharArray)
-                            .orElse(null));
-
-                    sslFactoryBuilder.withIdentityMaterial(keyManager);
-                }
+            if (keystore != null) {
+                char[] passwordAsCharArray = Optional.ofNullable(secret)
+                    .orElse("")
+                    .toCharArray();
+                sslFactoryBuilder.withIdentityMaterial(
+                    fileSystem.getFile(keystore).toPath(),
+                    passwordAsCharArray,
+                    passwordAsCharArray,
+                    keystoreType);
+            } else {
+                X509ExtendedKeyManager keyManager = PemUtils.loadIdentityMaterial(
+                    fileSystem.getResource(certificates),
+                    fileSystem.getResource(privateKey),
+                    Optional.ofNullable(secret)
+                        .map(String::toCharArray)
+                        .orElse(null));
+
+                sslFactoryBuilder.withIdentityMaterial(keyManager);
+            }
 
-                if (clientAuth != null) {
-                    if (truststore != null) {
-                        sslFactoryBuilder.withTrustMaterial(
-                            fileSystem.getFile(truststore).toPath(),
-                            truststoreSecret,
-                            truststoreType);
-                    }
+            if (clientAuth != null) {
+                if (truststore != null) {
+                    sslFactoryBuilder.withTrustMaterial(
+                        fileSystem.getFile(truststore).toPath(),
+                        truststoreSecret,
+                        truststoreType);
                 }
+            }
 
-                SSLContext context = sslFactoryBuilder.build().getSslContext();
+            SSLContext context = sslFactoryBuilder.build().getSslContext();
 
-                if (useStartTLS) {
-                    encryption = Encryption.createStartTls(context, enabledCipherSuites, clientAuth);
-                } else {
-                    encryption = Encryption.createTls(context, enabledCipherSuites, clientAuth);
-                }
-            } finally {
-                if (fis != null) {
-                    fis.close();
-                }
+            if (useStartTLS) {
+                encryption = Encryption.createStartTls(context, enabledCipherSuites, clientAuth);
+            } else {
+                encryption = Encryption.createTls(context, enabledCipherSuites, clientAuth);
             }
         }
     }


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


[james-project] 01/19: JAMES-3715 ManageSieveServer: apply maxLineLength

Posted by bt...@apache.org.
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 9244a3202717d956925f2bca93176a07eeefa4f3
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 3 11:41:09 2022 +0700

    JAMES-3715 ManageSieveServer: apply maxLineLength
---
 .../netty/ManageSieveChannelUpstreamHandler.java       | 18 ++++++++++++------
 .../managesieveserver/netty/ManageSieveServer.java     |  4 +---
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
index 463dc60a1c..28c3acb1c3 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveChannelUpstreamHandler.java
@@ -29,6 +29,7 @@ import org.apache.james.managesieve.transcode.NotEnoughDataException;
 import org.apache.james.managesieve.util.SettableSession;
 import org.apache.james.protocols.api.Encryption;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import io.netty.buffer.Unpooled;
 import io.netty.channel.Channel;
@@ -41,17 +42,19 @@ import io.netty.handler.ssl.SslHandler;
 
 @ChannelHandler.Sharable
 public class ManageSieveChannelUpstreamHandler extends ChannelInboundHandlerAdapter {
+    private static final Logger LOGGER = LoggerFactory.getLogger(ManageSieveChannelUpstreamHandler.class);
 
     static final String SSL_HANDLER = "sslHandler";
 
-    private final Logger logger;
     private final ManageSieveProcessor manageSieveProcessor;
     private final Encryption secure;
+    private final int maxLineLength;
 
-    public ManageSieveChannelUpstreamHandler(ManageSieveProcessor manageSieveProcessor, Encryption secure, Logger logger) {
-        this.logger = logger;
+    public ManageSieveChannelUpstreamHandler(
+        ManageSieveProcessor manageSieveProcessor, Encryption secure, int maxLineLength) {
         this.manageSieveProcessor = manageSieveProcessor;
         this.secure = secure;
+        this.maxLineLength = maxLineLength;
     }
 
     private boolean isSSL() {
@@ -66,6 +69,9 @@ public class ManageSieveChannelUpstreamHandler extends ChannelInboundHandlerAdap
             if (request.isEmpty() || request.startsWith("\r\n")) {
                 return;
             }
+            if (request.length() > maxLineLength) {
+                throw new TooLongFrameException();
+            }
 
             Session manageSieveSession = ctx.channel().attr(NettyConstants.SESSION_ATTRIBUTE_KEY).get();
             String responseString = manageSieveProcessor.handleRequest(manageSieveSession, request);
@@ -85,7 +91,7 @@ public class ManageSieveChannelUpstreamHandler extends ChannelInboundHandlerAdap
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
         try (Closeable closeable = ManageSieveMDCContext.from(ctx)) {
-            logger.warn("Error while processing ManageSieve request", cause);
+            LOGGER.warn("Error while processing ManageSieve request", cause);
 
             if (cause instanceof TooLongFrameException) {
                 // Max line length exceeded
@@ -112,7 +118,7 @@ public class ManageSieveChannelUpstreamHandler extends ChannelInboundHandlerAdap
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
         try (Closeable closeable = ManageSieveMDCContext.from(ctx)) {
             InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress();
-            logger.info("Connection established from {}", address.getAddress().getHostAddress());
+            LOGGER.info("Connection established from {}", address.getAddress().getHostAddress());
 
             Session session = new SettableSession();
             if (isSSL()) {
@@ -129,7 +135,7 @@ public class ManageSieveChannelUpstreamHandler extends ChannelInboundHandlerAdap
     public void channelInactive(ChannelHandlerContext ctx) throws Exception {
         try (Closeable closeable = ManageSieveMDCContext.from(ctx)) {
             InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress();
-            logger.info("Connection closed for {}", address.getAddress().getHostAddress());
+            LOGGER.info("Connection closed for {}", address.getAddress().getHostAddress());
             ctx.channel().attr(NettyConstants.SESSION_ATTRIBUTE_KEY).getAndSet(null);
             super.channelInactive(ctx);
         }
diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
index 75d6b32423..70891286cb 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
@@ -74,9 +74,7 @@ public class ManageSieveServer extends AbstractConfigurableAsyncServer implement
 
     @Override
     protected ChannelInboundHandlerAdapter createCoreHandler() {
-        return new ManageSieveChannelUpstreamHandler(manageSieveProcessor,
-            getEncryption(),
-            LOGGER);
+        return new ManageSieveChannelUpstreamHandler(manageSieveProcessor, getEncryption(), maxLineLength);
     }
 
     @Override


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


[james-project] 13/19: JAMES-3715 NettyImapRequestLineReader: Avoid allocating an int for each IMAP char

Posted by bt...@apache.org.
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 9e780efd442870b51158f1a3d6682a8478ca292e
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Fri Mar 4 10:34:16 2022 +0700

    JAMES-3715 NettyImapRequestLineReader: Avoid allocating an int for each IMAP char
---
 .../james/imapserver/netty/NettyImapRequestLineReader.java       | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java
index ea66a6fec2..e7a2d246db 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyImapRequestLineReader.java
@@ -62,18 +62,15 @@ public class NettyImapRequestLineReader extends AbstractNettyImapRequestLineRead
      * char
      */
     @Override
-    public char nextChar() throws DecodingException {
+    public char nextChar() {
         if (!nextSeen) {
-            int next;
-
             if (buffer.isReadable()) {
-                next = buffer.readByte();
+                nextChar = (char) buffer.readByte();
                 read++;
+                nextSeen = true;
             } else {
                 throw new NotEnoughDataException();
             }
-            nextSeen = true;
-            nextChar = (char) next;
         }
         return nextChar;
     }


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


[james-project] 02/19: JAMES-3715 Apply NETTY-311 suggestions

Posted by bt...@apache.org.
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 3eccd03c4c91ed0617399304244fb216c7b2324d
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 3 12:00:39 2022 +0700

    JAMES-3715 Apply NETTY-311 suggestions
    
    CF https://issues.redhat.com/browse/NETTY-311
    
    Don't add these items to the pipeline if they are not used...
    
    Also a volatile variable was immutable and could be final.
    
    Remove NETTY-311 todos: that contribution aborted...
---
 .../james/protocols/netty/AbstractAsyncServer.java |  2 +-
 .../netty/AbstractChannelPipelineFactory.java      | 14 +++----
 .../netty/ConnectionLimitUpstreamHandler.java      | 26 +++++++-----
 .../netty/ConnectionPerIpLimitUpstreamHandler.java | 46 ++++++++++++----------
 .../apache/james/imapserver/netty/IMAPServer.java  |  4 +-
 .../managesieveserver/netty/ManageSieveServer.java |  6 ++-
 6 files changed, 55 insertions(+), 43 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 78e05e2c18..6767dd20cd 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
@@ -124,7 +124,7 @@ public abstract class AbstractAsyncServer implements ProtocolServer {
     
     @Override
     public synchronized void unbind() {
-        if (started == false) {
+        if (!started) {
             return;
         }
 
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 601f91adaa..6412d41684 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
@@ -33,9 +33,9 @@ import io.netty.util.concurrent.EventExecutorGroup;
 public abstract class AbstractChannelPipelineFactory<C extends SocketChannel> extends ChannelInitializer<C> {
     public static final int MAX_LINE_LENGTH = 8192;
 
-    protected final ConnectionLimitUpstreamHandler connectionLimitHandler;
-    protected final ConnectionPerIpLimitUpstreamHandler connectionPerIpLimitHandler;
     private final int timeout;
+    private final int maxConnectsPerIp;
+    private final int connectionLimit;
     private final ChannelHandlerFactory frameHandlerFactory;
     private final EventExecutorGroup eventExecutorGroup;
 
@@ -45,11 +45,11 @@ public abstract class AbstractChannelPipelineFactory<C extends SocketChannel> ex
 
     public AbstractChannelPipelineFactory(int timeout, int maxConnections, int maxConnectsPerIp,
                                           ChannelHandlerFactory frameHandlerFactory, EventExecutorGroup eventExecutorGroup) {
-        this.connectionLimitHandler = new ConnectionLimitUpstreamHandler(maxConnections);
-        this.connectionPerIpLimitHandler = new ConnectionPerIpLimitUpstreamHandler(maxConnectsPerIp);
         this.timeout = timeout;
         this.frameHandlerFactory = frameHandlerFactory;
         this.eventExecutorGroup = eventExecutorGroup;
+        this.maxConnectsPerIp = maxConnectsPerIp;
+        this.connectionLimit = maxConnections;
     }
     
     
@@ -58,11 +58,9 @@ public abstract class AbstractChannelPipelineFactory<C extends SocketChannel> ex
         // Create a default pipeline implementation.
         ChannelPipeline pipeline = channel.pipeline();
 
-        pipeline.addLast(HandlerConstants.CONNECTION_LIMIT_HANDLER, connectionLimitHandler);
+        ConnectionLimitUpstreamHandler.addToPipeline(pipeline, connectionLimit);
+        ConnectionPerIpLimitUpstreamHandler.addToPipeline(pipeline, maxConnectsPerIp);
 
-        pipeline.addLast(HandlerConstants.CONNECTION_PER_IP_LIMIT_HANDLER, connectionPerIpLimitHandler);
-
-        
         // Add the text line decoder which limit the max line length, don't strip the delimiter and use CRLF as delimiter
         pipeline.addLast(eventExecutorGroup, HandlerConstants.FRAMER, frameHandlerFactory.create(pipeline));
        
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 cd001ba8c8..72595e3862 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
@@ -20,6 +20,8 @@ package org.apache.james.protocols.netty;
 
 import java.util.concurrent.atomic.AtomicInteger;
 
+import com.google.common.base.Preconditions;
+
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;
@@ -30,27 +32,31 @@ import io.netty.channel.ChannelPipeline;
  * 
  * This handler must be used as singleton when adding it to the {@link ChannelPipeline} to work correctly
  *
- * TODO: Remove when its committed to NETTY. 
- *       https://jira.jboss.org/jira/browse/NETTY-311
  */
 @ChannelHandler.Sharable
 public class ConnectionLimitUpstreamHandler extends ChannelInboundHandlerAdapter {
+    private static final String CONNECTION_LIMIT_HANDLER = "connectionLimitHandler";
+
+    public static void addToPipeline(ChannelPipeline pipeline, int connPerIP) {
+        if (connPerIP > 0) {
+            pipeline.addLast(CONNECTION_LIMIT_HANDLER, new ConnectionLimitUpstreamHandler(connPerIP));
+        }
+    }
 
     private final AtomicInteger connections = new AtomicInteger(0);
-    private volatile int maxConnections = -1;
+    private final int maxConnections;
     
-    public ConnectionLimitUpstreamHandler(int maxConnections) {
+    private ConnectionLimitUpstreamHandler(int maxConnections) {
+        Preconditions.checkArgument(maxConnections > 0);
         this.maxConnections = maxConnections;
     }
 
     @Override
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        if (maxConnections > 0) {
-            int currentCount = connections.incrementAndGet();
-            
-            if (currentCount > maxConnections) {
-                ctx.close();
-            }
+        int currentCount = connections.incrementAndGet();
+
+        if (currentCount > maxConnections) {
+            ctx.close();
         }
         
         super.channelActive(ctx);
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 9e26105d1f..848b24aa14 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
@@ -23,6 +23,8 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import com.google.common.base.Preconditions;
+
 import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelInboundHandlerAdapter;
@@ -33,39 +35,43 @@ import io.netty.channel.ChannelPipeline;
  * 
  * This handler must be used as singleton when adding it to the {@link ChannelPipeline} to work correctly
  *
- * TODO: Remove when its committed to NETTY. 
- *       https://jira.jboss.org/jira/browse/NETTY-311
  */
 @ChannelHandler.Sharable
 public class ConnectionPerIpLimitUpstreamHandler extends ChannelInboundHandlerAdapter {
+    private static final String CONNECTION_LIMIT_PER_IP_HANDLER = "connectionPerIpLimitHandler";
+
+    public static void addToPipeline(ChannelPipeline pipeline, int connPerIP) {
+        if (connPerIP > 0) {
+            pipeline.addLast(CONNECTION_LIMIT_PER_IP_HANDLER, new ConnectionPerIpLimitUpstreamHandler(connPerIP));
+        }
+    }
 
     private final ConcurrentMap<String, AtomicInteger> connections = new ConcurrentHashMap<>();
     private final int maxConnectionsPerIp;
     
-    public ConnectionPerIpLimitUpstreamHandler(int maxConnectionsPerIp) {
+    private ConnectionPerIpLimitUpstreamHandler(int maxConnectionsPerIp) {
+        Preconditions.checkArgument(maxConnectionsPerIp > 0);
         this.maxConnectionsPerIp = maxConnectionsPerIp;
     }
 
     @Override
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        if (maxConnectionsPerIp > 0) {
-            InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
-            String remoteIp = remoteAddress.getAddress().getHostAddress();
-            
-            AtomicInteger atomicCount = connections.get(remoteIp);
+        InetSocketAddress remoteAddress = (InetSocketAddress) ctx.channel().remoteAddress();
+        String remoteIp = remoteAddress.getAddress().getHostAddress();
 
-            if (atomicCount == null) {
-                atomicCount = new AtomicInteger(1);
-                AtomicInteger oldAtomicCount = connections.putIfAbsent(remoteIp, atomicCount);
-                // if another thread put a new counter for this ip, we must use the other one.
-                if (oldAtomicCount != null) {
-                    atomicCount = oldAtomicCount;
-                }
-            } else {
-                Integer count = atomicCount.incrementAndGet();
-                if (count > maxConnectionsPerIp) {
-                    ctx.channel().close();
-                }
+        AtomicInteger atomicCount = connections.get(remoteIp);
+
+        if (atomicCount == null) {
+            atomicCount = new AtomicInteger(1);
+            AtomicInteger oldAtomicCount = connections.putIfAbsent(remoteIp, atomicCount);
+            // if another thread put a new counter for this ip, we must use the other one.
+            if (oldAtomicCount != null) {
+                atomicCount = oldAtomicCount;
+            }
+        } else {
+            Integer count = atomicCount.incrementAndGet();
+            if (count > maxConnectionsPerIp) {
+                ctx.channel().close();
             }
         }
         
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
index f39c8268d4..29961a3dee 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
@@ -219,9 +219,9 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC
             public void initChannel(Channel channel) throws Exception {
                 ChannelPipeline pipeline = channel.pipeline();
                 pipeline.addLast(TIMEOUT_HANDLER, new ImapIdleStateHandler(timeout));
-                pipeline.addLast(CONNECTION_LIMIT_HANDLER, new ConnectionLimitUpstreamHandler(IMAPServer.this.connectionLimit));
 
-                pipeline.addLast(CONNECTION_LIMIT_PER_IP_HANDLER, new ConnectionPerIpLimitUpstreamHandler(IMAPServer.this.connPerIP));
+                ConnectionLimitUpstreamHandler.addToPipeline(pipeline, connectionLimit);
+                ConnectionPerIpLimitUpstreamHandler.addToPipeline(pipeline, connPerIP);
 
                 // Add the text line decoder which limit the max line length,
                 // don't strip the delimiter and use CRLF as delimiter
diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
index 70891286cb..6af2449b83 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
@@ -99,8 +99,10 @@ public class ManageSieveServer extends AbstractConfigurableAsyncServer implement
                     pipeline.addFirst(SSL_HANDLER, new SslHandler(engine));
 
                 }
-                pipeline.addLast(CONNECTION_LIMIT_HANDLER, new ConnectionLimitUpstreamHandler(ManageSieveServer.this.connectionLimit));
-                pipeline.addLast(CONNECTION_LIMIT_PER_IP_HANDLER, new ConnectionPerIpLimitUpstreamHandler(ManageSieveServer.this.connPerIP));
+
+                ConnectionLimitUpstreamHandler.addToPipeline(pipeline, connectionLimit);
+                ConnectionPerIpLimitUpstreamHandler.addToPipeline(pipeline, connPerIP);
+
                 // Add the text line decoder which limit the max line length,
                 // don't strip the delimiter and use CRLF as delimiter
                 // Use a SwitchableDelimiterBasedFrameDecoder, see JAMES-1436


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


[james-project] 12/19: JAMES-3715 HandlerConstants: remove unused constants

Posted by bt...@apache.org.
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 ed2f6ade13a4c424e4041ab88655dd326fcf3bee
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Tue Mar 22 10:57:10 2022 +0700

    JAMES-3715 HandlerConstants: remove unused constants
---
 .../java/org/apache/james/protocols/netty/HandlerConstants.java     | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/protocols/netty/src/main/java/org/apache/james/protocols/netty/HandlerConstants.java b/protocols/netty/src/main/java/org/apache/james/protocols/netty/HandlerConstants.java
index 3464ba1dc8..54c58a6b39 100644
--- a/protocols/netty/src/main/java/org/apache/james/protocols/netty/HandlerConstants.java
+++ b/protocols/netty/src/main/java/org/apache/james/protocols/netty/HandlerConstants.java
@@ -29,12 +29,6 @@ public interface HandlerConstants {
 
     String SSL_HANDLER = "sslHandler";
 
-    String GROUP_HANDLER = "groupHandler";
-
-    String CONNECTION_LIMIT_HANDLER = " connectionLimit";
-
-    String CONNECTION_PER_IP_LIMIT_HANDLER = "connectionPerIpLimit";
-
     String FRAMER = "framer";
 
     String TIMEOUT_HANDLER = "timeoutHandler";


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


[james-project] 03/19: JAMES-3715 ConnectionCountHandler state was unused by production code

Posted by bt...@apache.org.
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 a17d3ca3885dd2e90afddce9ee9bfda722f80334
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 3 12:07:38 2022 +0700

    JAMES-3715 ConnectionCountHandler state was unused by production code
---
 .../apache/james/imapserver/netty/IMAPServer.java  |  1 -
 .../james/imapserver/netty/NettyConstants.java     |  3 -
 .../james/protocols/lib/jmx/ServerMBean.java       | 10 ----
 .../lib/netty/AbstractConfigurableAsyncServer.java | 25 +-------
 ...bstractExecutorAwareChannelPipelineFactory.java | 49 ----------------
 .../lib/netty/ConnectionCountHandler.java          | 68 ----------------------
 .../managesieveserver/netty/ManageSieveServer.java |  1 -
 .../apache/james/smtpserver/SMTPServerTest.java    | 11 +---
 8 files changed, 3 insertions(+), 165 deletions(-)

diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
index 29961a3dee..4a64635b4b 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/IMAPServer.java
@@ -237,7 +237,6 @@ public class IMAPServer extends AbstractConfigurableAsyncServer implements ImapC
                     pipeline.addFirst(SSL_HANDLER, new SslHandler(engine));
 
                 }
-                pipeline.addLast(CONNECTION_COUNT_HANDLER, getConnectionCountHandler());
 
                 pipeline.addLast(CHUNK_WRITE_HANDLER, new ChunkedWriteHandler());
 
diff --git a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyConstants.java b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyConstants.java
index afe1c26e70..36d7d3dafc 100644
--- a/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyConstants.java
+++ b/server/protocols/protocols-imap4/src/main/java/org/apache/james/imapserver/netty/NettyConstants.java
@@ -36,9 +36,6 @@ public interface NettyConstants {
     String FRAMER = "framer";
     String TIMEOUT_HANDLER = "timeoutHandler";
     String CORE_HANDLER = "coreHandler";
-    String CONNECTION_LIMIT_HANDLER = "connectionLimitHandler";
-    String CONNECTION_LIMIT_PER_IP_HANDLER = "connectionPerIpLimitHandler";
-    String CONNECTION_COUNT_HANDLER = "connectionCountHandler";
     String CHUNK_WRITE_HANDLER = "chunkWriteHandler";
     String HEARTBEAT_HANDLER = "heartbeatHandler";
 
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/ServerMBean.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/ServerMBean.java
index 0a0aea228b..f75c76bc82 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/ServerMBean.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/ServerMBean.java
@@ -28,16 +28,6 @@ public interface ServerMBean {
      */
     int getMaximumConcurrentConnections();
 
-    /**
-     * Return the current connection count
-     */
-    int getCurrentConnections();
-
-    /**
-     * Return the count of handled connections till startup
-     */
-    long getHandledConnections();
-
     /**
      * Return true if the server is enabled
      */
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
index 1d4bc96d39..9ef0e4cc68 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractConfigurableAsyncServer.java
@@ -47,6 +47,7 @@ import org.apache.james.protocols.api.Encryption;
 import org.apache.james.protocols.lib.jmx.ServerMBean;
 import org.apache.james.protocols.netty.AbstractAsyncServer;
 import org.apache.james.protocols.netty.AbstractChannelPipelineFactory;
+import org.apache.james.protocols.netty.AbstractSSLAwareChannelPipelineFactory;
 import org.apache.james.protocols.netty.ChannelHandlerFactory;
 import org.apache.james.util.concurrent.NamedThreadFactory;
 import org.slf4j.Logger;
@@ -115,8 +116,6 @@ public abstract class AbstractConfigurableAsyncServer extends AbstractAsyncServe
 
     private String[] enabledCipherSuites;
 
-    private final ConnectionCountHandler countHandler = new ConnectionCountHandler();
-
     private ChannelHandlerFactory frameHandlerFactory;
 
     private EventExecutorGroup executorGroup;
@@ -510,20 +509,6 @@ public abstract class AbstractConfigurableAsyncServer extends AbstractAsyncServe
         return true;
     }
 
-    @Override
-    public long getHandledConnections() {
-        return countHandler.getConnectionsTillStartup();
-    }
-
-    @Override
-    public int getCurrentConnections() {
-        return countHandler.getCurrentConnectionCount();
-    }
-
-    protected ConnectionCountHandler getConnectionCountHandler() {
-        return countHandler;
-    }
-
     @Override
     public String[] getBoundAddresses() {
 
@@ -555,7 +540,7 @@ public abstract class AbstractConfigurableAsyncServer extends AbstractAsyncServe
     
     @Override
     protected AbstractChannelPipelineFactory createPipelineFactory() {
-        return new AbstractExecutorAwareChannelPipelineFactory(getTimeout(), connectionLimit, connPerIP,
+        return new AbstractSSLAwareChannelPipelineFactory(getTimeout(), connectionLimit, connPerIP,
             getEncryption(), getFrameHandlerFactory(), getExecutorGroup()) {
 
             @Override
@@ -563,12 +548,6 @@ public abstract class AbstractConfigurableAsyncServer extends AbstractAsyncServe
                 return AbstractConfigurableAsyncServer.this.createCoreHandler();
 
             }
-
-            @Override
-            protected ConnectionCountHandler getConnectionCountHandler() {
-                return AbstractConfigurableAsyncServer.this.getConnectionCountHandler();
-            }
-
         };
     }
     
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractExecutorAwareChannelPipelineFactory.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractExecutorAwareChannelPipelineFactory.java
deleted file mode 100644
index 07e55ea4e6..0000000000
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractExecutorAwareChannelPipelineFactory.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/****************************************************************
- * 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.lib.netty;
-
-import org.apache.james.protocols.api.Encryption;
-import org.apache.james.protocols.netty.AbstractSSLAwareChannelPipelineFactory;
-import org.apache.james.protocols.netty.ChannelHandlerFactory;
-
-import io.netty.channel.ChannelHandler;
-import io.netty.util.concurrent.EventExecutorGroup;
-
-/**
- * Abstract base class which should get used if you MAY need an {@link ExecutionHandler}
- * 
- *
- */
-@ChannelHandler.Sharable
-public abstract class AbstractExecutorAwareChannelPipelineFactory extends AbstractSSLAwareChannelPipelineFactory {
-
-    public AbstractExecutorAwareChannelPipelineFactory(int timeout, int maxConnections, int maxConnectsPerIp,
-                                                       Encryption encryption,
-                                                       ChannelHandlerFactory frameHandlerFactory, EventExecutorGroup eventExecutorGroup) {
-        super(timeout, maxConnections, maxConnectsPerIp, encryption, frameHandlerFactory, eventExecutorGroup);
-    }
-    
-    /**
-     * Return the {@link ConnectionCountHandler} to use
-     * 
-     * @return cHandler
-     */
-    protected abstract ConnectionCountHandler getConnectionCountHandler();
-
-}
diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/ConnectionCountHandler.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/ConnectionCountHandler.java
deleted file mode 100644
index 16eca52e96..0000000000
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/ConnectionCountHandler.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/****************************************************************
- * 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.lib.netty;
-
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicLong;
-
-import io.netty.channel.ChannelHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-
-/**
- * Count connections
- */
-@ChannelHandler.Sharable
-public class ConnectionCountHandler extends ChannelInboundHandlerAdapter {
-
-    public final AtomicInteger currentConnectionCount = new AtomicInteger();
-    public final AtomicLong connectionsTillStartup = new AtomicLong();
-
-    @Override
-    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
-        currentConnectionCount.decrementAndGet();
-        super.channelInactive(ctx);
-    }
-
-    @Override
-    public void channelActive(ChannelHandlerContext ctx) throws Exception {
-        currentConnectionCount.incrementAndGet();
-        connectionsTillStartup.incrementAndGet();
-        super.channelActive(ctx);
-    }
-
-    /**
-     * Return the count of the current open connections
-     * 
-     * @return count
-     */
-    public int getCurrentConnectionCount() {
-        return currentConnectionCount.get();
-    }
-
-    /**
-     * Return the count of all connections which where made till the server
-     * was started
-     * 
-     * @return tillCount
-     */
-    public long getConnectionsTillStartup() {
-        return connectionsTillStartup.get();
-    }
-}
diff --git a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
index 6af2449b83..e1753601c4 100644
--- a/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
+++ b/server/protocols/protocols-managesieve/src/main/java/org/apache/james/managesieveserver/netty/ManageSieveServer.java
@@ -107,7 +107,6 @@ public class ManageSieveServer extends AbstractConfigurableAsyncServer implement
                 // don't strip the delimiter and use CRLF as delimiter
                 // Use a SwitchableDelimiterBasedFrameDecoder, see JAMES-1436
                 pipeline.addLast(getExecutorGroup(), FRAMER, getFrameHandlerFactory().create(pipeline));
-                pipeline.addLast(getExecutorGroup(), CONNECTION_COUNT_HANDLER, getConnectionCountHandler());
                 pipeline.addLast(getExecutorGroup(), CHUNK_WRITE_HANDLER, new ChunkedWriteHandler());
 
                 pipeline.addLast(getExecutorGroup(), "stringDecoder", new StringDecoder(CharsetUtil.UTF_8));
diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
index 8b357c8d0d..46ee7d6511 100644
--- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
+++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
@@ -350,18 +350,9 @@ public class SMTPServerTest {
 
     }
 
-    private void ensureIsDisconnected(SMTPClient client) throws IOException, InterruptedException {
-        int initialConnections = smtpServer.getCurrentConnections();
+    private void ensureIsDisconnected(SMTPClient client) throws IOException {
         client.quit();
         client.disconnect();
-        assertIsDisconnected(initialConnections);
-    }
-
-    private void assertIsDisconnected(int initialConnections) throws InterruptedException {
-        int iterations = 0;
-        while (smtpServer.getCurrentConnections() >= initialConnections && iterations++ < MAX_ITERATIONS) {
-            Thread.sleep(HALF_SECOND);
-        }
     }
 
     @AfterEach


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


[james-project] 09/19: JAMES-3715 Fix small warnings in AbstractServerFactory

Posted by bt...@apache.org.
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 ce87d835df789627440d17d61c73d7f655f13c29
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 3 12:40:13 2022 +0700

    JAMES-3715 Fix small warnings in AbstractServerFactory
---
 .../apache/james/protocols/lib/netty/AbstractServerFactory.java   | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractServerFactory.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractServerFactory.java
index ef57ae615b..bf672d5efa 100644
--- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractServerFactory.java
+++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/netty/AbstractServerFactory.java
@@ -25,7 +25,6 @@ import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 
 import org.apache.commons.configuration2.HierarchicalConfiguration;
-import org.apache.commons.configuration2.ex.ConfigurationException;
 import org.apache.commons.configuration2.tree.ImmutableNode;
 import org.apache.james.lifecycle.api.Configurable;
 
@@ -40,14 +39,12 @@ public abstract class AbstractServerFactory implements Configurable {
     /**
      * Create {@link AbstractConfigurableAsyncServer} servers, inject dependencies and configure them before return all fo them in a {@link List}
      *
-     * @param config
      * @return servers
-     * @throws Exception
      */
     protected abstract List<AbstractConfigurableAsyncServer> createServers(HierarchicalConfiguration<ImmutableNode> config) throws Exception;
     
     @Override
-    public void configure(HierarchicalConfiguration<ImmutableNode> config) throws ConfigurationException {
+    public void configure(HierarchicalConfiguration<ImmutableNode> config) {
         this.config = config;
     }
 
@@ -60,8 +57,7 @@ public abstract class AbstractServerFactory implements Configurable {
     }
     
     /**
-     * Return all {@link AbstractConfigurableAsyncServer} instances that was create via this Factory
-     * @return
+     * @return all {@link AbstractConfigurableAsyncServer} instances that was create via this Factory
      */
     public List<AbstractConfigurableAsyncServer> getServers() {
         return servers;


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


[james-project] 05/19: JAMES-3715 ConnectionPerIpLimitUpstreamHandler: counter not incremented upon insert conflict

Posted by bt...@apache.org.
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 50f43a922cd95e205f14be44237ce933128762a3
Author: Benoit Tellier <bt...@linagora.com>
AuthorDate: Thu Mar 3 12:14:45 2022 +0700

    JAMES-3715 ConnectionPerIpLimitUpstreamHandler: counter not incremented upon insert conflict
---
 .../james/protocols/netty/ConnectionPerIpLimitUpstreamHandler.java      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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 848b24aa14..2a8e642d04 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
@@ -66,7 +66,7 @@ public class ConnectionPerIpLimitUpstreamHandler extends ChannelInboundHandlerAd
             AtomicInteger oldAtomicCount = connections.putIfAbsent(remoteIp, atomicCount);
             // if another thread put a new counter for this ip, we must use the other one.
             if (oldAtomicCount != null) {
-                atomicCount = oldAtomicCount;
+                oldAtomicCount.incrementAndGet();
             }
         } else {
             Integer count = atomicCount.incrementAndGet();


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