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 04af61eeb3..3192609e7a 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 @@ -395,6 +395,12 @@ public interface ActiveMQServerControl { @Attribute(desc = "names of the queues created on this server") String[] getQueueNames(); + /** + * Returns the names of the queues created on this server with the given routing-type. + */ + @Attribute(desc = "names of the queues created on this server with the given routing-type (i.e. ANYCAST or MULTICAST)") + String[] getQueueNames(String routingType); + /** * Returns the uptime of this server. */ diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/QueueControl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/QueueControl.java index 11c98ad766..1bc28d411c 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/QueueControl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/QueueControl.java @@ -59,8 +59,8 @@ public interface QueueControl { /** * The routing type of this queue. */ - @Attribute(desc = "The routing type of this queue") - byte getRoutingType() throws Exception; + @Attribute(desc = "routing type of this queue") + String getRoutingType(); /** * Returns the filter associated with this queue. 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 734933a614..ad906272d4 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 @@ -782,18 +782,28 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active @Override public String[] getQueueNames() { + return getQueueNames(null); + } + + @Override + public String[] getQueueNames(String routingType) { checkStarted(); clearIO(); try { - Object[] queues = server.getManagementService().getResources(QueueControl.class); - String[] names = new String[queues.length]; - for (int i = 0; i < queues.length; i++) { - QueueControl queue = (QueueControl) queues[i]; - names[i] = queue.getName(); + Object[] queueControls = server.getManagementService().getResources(QueueControl.class); + List names = new ArrayList<>(); + for (int i = 0; i < queueControls.length; i++) { + QueueControl queueControl = (QueueControl) queueControls[i]; + if (routingType != null && queueControl.getRoutingType().equals(routingType.toUpperCase())) { + names.add(queueControl.getName()); + } else if (routingType == null) { + names.add(queueControl.getName()); + } } - return names; + String[] result = new String[names.size()]; + return names.toArray(result); } finally { blockOnIO(); } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java index f96556198e..2e886f9f73 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java @@ -176,12 +176,12 @@ public class QueueControlImpl extends AbstractControl implements QueueControl { } @Override - public byte getRoutingType() throws Exception { + public String getRoutingType() { checkStarted(); clearIO(); try { - return queue.getRoutingType().getType(); + return queue.getRoutingType().toString(); } finally { blockOnIO(); } 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 7d84e1f721..526a5ae2ac 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 @@ -392,6 +392,34 @@ public class ActiveMQServerControlTest extends ManagementTestBase { Assert.assertFalse(ActiveMQServerControlTest.contains(name.toString(), serverControl.getQueueNames())); } + @Test + public void testGetQueueNamesWithRoutingType() throws Exception { + SimpleString address = RandomUtil.randomSimpleString(); + SimpleString anycastName = RandomUtil.randomSimpleString(); + SimpleString multicastName = RandomUtil.randomSimpleString(); + + ActiveMQServerControl serverControl = createManagementControl(); + + // due to replication, there can be another queue created for replicating + // management operations + + Assert.assertFalse(ActiveMQServerControlTest.contains(anycastName.toString(), serverControl.getQueueNames())); + Assert.assertFalse(ActiveMQServerControlTest.contains(multicastName.toString(), serverControl.getQueueNames())); + + serverControl.createQueue(address.toString(), RoutingType.ANYCAST.toString(), anycastName.toString(), null, true, -1, false, true); + Assert.assertTrue(ActiveMQServerControlTest.contains(anycastName.toString(), serverControl.getQueueNames(RoutingType.ANYCAST.toString()))); + Assert.assertFalse(ActiveMQServerControlTest.contains(anycastName.toString(), serverControl.getQueueNames(RoutingType.MULTICAST.toString()))); + + serverControl.createQueue(address.toString(), RoutingType.MULTICAST.toString(), multicastName.toString(), null, true, -1, false, true); + Assert.assertTrue(ActiveMQServerControlTest.contains(multicastName.toString(), serverControl.getQueueNames(RoutingType.MULTICAST.toString()))); + Assert.assertFalse(ActiveMQServerControlTest.contains(multicastName.toString(), serverControl.getQueueNames(RoutingType.ANYCAST.toString()))); + + serverControl.destroyQueue(anycastName.toString()); + serverControl.destroyQueue(multicastName.toString()); + Assert.assertFalse(ActiveMQServerControlTest.contains(anycastName.toString(), serverControl.getQueueNames())); + Assert.assertFalse(ActiveMQServerControlTest.contains(multicastName.toString(), serverControl.getQueueNames())); + } + @Test public void testGetAddressNames() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); 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 d2ebe8d135..75e72fde93 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 @@ -260,6 +260,17 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes return ActiveMQServerControlUsingCoreTest.toStringArray((Object[]) proxy.retrieveAttributeValue("queueNames", String.class)); } + @Override + public String[] getQueueNames(String routingType) { + try { + return (String[]) proxy.invokeOperation("getQueueNames", routingType); + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + @Override public String getUptime() { return null; diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlUsingCoreTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlUsingCoreTest.java index e96b5cb2b7..f778ef608a 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlUsingCoreTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlUsingCoreTest.java @@ -172,8 +172,8 @@ public class QueueControlUsingCoreTest extends QueueControlTest { } @Override - public byte getRoutingType() throws Exception { - return (byte) proxy.retrieveAttributeValue("routingType"); + public String getRoutingType() { + return (String) proxy.retrieveAttributeValue("routingType"); } @Override