From 74d0a1a8182947741a3eedb2e52d51ddcee475d7 Mon Sep 17 00:00:00 2001 From: Andy Taylor Date: Wed, 30 Nov 2016 13:56:37 +0000 Subject: [PATCH] ARTEMIS-784 Add new JMX methods and update JMX API --- .../core/management/ActiveMQServerControl.java | 2 +- .../api/core/management/ObjectNameBuilder.java | 17 ++++++++++++++--- .../impl/ActiveMQServerControlImpl.java | 6 ++---- .../core/postoffice/impl/PostOfficeImpl.java | 3 ++- .../server/management/ManagementService.java | 3 ++- .../management/impl/ManagementServiceImpl.java | 7 ++++--- .../group/impl/ClusteredResetMockTest.java | 3 ++- .../management/ActiveMQServerControlTest.java | 2 +- .../ActiveMQServerControlUsingCoreTest.java | 2 +- .../management/ManagementControlHelper.java | 3 ++- .../jms/bridge/impl/JMSBridgeImplTest.java | 3 ++- 11 files changed, 33 insertions(+), 18 deletions(-) diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java index b6b5b5e5b4..cd257c6523 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java @@ -436,7 +436,7 @@ public interface ActiveMQServerControl { @Operation(desc = "delete an address", impact = MBeanOperationInfo.ACTION) void createAddress(@Parameter(name = "name", desc = "The name of the address") String name, - @Parameter(name = "deliveryMode", desc = "The delivery modes enabled for this address'") Object[] routingTypes) throws Exception; + @Parameter(name = "routingType", desc = "Comma separated list of Routing Typles (anycast/multicast)") String routingTypes) throws Exception; @Operation(desc = "delete an address", impact = MBeanOperationInfo.ACTION) void deleteAddress(@Parameter(name = "name", desc = "The name of the address") String name) throws Exception; diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ObjectNameBuilder.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ObjectNameBuilder.java index 3bbd45658c..00a95e1634 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ObjectNameBuilder.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ObjectNameBuilder.java @@ -20,6 +20,7 @@ import javax.management.ObjectName; import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; import org.apache.activemq.artemis.api.core.SimpleString; +import org.apache.activemq.artemis.core.server.RoutingType; /** * Helper class to build ObjectNames for ActiveMQ Artemis resources. @@ -98,10 +99,20 @@ public final class ObjectNameBuilder { * * @see QueueControl */ - public ObjectName getQueueObjectName(final SimpleString address, final SimpleString name) throws Exception { - return ObjectName.getInstance(String.format("%s:" + getBrokerProperties() + "parentType=%s,parentName=%s," + getObjectType() + "=%s,name=%s", domain, "Address", ObjectName.quote(address.toString()), "Queue", ObjectName.quote(name.toString()))); + public ObjectName getQueueObjectName(final SimpleString address, final SimpleString name, RoutingType routingType) throws Exception { + return ObjectName.getInstance(String.format("%s:" + getBrokerProperties() + "parentType=%s,parentName=%s," + getObjectType() + "=%s, routingType=%s,name=%s", domain, "Address", ObjectName.quote(address.toString()), "Queue", routingType.toString(), ObjectName.quote(name.toString()))); } + /** + * Returns the ObjectName used by QueueControl. + * + * @see QueueControl + */ + public ObjectName getQueueObjectName(final SimpleString address, final SimpleString name) throws Exception { + return ObjectName.getInstance(String.format("%s:" + getBrokerProperties() + "parentType=%s,parentName=%s," + getObjectType() + "=%s, routingType=%s,name=%s", domain, "Address", ObjectName.quote(address.toString()), "Queue", ActiveMQDefaultConfiguration.getDefaultRoutingType(), ObjectName.quote(name.toString()))); + } + + /** * Returns the ObjectName used by DivertControl. * @@ -165,7 +176,7 @@ public final class ObjectNameBuilder { * Returns the ObjectName used by JMSQueueControl. */ public ObjectName getJMSQueueObjectName(final String name) throws Exception { - return getQueueObjectName(SimpleString.toSimpleString(name), SimpleString.toSimpleString(name)); + return getQueueObjectName(SimpleString.toSimpleString(name), SimpleString.toSimpleString(name), RoutingType.ANYCAST); } /** diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java index e6c32c8248..82f3943512 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java @@ -52,7 +52,6 @@ import org.apache.activemq.artemis.api.core.management.AddressControl; import org.apache.activemq.artemis.api.core.management.BridgeControl; import org.apache.activemq.artemis.api.core.management.CoreNotificationType; import org.apache.activemq.artemis.api.core.management.DivertControl; -import org.apache.activemq.artemis.api.core.management.Parameter; import org.apache.activemq.artemis.api.core.management.QueueControl; import org.apache.activemq.artemis.core.client.impl.Topology; import org.apache.activemq.artemis.core.client.impl.TopologyMemberImpl; @@ -563,14 +562,13 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active } @Override - public void createAddress(@Parameter(name = "name", desc = "The name of the address") String name, - @Parameter(name = "routingType", desc = "The delivery modes enabled for this address'") Object[] routingTypes) throws Exception { + public void createAddress(String name, String routingTypes) throws Exception { checkStarted(); clearIO(); try { Set set = new HashSet<>(); - for (Object routingType : routingTypes) { + for (Object routingType : toList(routingTypes)) { set.add(RoutingType.valueOf(routingType.toString())); } server.createAddressInfo(new AddressInfo(new SimpleString(name), set)); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java index e060542075..9bd69d1f94 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/postoffice/impl/PostOfficeImpl.java @@ -539,7 +539,8 @@ public class PostOfficeImpl implements PostOffice, NotificationListener, Binding } if (binding.getType() == BindingType.LOCAL_QUEUE) { - managementService.unregisterQueue(uniqueName, binding.getAddress()); + Queue queue = (Queue) binding.getBindable(); + managementService.unregisterQueue(uniqueName, binding.getAddress(), queue.getRoutingType()); } else if (binding.getType() == BindingType.DIVERT) { managementService.unregisterDivert(uniqueName, binding.getAddress()); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementService.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementService.java index 58d91a498f..767e3f04a5 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementService.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/ManagementService.java @@ -41,6 +41,7 @@ import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.Divert; import org.apache.activemq.artemis.core.server.Queue; import org.apache.activemq.artemis.core.server.QueueFactory; +import org.apache.activemq.artemis.core.server.RoutingType; import org.apache.activemq.artemis.core.server.ServerMessage; import org.apache.activemq.artemis.core.server.cluster.Bridge; import org.apache.activemq.artemis.core.server.cluster.BroadcastGroup; @@ -96,7 +97,7 @@ public interface ManagementService extends NotificationService, ActiveMQComponen void registerQueue(Queue queue, SimpleString address, StorageManager storageManager) throws Exception; - void unregisterQueue(SimpleString name, SimpleString address) throws Exception; + void unregisterQueue(SimpleString name, SimpleString address, RoutingType routingType) throws Exception; void registerAcceptor(Acceptor acceptor, TransportConfiguration configuration) throws Exception; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java index 213f965e29..71d988d1ab 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java @@ -71,6 +71,7 @@ import org.apache.activemq.artemis.core.server.ActiveMQServerLogger; import org.apache.activemq.artemis.core.server.Divert; import org.apache.activemq.artemis.core.server.Queue; import org.apache.activemq.artemis.core.server.QueueFactory; +import org.apache.activemq.artemis.core.server.RoutingType; import org.apache.activemq.artemis.core.server.ServerMessage; import org.apache.activemq.artemis.core.server.cluster.Bridge; import org.apache.activemq.artemis.core.server.cluster.BroadcastGroup; @@ -241,7 +242,7 @@ public class ManagementServiceImpl implements ManagementService { queueControl.setMessageCounter(counter); messageCounterManager.registerMessageCounter(queue.getName().toString(), counter); } - ObjectName objectName = objectNameBuilder.getQueueObjectName(address, queue.getName()); + ObjectName objectName = objectNameBuilder.getQueueObjectName(address, queue.getName(),queue.getRoutingType()); registerInJMX(objectName, queueControl); registerInRegistry(ResourceNames.QUEUE + queue.getName(), queueControl); @@ -251,8 +252,8 @@ public class ManagementServiceImpl implements ManagementService { } @Override - public synchronized void unregisterQueue(final SimpleString name, final SimpleString address) throws Exception { - ObjectName objectName = objectNameBuilder.getQueueObjectName(address, name); + public synchronized void unregisterQueue(final SimpleString name, final SimpleString address, RoutingType routingType) throws Exception { + ObjectName objectName = objectNameBuilder.getQueueObjectName(address, name, routingType); unregisterFromJMX(objectName); unregisterFromRegistry(ResourceNames.QUEUE + name); messageCounterManager.unregisterMessageCounter(name.toString()); diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/group/impl/ClusteredResetMockTest.java b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/group/impl/ClusteredResetMockTest.java index 3736c0501c..5d612864b5 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/group/impl/ClusteredResetMockTest.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/group/impl/ClusteredResetMockTest.java @@ -43,6 +43,7 @@ import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.Divert; import org.apache.activemq.artemis.core.server.Queue; import org.apache.activemq.artemis.core.server.QueueFactory; +import org.apache.activemq.artemis.core.server.RoutingType; import org.apache.activemq.artemis.core.server.ServerMessage; import org.apache.activemq.artemis.core.server.cluster.Bridge; import org.apache.activemq.artemis.core.server.cluster.BroadcastGroup; @@ -261,7 +262,7 @@ public class ClusteredResetMockTest extends ActiveMQTestBase { } @Override - public void unregisterQueue(SimpleString name, SimpleString address) throws Exception { + public void unregisterQueue(SimpleString name, SimpleString address, RoutingType routingType) throws Exception { } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java index 4ca23c4fb1..b75e019214 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java @@ -268,7 +268,7 @@ public class ActiveMQServerControlTest extends ManagementTestBase { serverControl.createQueue(address.toString(), RoutingType.ANYCAST.toString(), name.toString(), null, durable, maxConsumers, deleteOnNoConsumers, autoCreateAddress); - checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name)); + checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST)); QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, mbeanServer); Assert.assertEquals(address.toString(), queueControl.getAddress()); Assert.assertEquals(name.toString(), queueControl.getName()); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java index 5e02ff8e9a..985b4957d0 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java @@ -566,7 +566,7 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes @Override public void createAddress(@Parameter(name = "name", desc = "The name of the address") String name, - @Parameter(name = "routingType", desc = "The delivery modes enabled for this address'") Object[] routingTypes) throws Exception { + @Parameter(name = "routingType", desc = "The delivery modes enabled for this address'") String routingTypes) throws Exception { } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementControlHelper.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementControlHelper.java index 0f822226fb..6bc8f3dd13 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementControlHelper.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ManagementControlHelper.java @@ -20,6 +20,7 @@ import javax.management.MBeanServer; import javax.management.MBeanServerInvocationHandler; import javax.management.ObjectName; +import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.management.AcceptorControl; import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl; @@ -69,7 +70,7 @@ public class ManagementControlHelper { public static QueueControl createQueueControl(final SimpleString address, final SimpleString name, final MBeanServer mbeanServer) throws Exception { - return (QueueControl) ManagementControlHelper.createProxy(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name), QueueControl.class, mbeanServer); + return (QueueControl) ManagementControlHelper.createProxy(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, ActiveMQDefaultConfiguration.getDefaultRoutingType()), QueueControl.class, mbeanServer); } public static AddressControl createAddressControl(final SimpleString address, diff --git a/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/jms/bridge/impl/JMSBridgeImplTest.java b/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/jms/bridge/impl/JMSBridgeImplTest.java index 6aefd523e5..d49afabdff 100644 --- a/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/jms/bridge/impl/JMSBridgeImplTest.java +++ b/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/jms/bridge/impl/JMSBridgeImplTest.java @@ -55,6 +55,7 @@ import org.apache.activemq.artemis.core.registry.JndiBindingRegistry; import org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory; import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory; import org.apache.activemq.artemis.core.server.ActiveMQServers; +import org.apache.activemq.artemis.core.server.RoutingType; import org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory; import org.apache.activemq.artemis.jms.bridge.DestinationFactory; import org.apache.activemq.artemis.jms.bridge.QualityOfServiceMode; @@ -470,7 +471,7 @@ public class JMSBridgeImplTest extends ActiveMQTestBase { sourceConn.close(); SimpleString add = new SimpleString(JMSBridgeImplTest.SOURCE); - QueueControl jmsQueueControl = MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(), ObjectNameBuilder.DEFAULT.getQueueObjectName(add, add), QueueControl.class, false); + QueueControl jmsQueueControl = MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(), ObjectNameBuilder.DEFAULT.getQueueObjectName(add, add, RoutingType.ANYCAST), QueueControl.class, false); assertNotEquals(jmsQueueControl.getDeliveringCount(), numMessages); bridge.stop();