Author: jmesnil
Date: 2010-09-14 04:20:09 -0400 (Tue, 14 Sep 2010)
New Revision: 9683
Modified:
trunk/src/main/org/hornetq/api/core/management/AddressControl.java
trunk/src/main/org/hornetq/core/management/impl/AddressControlImpl.java
trunk/tests/src/org/hornetq/tests/integration/management/AddressControlTest.java
trunk/tests/src/org/hornetq/tests/integration/management/AddressControlUsingCoreTest.java
Log:
https://jira.jboss.org/browse/HORNETQ-509 Diverts are listed in
AddressControl.getQueueNames()
* list only QueueBindings in AddressControl.getQueueNames()
* add AddressControl.getBindingNames() to list *all* bindings
* tests
Modified: trunk/src/main/org/hornetq/api/core/management/AddressControl.java
===================================================================
--- trunk/src/main/org/hornetq/api/core/management/AddressControl.java 2010-09-13 23:36:57
UTC (rev 9682)
+++ trunk/src/main/org/hornetq/api/core/management/AddressControl.java 2010-09-14 08:20:09
UTC (rev 9683)
@@ -56,6 +56,11 @@
*/
long getNumberOfBytesPerPage() throws Exception;
+ /**
+ * Returns the names of all bindings (both queues and diverts) bound to this address
+ */
+ String[] getBindingNames() throws Exception;
+
// Operations ----------------------------------------------------
}
Modified: trunk/src/main/org/hornetq/core/management/impl/AddressControlImpl.java
===================================================================
--- trunk/src/main/org/hornetq/core/management/impl/AddressControlImpl.java 2010-09-13
23:36:57 UTC (rev 9682)
+++ trunk/src/main/org/hornetq/core/management/impl/AddressControlImpl.java 2010-09-14
08:20:09 UTC (rev 9683)
@@ -13,6 +13,8 @@
package org.hornetq.core.management.impl;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import javax.management.MBeanOperationInfo;
@@ -25,6 +27,7 @@
import org.hornetq.core.postoffice.Binding;
import org.hornetq.core.postoffice.Bindings;
import org.hornetq.core.postoffice.PostOffice;
+import org.hornetq.core.postoffice.QueueBinding;
import org.hornetq.core.security.CheckType;
import org.hornetq.core.security.Role;
import org.hornetq.core.settings.HierarchicalRepository;
@@ -86,13 +89,39 @@
try
{
Bindings bindings = postOffice.getBindingsForAddress(address);
- String[] queueNames = new String[bindings.getBindings().size()];
+ List<String> queueNames = new ArrayList<String>();
+ for (Binding binding : bindings.getBindings())
+ {
+ if (binding instanceof QueueBinding)
+ {
+ queueNames.add(binding.getUniqueName().toString());
+ }
+ }
+ return (String[])queueNames.toArray(new String[queueNames.size()]);
+ }
+ catch (Throwable t)
+ {
+ throw new IllegalStateException(t.getMessage());
+ }
+ finally
+ {
+ blockOnIO();
+ }
+ }
+
+ public String[] getBindingNames() throws Exception
+ {
+ clearIO();
+ try
+ {
+ Bindings bindings = postOffice.getBindingsForAddress(address);
+ String[] bindingNames = new String[bindings.getBindings().size()];
int i = 0;
for (Binding binding : bindings.getBindings())
{
- queueNames[i++] = binding.getUniqueName().toString();
+ bindingNames[i++] = binding.getUniqueName().toString();
}
- return queueNames;
+ return bindingNames;
}
catch (Throwable t)
{
Modified:
trunk/tests/src/org/hornetq/tests/integration/management/AddressControlTest.java
===================================================================
---
trunk/tests/src/org/hornetq/tests/integration/management/AddressControlTest.java 2010-09-13
23:36:57 UTC (rev 9682)
+++
trunk/tests/src/org/hornetq/tests/integration/management/AddressControlTest.java 2010-09-14
08:20:09 UTC (rev 9683)
@@ -13,6 +13,8 @@
package org.hornetq.tests.integration.management;
+import static org.hornetq.tests.util.RandomUtil.randomString;
+
import java.util.HashSet;
import java.util.Set;
@@ -20,7 +22,11 @@
import org.hornetq.api.core.SimpleString;
import org.hornetq.api.core.TransportConfiguration;
-import org.hornetq.api.core.client.*;
+import org.hornetq.api.core.client.ClientMessage;
+import org.hornetq.api.core.client.ClientProducer;
+import org.hornetq.api.core.client.ClientSession;
+import org.hornetq.api.core.client.ClientSessionFactory;
+import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.core.management.AddressControl;
import org.hornetq.api.core.management.RoleInfo;
import org.hornetq.core.config.Configuration;
@@ -96,7 +102,32 @@
session.deleteQueue(anotherQueue);
}
+
+ public void testGetBindingNames() throws Exception
+ {
+ SimpleString address = RandomUtil.randomSimpleString();
+ SimpleString queue = RandomUtil.randomSimpleString();
+ String divertName = RandomUtil.randomString();
+
+ session.createQueue(address, queue, false);
+ AddressControl addressControl = createManagementControl(address);
+ String[] bindingNames = addressControl.getBindingNames();
+ assertEquals(1, bindingNames.length);
+ assertEquals(queue.toString(), bindingNames[0]);
+
+ server.getHornetQServerControl().createDivert(divertName, randomString(),
address.toString(), RandomUtil.randomString(), false, null, null);
+
+ bindingNames = addressControl.getBindingNames();
+ Assert.assertEquals(2, bindingNames.length);
+
+ session.deleteQueue(queue);
+
+ bindingNames = addressControl.getBindingNames();
+ assertEquals(1, bindingNames.length);
+ assertEquals(divertName.toString(), bindingNames[0]);
+ }
+
public void testGetRoles() throws Exception
{
SimpleString address = RandomUtil.randomSimpleString();
Modified:
trunk/tests/src/org/hornetq/tests/integration/management/AddressControlUsingCoreTest.java
===================================================================
---
trunk/tests/src/org/hornetq/tests/integration/management/AddressControlUsingCoreTest.java 2010-09-13
23:36:57 UTC (rev 9682)
+++
trunk/tests/src/org/hornetq/tests/integration/management/AddressControlUsingCoreTest.java 2010-09-14
08:20:09 UTC (rev 9683)
@@ -13,6 +13,8 @@
package org.hornetq.tests.integration.management;
+import static org.hornetq.tests.util.RandomUtil.randomString;
+
import java.util.HashSet;
import java.util.Set;
@@ -25,7 +27,6 @@
import org.hornetq.api.core.client.HornetQClient;
import org.hornetq.api.core.management.AddressControl;
import org.hornetq.api.core.management.ResourceNames;
-import org.hornetq.core.client.impl.ClientSessionFactoryImpl;
import org.hornetq.core.config.Configuration;
import org.hornetq.core.config.impl.ConfigurationImpl;
import org.hornetq.core.remoting.impl.invm.InVMAcceptorFactory;
@@ -100,7 +101,32 @@
session.deleteQueue(anotherQueue);
}
+
+ public void testGetBindingNames() throws Exception
+ {
+ SimpleString address = RandomUtil.randomSimpleString();
+ SimpleString queue = RandomUtil.randomSimpleString();
+ String divertName = RandomUtil.randomString();
+
+ session.createQueue(address, queue, false);
+ CoreMessagingProxy proxy = createProxy(address);
+ Object[] bindingNames =
(Object[])proxy.retrieveAttributeValue("bindingNames");
+ assertEquals(1, bindingNames.length);
+ assertEquals(queue.toString(), bindingNames[0]);
+
+ server.getHornetQServerControl().createDivert(divertName, randomString(),
address.toString(), RandomUtil.randomString(), false, null, null);
+
+ bindingNames = (Object[])proxy.retrieveAttributeValue("bindingNames");
+ assertEquals(2, bindingNames.length);
+
+ session.deleteQueue(queue);
+
+ bindingNames = (Object[])proxy.retrieveAttributeValue("bindingNames");
+ assertEquals(1, bindingNames.length);
+ assertEquals(divertName.toString(), bindingNames[0]);
+ }
+
public void testGetRoles() throws Exception
{
SimpleString address = RandomUtil.randomSimpleString();