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:12 UTC
[james-project] 03/19: JAMES-3715 ConnectionCountHandler state was unused by production code
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