use of org.apache.activemq.artemis.api.core.management.BridgeControl in project activemq-artemis by apache.
the class ActiveMQServerControlImpl method getBridgeNames.
@Override
public String[] getBridgeNames() {
checkStarted();
clearIO();
try {
Object[] bridges = server.getManagementService().getResources(BridgeControl.class);
String[] names = new String[bridges.length];
for (int i = 0; i < bridges.length; i++) {
BridgeControl bridge = (BridgeControl) bridges[i];
names[i] = bridge.getName();
}
return names;
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.api.core.management.BridgeControl in project activemq-artemis by apache.
the class BridgeControlTest method testAttributes.
@Test
public void testAttributes() throws Exception {
checkResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(bridgeConfig.getName()));
BridgeControl bridgeControl = createBridgeControl(bridgeConfig.getName(), mbeanServer);
Assert.assertEquals(bridgeConfig.getName(), bridgeControl.getName());
Assert.assertEquals(bridgeConfig.getDiscoveryGroupName(), bridgeControl.getDiscoveryGroupName());
Assert.assertEquals(bridgeConfig.getQueueName(), bridgeControl.getQueueName());
Assert.assertEquals(bridgeConfig.getForwardingAddress(), bridgeControl.getForwardingAddress());
Assert.assertEquals(bridgeConfig.getFilterString(), bridgeControl.getFilterString());
Assert.assertEquals(bridgeConfig.getRetryInterval(), bridgeControl.getRetryInterval());
Assert.assertEquals(bridgeConfig.getRetryIntervalMultiplier(), bridgeControl.getRetryIntervalMultiplier(), 0.000001);
Assert.assertEquals(bridgeConfig.getReconnectAttempts(), bridgeControl.getReconnectAttempts());
Assert.assertEquals(bridgeConfig.isUseDuplicateDetection(), bridgeControl.isUseDuplicateDetection());
String[] connectorPairData = bridgeControl.getStaticConnectors();
Assert.assertEquals(bridgeConfig.getStaticConnectors().get(0), connectorPairData[0]);
Assert.assertTrue(bridgeControl.isStarted());
}
use of org.apache.activemq.artemis.api.core.management.BridgeControl in project activemq-artemis by apache.
the class BridgeControlTest method testStartStop.
@Test
public void testStartStop() throws Exception {
checkResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(bridgeConfig.getName()));
BridgeControl bridgeControl = createBridgeControl(bridgeConfig.getName(), mbeanServer);
// started by the server
Assert.assertTrue(bridgeControl.isStarted());
bridgeControl.stop();
Assert.assertFalse(bridgeControl.isStarted());
bridgeControl.start();
Assert.assertTrue(bridgeControl.isStarted());
}
use of org.apache.activemq.artemis.api.core.management.BridgeControl in project activemq-artemis by apache.
the class ManagementServiceImpl method registerBridge.
@Override
public synchronized void registerBridge(final Bridge bridge, final BridgeConfiguration configuration) throws Exception {
bridge.setNotificationService(this);
ObjectName objectName = objectNameBuilder.getBridgeObjectName(configuration.getName());
BridgeControl control = new BridgeControlImpl(bridge, storageManager, configuration);
registerInJMX(objectName, control);
registerInRegistry(ResourceNames.BRIDGE + configuration.getName(), control);
}
use of org.apache.activemq.artemis.api.core.management.BridgeControl in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testCreateAndDestroyBridge.
@Test
public void testCreateAndDestroyBridge() throws Exception {
String name = RandomUtil.randomString();
String sourceAddress = RandomUtil.randomString();
String sourceQueue = RandomUtil.randomString();
String targetAddress = RandomUtil.randomString();
String targetQueue = RandomUtil.randomString();
ActiveMQServerControl serverControl = createManagementControl();
checkNoResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(name));
assertEquals(0, serverControl.getBridgeNames().length);
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory csf = createSessionFactory(locator);
ClientSession session = csf.createSession();
session.createQueue(sourceAddress, RoutingType.ANYCAST, sourceQueue);
session.createQueue(targetAddress, RoutingType.ANYCAST, targetQueue);
// forwardingAddress
serverControl.createBridge(// forwardingAddress
name, // forwardingAddress
sourceQueue, // forwardingAddress
targetAddress, // forwardingAddress
null, // filterString
null, // duplicateDetection
ActiveMQClient.DEFAULT_RETRY_INTERVAL, // duplicateDetection
ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER, // duplicateDetection
ActiveMQClient.INITIAL_CONNECT_ATTEMPTS, // duplicateDetection
ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS, // duplicateDetection
false, // confirmationWindowSize
1, // producerWindowSize
-1, // liveConnector
ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD, // liveConnector
connectorConfig.getName(), false, false, null, null);
checkResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(name));
String[] bridgeNames = serverControl.getBridgeNames();
assertEquals(1, bridgeNames.length);
assertEquals(name, bridgeNames[0]);
BridgeControl bridgeControl = ManagementControlHelper.createBridgeControl(name, mbeanServer);
assertEquals(name, bridgeControl.getName());
assertTrue(bridgeControl.isStarted());
// check that a message sent to the sourceAddress is put in the tagetQueue
ClientProducer producer = session.createProducer(sourceAddress);
ClientMessage message = session.createMessage(false);
String text = RandomUtil.randomString();
message.putStringProperty("prop", text);
producer.send(message);
session.start();
ClientConsumer targetConsumer = session.createConsumer(targetQueue);
message = targetConsumer.receive(5000);
assertNotNull(message);
assertEquals(text, message.getStringProperty("prop"));
ClientConsumer sourceConsumer = session.createConsumer(sourceQueue);
assertNull(sourceConsumer.receiveImmediate());
serverControl.destroyBridge(name);
checkNoResource(ObjectNameBuilder.DEFAULT.getBridgeObjectName(name));
assertEquals(0, serverControl.getBridgeNames().length);
// check that a message is no longer diverted
message = session.createMessage(false);
String text2 = RandomUtil.randomString();
message.putStringProperty("prop", text2);
producer.send(message);
assertNull(targetConsumer.receiveImmediate());
message = sourceConsumer.receive(5000);
assertNotNull(message);
assertEquals(text2, message.getStringProperty("prop"));
sourceConsumer.close();
targetConsumer.close();
session.deleteQueue(sourceQueue);
session.deleteQueue(targetQueue);
session.close();
locator.close();
}
Aggregations