ARTEMIS-1065 get queue names by routing type

This commit is contained in:
Justin Bertram 2017-03-28 20:26:31 -05:00 committed by Clebert Suconic
parent 9b11914c21
commit ce3adf6fa8
7 changed files with 67 additions and 12 deletions

View File

@ -395,6 +395,12 @@ public interface ActiveMQServerControl {
@Attribute(desc = "names of the queues created on this server") @Attribute(desc = "names of the queues created on this server")
String[] getQueueNames(); 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. * Returns the uptime of this server.
*/ */

View File

@ -59,8 +59,8 @@ public interface QueueControl {
/** /**
* The routing type of this queue. * The routing type of this queue.
*/ */
@Attribute(desc = "The routing type of this queue") @Attribute(desc = "routing type of this queue")
byte getRoutingType() throws Exception; String getRoutingType();
/** /**
* Returns the filter associated with this queue. * Returns the filter associated with this queue.

View File

@ -782,18 +782,28 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active
@Override @Override
public String[] getQueueNames() { public String[] getQueueNames() {
return getQueueNames(null);
}
@Override
public String[] getQueueNames(String routingType) {
checkStarted(); checkStarted();
clearIO(); clearIO();
try { try {
Object[] queues = server.getManagementService().getResources(QueueControl.class); Object[] queueControls = server.getManagementService().getResources(QueueControl.class);
String[] names = new String[queues.length]; List<String> names = new ArrayList<>();
for (int i = 0; i < queues.length; i++) { for (int i = 0; i < queueControls.length; i++) {
QueueControl queue = (QueueControl) queues[i]; QueueControl queueControl = (QueueControl) queueControls[i];
names[i] = queue.getName(); 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 { } finally {
blockOnIO(); blockOnIO();
} }

View File

@ -176,12 +176,12 @@ public class QueueControlImpl extends AbstractControl implements QueueControl {
} }
@Override @Override
public byte getRoutingType() throws Exception { public String getRoutingType() {
checkStarted(); checkStarted();
clearIO(); clearIO();
try { try {
return queue.getRoutingType().getType(); return queue.getRoutingType().toString();
} finally { } finally {
blockOnIO(); blockOnIO();
} }

View File

@ -392,6 +392,34 @@ public class ActiveMQServerControlTest extends ManagementTestBase {
Assert.assertFalse(ActiveMQServerControlTest.contains(name.toString(), serverControl.getQueueNames())); 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 @Test
public void testGetAddressNames() throws Exception { public void testGetAddressNames() throws Exception {
SimpleString address = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString();

View File

@ -260,6 +260,17 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes
return ActiveMQServerControlUsingCoreTest.toStringArray((Object[]) proxy.retrieveAttributeValue("queueNames", String.class)); 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 @Override
public String getUptime() { public String getUptime() {
return null; return null;

View File

@ -172,8 +172,8 @@ public class QueueControlUsingCoreTest extends QueueControlTest {
} }
@Override @Override
public byte getRoutingType() throws Exception { public String getRoutingType() {
return (byte) proxy.retrieveAttributeValue("routingType"); return (String) proxy.retrieveAttributeValue("routingType");
} }
@Override @Override