Create/delete queue JMX stuff
Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/9e3953b3 Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/9e3953b3 Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/9e3953b3 Branch: refs/heads/ARTEMIS-780 Commit: 9e3953b3afa1bfa0672a39bdffba00755fd9f7dc Parents: 3017201 Author: jbertram <[email protected]> Authored: Mon Nov 28 21:20:25 2016 -0600 Committer: jbertram <[email protected]> Committed: Mon Nov 28 21:20:25 2016 -0600 ---------------------------------------------------------------------- .../core/management/ActiveMQServerControl.java | 44 ++++++++++++++------ .../api/core/management/QueueControl.java | 12 ++++++ .../impl/ActiveMQServerControlImpl.java | 18 ++++---- .../core/management/impl/QueueControlImpl.java | 24 +++++++++++ .../core/server/impl/ActiveMQServerImpl.java | 2 +- .../management/ActiveMQServerControlTest.java | 37 ++++++++++++++++ .../ActiveMQServerControlUsingCoreTest.java | 24 +++++------ .../management/QueueControlUsingCoreTest.java | 10 +++++ 8 files changed, 136 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9e3953b3/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java ---------------------------------------------------------------------- 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 f002b5c..b6b5b5e 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 @@ -20,7 +20,6 @@ import javax.management.MBeanOperationInfo; import java.util.Map; import org.apache.activemq.artemis.api.core.ActiveMQAddressDoesNotExistException; -import org.apache.activemq.artemis.core.server.RoutingType; /** * An ActiveMQServerControl is used to manage ActiveMQ Artemis servers. @@ -456,14 +455,21 @@ public interface ActiveMQServerControl { void createQueue(@Parameter(name = "address", desc = "Address of the queue") String address, @Parameter(name = "name", desc = "Name of the queue") String name) throws Exception; + /** + * Create a queue. + * <br> + * If {@code address} is {@code null} it will be defaulted to {@code name}. + * <br> + * This method throws a {@link org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException}) exception if the queue already exits. + * + * @param address address to bind the queue to + * @param name name of the queue + * @param durable whether the queue is durable + */ + @Operation(desc = "Create a queue with the specified address, name and durability", impact = MBeanOperationInfo.ACTION) void createQueue(@Parameter(name = "address", desc = "Address of the queue") String address, - @Parameter(name = "routingType", desc = "The routing type used for this address, 0=multicast, 1=anycast") RoutingType routingType, @Parameter(name = "name", desc = "Name of the queue") String name, - @Parameter(name = "filter", desc = "Filter of the queue") String filterStr, - @Parameter(name = "durable", desc = "Is the queue durable?") boolean durable, - @Parameter(name = "maxConsumers", desc = "The maximum number of consumers allowed on this queue at any one time") int maxConsumers, - @Parameter(name = "deleteOnNoConsumers", desc = "Delete this queue when the last consumer disconnects") boolean deleteOnNoConsumers, - @Parameter(name = "autoCreateAddress", desc = "Create an address with default values should a matching address not be found") boolean autoCreateAddress) throws Exception; + @Parameter(name = "durable", desc = "Is the queue durable?") boolean durable) throws Exception; /** * Create a queue. @@ -490,14 +496,25 @@ public interface ActiveMQServerControl { * <br> * This method throws a {@link org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException}) exception if the queue already exits. * - * @param address address to bind the queue to - * @param name name of the queue - * @param durable whether the queue is durable + * @param address address to bind the queue to + * @param routingType the routing type used for this address, {@code MULTICAST} or {@code ANYCAST} + * @param name name of the queue + * @param filterStr filter of the queue + * @param durable is the queue durable? + * @param maxConsumers the maximum number of consumers allowed on this queue at any one time + * @param deleteOnNoConsumers delete this queue when the last consumer disconnects + * @param autoCreateAddress create an address with default values should a matching address not be found + * @throws Exception */ - @Operation(desc = "Create a queue with the specified address, name and durability", impact = MBeanOperationInfo.ACTION) void createQueue(@Parameter(name = "address", desc = "Address of the queue") String address, + @Parameter(name = "routingType", desc = "The routing type used for this address, MULTICAST or ANYCAST") String routingType, @Parameter(name = "name", desc = "Name of the queue") String name, - @Parameter(name = "durable", desc = "Is the queue durable?") boolean durable) throws Exception; + @Parameter(name = "filter", desc = "Filter of the queue") String filterStr, + @Parameter(name = "durable", desc = "Is the queue durable?") boolean durable, + @Parameter(name = "maxConsumers", desc = "The maximum number of consumers allowed on this queue at any one time") int maxConsumers, + @Parameter(name = "deleteOnNoConsumers", desc = "Delete this queue when the last consumer disconnects") boolean deleteOnNoConsumers, + @Parameter(name = "autoCreateAddress", desc = "Create an address with default values should a matching address not be found") boolean autoCreateAddress) throws Exception; + /** * Deploy a durable queue. @@ -551,7 +568,8 @@ public interface ActiveMQServerControl { */ @Operation(desc = "Destroy a queue", impact = MBeanOperationInfo.ACTION) void destroyQueue(@Parameter(name = "name", desc = "Name of the queue to destroy") String name, - @Parameter(name = "removeConsumers", desc = "Remove consumers of this queue") boolean removeConsumers, boolean autoDeleteAddress) throws Exception; + @Parameter(name = "removeConsumers", desc = "Remove consumers of this queue") boolean removeConsumers, + @Parameter(name = "autoDeleteAddress", desc = "Automatically delete the address if this was the last queue") boolean autoDeleteAddress) throws Exception; /** http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9e3953b3/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/QueueControl.java ---------------------------------------------------------------------- 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 bbf365c..dbd3ea5 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 @@ -140,6 +140,18 @@ public interface QueueControl { @Attribute(desc = "dead-letter address associated with this queue") String getDeadLetterAddress(); + /** + * + */ + @Attribute(desc = "maximum number of consumers allowed on this queue at any one time") + int getMaxConsumers(); + + /** + * + */ + @Attribute(desc = "delete this queue when the last consumer disconnects") + boolean isDeleteOnNoConsumers(); + // Operations ---------------------------------------------------- /** http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9e3953b3/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/ActiveMQServerControlImpl.java ---------------------------------------------------------------------- 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 c9214f3..9e103f4 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 @@ -647,14 +647,14 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active } @Override - public void createQueue(@Parameter(name = "address", desc = "Address of the queue") String address, - @Parameter(name = "routingType", desc = "The routing type used for this address, 0=multicast, 1=anycast") RoutingType routingType, - @Parameter(name = "name", desc = "Name of the queue") String name, - @Parameter(name = "filter", desc = "Filter of the queue") String filterStr, - @Parameter(name = "durable", desc = "Is the queue durable?") boolean durable, - @Parameter(name = "maxConsumers", desc = "The maximum number of consumers allowed on this queue at any one time") int maxConsumers, - @Parameter(name = "deleteOnNoConsumers", desc = "Delete this queue when the last consumer disconnects") boolean deleteOnNoConsumers, - @Parameter(name = "autoCreateAddress", desc = "Create an address with default values should a matching address not be found") boolean autoCreateAddress) throws Exception { + public void createQueue(String address, + String routingType, + String name, + String filterStr, + boolean durable, + int maxConsumers, + boolean deleteOnNoConsumers, + boolean autoCreateAddress) throws Exception { checkStarted(); clearIO(); @@ -665,7 +665,7 @@ public class ActiveMQServerControlImpl extends AbstractControl implements Active filter = new SimpleString(filterStr); } - server.createQueue(SimpleString.toSimpleString(address), routingType, new SimpleString(name), filter, durable, false, maxConsumers, deleteOnNoConsumers, autoCreateAddress); + server.createQueue(SimpleString.toSimpleString(address), RoutingType.valueOf(routingType), new SimpleString(name), filter, durable, false, maxConsumers, deleteOnNoConsumers, autoCreateAddress); } finally { blockOnIO(); } http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9e3953b3/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/QueueControlImpl.java ---------------------------------------------------------------------- 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 c4d25ac..3bbbac8 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 @@ -332,6 +332,30 @@ public class QueueControlImpl extends AbstractControl implements QueueControl { } @Override + public int getMaxConsumers() { + checkStarted(); + + clearIO(); + try { + return queue.getMaxConsumers(); + } finally { + blockOnIO(); + } + } + + @Override + public boolean isDeleteOnNoConsumers() { + checkStarted(); + + clearIO(); + try { + return queue.isDeleteOnNoConsumers(); + } finally { + blockOnIO(); + } + } + + @Override public Map<String, Object>[] listScheduledMessages() throws Exception { checkStarted(); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9e3953b3/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java ---------------------------------------------------------------------- diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index ccc0b89..d27fad2 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -2386,7 +2386,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { } AddressInfo defaultAddressInfo = new AddressInfo(addressName); - defaultAddressInfo.addRoutingType(ActiveMQDefaultConfiguration.getDefaultRoutingType()); + defaultAddressInfo.addRoutingType(routingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : routingType); AddressInfo info = postOffice.getAddressInfo(addressName); if (info == null) { http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9e3953b3/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlTest.java ---------------------------------------------------------------------- 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 142c3d5..1073f67 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 @@ -37,6 +37,7 @@ import org.apache.activemq.artemis.api.core.client.ClientSession; import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.ServerLocator; import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl; +import org.apache.activemq.artemis.api.core.management.AddressControl; import org.apache.activemq.artemis.api.core.management.AddressSettingsInfo; import org.apache.activemq.artemis.api.core.management.BridgeControl; import org.apache.activemq.artemis.api.core.management.DivertControl; @@ -52,6 +53,7 @@ import org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants; import org.apache.activemq.artemis.core.security.Role; import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ActiveMQServers; +import org.apache.activemq.artemis.core.server.RoutingType; import org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy; import org.apache.activemq.artemis.core.transaction.impl.XidImpl; import org.apache.activemq.artemis.jlibaio.LibaioContext; @@ -252,6 +254,41 @@ public class ActiveMQServerControlTest extends ManagementTestBase { } @Test + public void testCreateAndDestroyQueue_4() throws Exception { + SimpleString address = RandomUtil.randomSimpleString(); + SimpleString name = RandomUtil.randomSimpleString(); + boolean durable = RandomUtil.randomBoolean(); + boolean deleteOnNoConsumers = RandomUtil.randomBoolean(); + boolean autoCreateAddress = true; + int maxConsumers = RandomUtil.randomInt(); + + ActiveMQServerControl serverControl = createManagementControl(); + + checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name)); + + serverControl.createQueue(address.toString(), RoutingType.ANYCAST.toString(), name.toString(), null, durable, maxConsumers, deleteOnNoConsumers, autoCreateAddress); + + checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name)); + QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, mbeanServer); + Assert.assertEquals(address.toString(), queueControl.getAddress()); + Assert.assertEquals(name.toString(), queueControl.getName()); + Assert.assertNull(queueControl.getFilter()); + Assert.assertEquals(durable, queueControl.isDurable()); + Assert.assertEquals(deleteOnNoConsumers, queueControl.isDeleteOnNoConsumers()); + Assert.assertEquals(maxConsumers, queueControl.getMaxConsumers()); + Assert.assertEquals(false, queueControl.isTemporary()); + + checkResource(ObjectNameBuilder.DEFAULT.getAddressObjectName(address)); + AddressControl addressControl = ManagementControlHelper.createAddressControl(address, mbeanServer); + Assert.assertEquals(address.toString(), addressControl.getAddress()); + + serverControl.destroyQueue(name.toString(), true, true); + + checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name)); + checkNoResource(ObjectNameBuilder.DEFAULT.getAddressObjectName(address)); + } + + @Test public void testCreateAndDestroyQueueClosingConsumers() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); SimpleString name = RandomUtil.randomSimpleString(); http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9e3953b3/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/ActiveMQServerControlUsingCoreTest.java ---------------------------------------------------------------------- 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 7508a37..193c58c 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 @@ -22,7 +22,6 @@ import org.apache.activemq.artemis.api.core.ActiveMQAddressDoesNotExistException import org.apache.activemq.artemis.api.core.management.ActiveMQServerControl; import org.apache.activemq.artemis.api.core.management.Parameter; import org.apache.activemq.artemis.api.core.management.ResourceNames; -import org.apache.activemq.artemis.core.server.RoutingType; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTest { @@ -102,15 +101,15 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes } @Override - public void createQueue(@Parameter(name = "address", desc = "Address of the queue") String address, - @Parameter(name = "routingType", desc = "The routing type used for this address, 0=multicast, 1=anycast") RoutingType routingType, - @Parameter(name = "name", desc = "Name of the queue") String name, - @Parameter(name = "filter", desc = "Filter of the queue") String filterStr, - @Parameter(name = "durable", desc = "Is the queue durable?") boolean durable, - @Parameter(name = "maxConsumers", desc = "The maximum number of consumers allowed on this queue at any one time") int maxConsumers, - @Parameter(name = "deleteOnNoConsumers", desc = "Delete this queue when the last consumer disconnects") boolean deleteOnNoConsumers, - @Parameter(name = "autoCreateAddress", desc = "Create an address with default values should a matching address not be found") boolean autoCreateAddress) throws Exception { - + public void createQueue(String address, + String routingType, + String name, + String filterStr, + boolean durable, + int maxConsumers, + boolean deleteOnNoConsumers, + boolean autoCreateAddress) throws Exception { + proxy.invokeOperation("createQueue", address, routingType, name, filterStr, durable, maxConsumers, deleteOnNoConsumers, autoCreateAddress); } @@ -157,9 +156,10 @@ public class ActiveMQServerControlUsingCoreTest extends ActiveMQServerControlTes } @Override - public void destroyQueue(@Parameter(name = "name", desc = "Name of the queue to destroy") String name, - @Parameter(name = "removeConsumers", desc = "Remove consumers of this queue") boolean removeConsumers, + public void destroyQueue(String name, + boolean removeConsumers, boolean autoDeleteAddress) throws Exception { + proxy.invokeOperation("destroyQueue", name, removeConsumers, autoDeleteAddress); } @Override http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9e3953b3/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/QueueControlUsingCoreTest.java ---------------------------------------------------------------------- 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 250289a..34a6e4f 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 @@ -82,6 +82,16 @@ public class QueueControlUsingCoreTest extends QueueControlTest { } @Override + public int getMaxConsumers() { + return (Integer) proxy.retrieveAttributeValue("maxConsumers"); + } + + @Override + public boolean isDeleteOnNoConsumers() { + return (Boolean) proxy.retrieveAttributeValue("deleteOnNoConsumers"); + } + + @Override public int getDeliveringCount() { return (Integer) proxy.retrieveAttributeValue("deliveringCount", Integer.class); }
