diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/Connector.java b/activemq-broker/src/main/java/org/apache/activemq/broker/Connector.java index c31e7692b4f..99d8026689c 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/Connector.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/Connector.java @@ -79,4 +79,9 @@ public interface Connector extends Service { String getUpdateClusterFilter(); long getMaxConnectionExceededCount(); + + /** + * @return true if connector is started + */ + public boolean isStarted(); } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnector.java b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnector.java index 0498795c684..78ab04cc703 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnector.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnector.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.StringTokenizer; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Pattern; import javax.management.ObjectName; @@ -81,6 +82,7 @@ public class TransportConnector implements Connector, BrokerServiceAware { private boolean displayStackTrace = false; LinkedList peerBrokers = new LinkedList(); + private AtomicBoolean started = new AtomicBoolean(false); public TransportConnector() { } @@ -273,6 +275,7 @@ private void onAcceptError(Exception error, String remoteHost) { this.statusDector.start(); } + started.set(true); LOG.info("Connector {} started", getName()); } @@ -317,6 +320,7 @@ public void stop() throws Exception { ss.stop(connection); } server = null; + started.set(false); ss.throwFirstException(); LOG.info("Connector {} stopped", getName()); } @@ -687,4 +691,9 @@ public void setDisplayStackTrace(boolean displayStackTrace) { public long getMaxConnectionExceededCount() { return (server != null ? server.getMaxConnectionExceededCount() : 0l); } + + @Override + public boolean isStarted() { + return started.get(); + } } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectorView.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectorView.java index d9960e9fdf4..3c7fbc91bce 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectorView.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectorView.java @@ -141,4 +141,9 @@ public boolean isAllowLinkStealingEnabled() { public long getMaxConnectionExceededCount() { return this.connector.getMaxConnectionExceededCount(); } + + @Override + public boolean isStarted() { + return this.connector.isStarted(); + } } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectorViewMBean.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectorViewMBean.java index 97ff8f5729f..547798574e8 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectorViewMBean.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ConnectorViewMBean.java @@ -89,4 +89,10 @@ public interface ConnectorViewMBean extends Service { */ @MBeanInfo("Max connection exceeded count") long getMaxConnectionExceededCount(); + + /** + * @return true if transport connector is started + */ + @MBeanInfo("Connector started") + boolean isStarted(); } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java index 6f55e3de38d..d795823a804 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/TransportConnectorMBeanTest.java @@ -18,10 +18,16 @@ import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import java.lang.management.ManagementFactory; import java.net.Socket; import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import javax.management.JMX; import javax.management.ObjectName; import org.apache.activemq.ActiveMQConnection; @@ -60,6 +66,18 @@ public void verifyClientIdDuplexNetwork() throws Exception { doVerifyClientIdNetwork(true); } + @Test + public void testStartStop() throws Exception { + createBroker(true); + final ConnectorViewMBean connectorViewMBean = JMX.newMBeanProxy(ManagementFactory.getPlatformMBeanServer(), BrokerMBeanSupport.createConnectorName(BrokerMBeanSupport.createBrokerObjectName("org.apache.activemq", "localhost").toString(), "clientConnectors", broker.getTransportConnectorByScheme("tcp").getPublishableConnectString()), ConnectorViewMBean.class); + assertNotNull(connectorViewMBean); + assertTrue(connectorViewMBean.isStarted()); + connectorViewMBean.stop(); + assertFalse(connectorViewMBean.isStarted()); + connectorViewMBean.start(); + assertTrue(connectorViewMBean.isStarted()); + } + private void doVerifyClientIdNetwork(boolean duplex) throws Exception { createBroker(true);