From beaacbfa8d8a239d6c4e5af0bcfb2a98e3a50e2a Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Thu, 17 Sep 2020 10:24:28 -0500 Subject: [PATCH] ARTEMIS-2904 prevent acceptor from automatically starting --- .../core/remoting/impl/netty/TransportConstants.java | 5 +++++ .../core/remoting/impl/netty/NettyAcceptor.java | 8 ++++++++ .../remoting/server/impl/RemotingServiceImpl.java | 4 ++++ docs/user-manual/en/configuring-transports.md | 3 +++ .../core/remoting/impl/netty/NettyAcceptorTest.java | 12 ++++++++++++ 5 files changed, 32 insertions(+) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/TransportConstants.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/TransportConstants.java index 8bc25a918c..726d28d33a 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/TransportConstants.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/TransportConstants.java @@ -186,6 +186,10 @@ public class TransportConstants { public static final String PROXY_REMOTE_DNS_PROP_NAME = "socksRemoteDNS"; + public static final String AUTO_START = "autoStart"; + + public static final boolean DEFAULT_AUTO_START = true; + public static final boolean DEFAULT_SSL_ENABLED = false; public static final String DEFAULT_SSL_KRB5_CONFIG = null; @@ -420,6 +424,7 @@ public class TransportConstants { allowableAcceptorKeys.add(TransportConstants.SHUTDOWN_TIMEOUT); allowableAcceptorKeys.add(TransportConstants.QUIET_PERIOD); allowableAcceptorKeys.add(TransportConstants.DISABLE_STOMP_SERVER_HEADER); + allowableAcceptorKeys.add(TransportConstants.AUTO_START); ALLOWABLE_ACCEPTOR_KEYS = Collections.unmodifiableSet(allowableAcceptorKeys); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java index 716123a86f..a3bf4c0527 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java @@ -229,6 +229,8 @@ public class NettyAcceptor extends AbstractAcceptor { private Map extraConfigs; + private final boolean autoStart; + final AtomicBoolean warningPrinted = new AtomicBoolean(false); @@ -341,6 +343,8 @@ public class NettyAcceptor extends AbstractAcceptor { httpUpgradeEnabled = ConfigurationHelper.getBooleanProperty(TransportConstants.HTTP_UPGRADE_ENABLED_PROP_NAME, TransportConstants.DEFAULT_HTTP_UPGRADE_ENABLED, configuration); connectionsAllowed = ConfigurationHelper.getLongProperty(TransportConstants.CONNECTIONS_ALLOWED, TransportConstants.DEFAULT_CONNECTIONS_ALLOWED, configuration); + + autoStart = ConfigurationHelper.getBooleanProperty(TransportConstants.AUTO_START, TransportConstants.DEFAULT_AUTO_START, configuration); } @Override @@ -1017,4 +1021,8 @@ public class NettyAcceptor extends AbstractAcceptor { return (list.size() < 2 ? throwable : list.get(list.size() - 1)); } } + + public boolean isAutoStart() { + return autoStart; + } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java index c526ba5dfc..c7e54f3ba2 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/server/impl/RemotingServiceImpl.java @@ -49,6 +49,7 @@ import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.ConfigurationUtils; import org.apache.activemq.artemis.core.protocol.core.CoreRemotingConnection; import org.apache.activemq.artemis.core.protocol.core.impl.CoreProtocolManagerFactory; +import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor; import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants; import org.apache.activemq.artemis.core.remoting.server.RemotingService; import org.apache.activemq.artemis.core.security.ActiveMQPrincipal; @@ -310,6 +311,9 @@ public class RemotingServiceImpl implements RemotingService, ServerConnectionLif if (isStarted()) { for (Acceptor a : acceptors.values()) { try { + if (a instanceof NettyAcceptor && !((NettyAcceptor)a).isAutoStart()) { + continue; + } a.start(); } catch (Throwable t) { ActiveMQServerLogger.LOGGER.errorStartingAcceptor(a.getName(), a.getConfiguration()); diff --git a/docs/user-manual/en/configuring-transports.md b/docs/user-manual/en/configuring-transports.md index d12bb608ed..652e404048 100644 --- a/docs/user-manual/en/configuring-transports.md +++ b/docs/user-manual/en/configuring-transports.md @@ -260,6 +260,9 @@ simple TCP: value. When set value to zero or negative integer this feature is turned off. Changing value needs to restart server to take effect. +- `autoStart`. Determines whether or not an acceptor will start automatically + when the broker is started. Default value is `true`. + ### Configuring Netty Native Transport Netty Native Transport support exists for selected OS platforms. This allows diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java index 2ab990dffb..7261d3cd47 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/remoting/impl/netty/NettyAcceptorTest.java @@ -28,6 +28,7 @@ import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.core.remoting.impl.netty.NettyAcceptor; import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants; import org.apache.activemq.artemis.core.server.ActiveMQComponent; +import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.spi.core.protocol.ProtocolManager; import org.apache.activemq.artemis.spi.core.remoting.BufferHandler; import org.apache.activemq.artemis.spi.core.remoting.Connection; @@ -111,4 +112,15 @@ public class NettyAcceptorTest extends ActiveMQTestBase { Assert.assertTrue(PortCheckRule.checkAvailable(TransportConstants.DEFAULT_PORT)); } + @Test + public void testAutoStart() throws Exception { + ActiveMQServer server = createServer(false, createDefaultInVMConfig()); + server.getConfiguration().addAcceptorConfiguration("default", "tcp://127.0.0.1:61617"); + server.getConfiguration().addAcceptorConfiguration("start", "tcp://127.0.0.1:61618?autoStart=true"); + server.getConfiguration().addAcceptorConfiguration("noStart", "tcp://127.0.0.1:61619?autoStart=false"); + server.start(); + assertTrue(server.getRemotingService().getAcceptor("default").isStarted()); + assertTrue(server.getRemotingService().getAcceptor("start").isStarted()); + assertFalse(server.getRemotingService().getAcceptor("noStart").isStarted()); + } }