Skip to content

Commit

Permalink
[AMQ-9163] Add 'Started' attribute to ConnectorView (apache#932)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrpav authored Nov 14, 2022
1 parent 821e881 commit c259753
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public interface Connector extends Service {
String getUpdateClusterFilter();

long getMaxConnectionExceededCount();

/**
* @return true if connector is started
*/
public boolean isStarted();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +82,7 @@ public class TransportConnector implements Connector, BrokerServiceAware {
private boolean displayStackTrace = false;

LinkedList<String> peerBrokers = new LinkedList<String>();
private AtomicBoolean started = new AtomicBoolean(false);

public TransportConnector() {
}
Expand Down Expand Up @@ -273,6 +275,7 @@ private void onAcceptError(Exception error, String remoteHost) {
this.statusDector.start();
}

started.set(true);
LOG.info("Connector {} started", getName());
}

Expand Down Expand Up @@ -317,6 +320,7 @@ public void stop() throws Exception {
ss.stop(connection);
}
server = null;
started.set(false);
ss.throwFirstException();
LOG.info("Connector {} stopped", getName());
}
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,4 +141,9 @@ public boolean isAllowLinkStealingEnabled() {
public long getMaxConnectionExceededCount() {
return this.connector.getMaxConnectionExceededCount();
}

@Override
public boolean isStarted() {
return this.connector.isStarted();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit c259753

Please sign in to comment.