activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [activemq-artemis] branch master updated: ARTEMIS-2904 prevent acceptor from automatically starting
Date Thu, 24 Sep 2020 00:19:28 GMT
This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new beaacbf  ARTEMIS-2904 prevent acceptor from automatically starting
     new 312b932  This closes #3266
beaacbf is described below

commit beaacbfa8d8a239d6c4e5af0bcfb2a98e3a50e2a
Author: Justin Bertram <jbertram@apache.org>
AuthorDate: Thu Sep 17 10:24:28 2020 -0500

    ARTEMIS-2904 prevent acceptor from automatically starting
---
 .../artemis/core/remoting/impl/netty/TransportConstants.java |  5 +++++
 .../artemis/core/remoting/impl/netty/NettyAcceptor.java      |  8 ++++++++
 .../core/remoting/server/impl/RemotingServiceImpl.java       |  4 ++++
 docs/user-manual/en/configuring-transports.md                |  3 +++
 .../unit/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 8bc25a9..726d28d 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 716123a..a3bf4c0 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<String, Object> 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 c526ba5..c7e54f3 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 d12bb60..652e404 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 2ab990d..7261d3c 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());
+   }
 }


Mime
View raw message