Skip to content

Commit

Permalink
https://jira.jboss.org/browse/HORNETQ-509 Diverts are listed in Addre…
Browse files Browse the repository at this point in the history
…ssControl.getQueueNames()

* list only QueueBindings in AddressControl.getQueueNames()
* add AddressControl.getBindingNames() to list *all* bindings
* tests
  • Loading branch information
jmesnil committed Sep 14, 2010
1 parent e0fb1f0 commit 7a88636
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/main/org/hornetq/api/core/management/AddressControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public interface AddressControl
*/
long getNumberOfBytesPerPage() throws Exception;

/**
* Returns the names of all bindings (both queues and diverts) bound to this address
*/
String[] getBindingNames() throws Exception;

// Operations ----------------------------------------------------

}
35 changes: 32 additions & 3 deletions src/main/org/hornetq/core/management/impl/AddressControlImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -86,13 +89,39 @@ public String[] getQueueNames() throws Exception
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@

package org.hornetq.tests.integration.management;

import static org.hornetq.tests.util.RandomUtil.randomString;

import java.util.HashSet;
import java.util.Set;

import junit.framework.Assert;

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;
Expand Down Expand Up @@ -96,6 +102,31 @@ public void testGetQueueNames() throws Exception

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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -100,6 +101,31 @@ public void testGetQueueNames() throws Exception

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
{
Expand Down

0 comments on commit 7a88636

Please sign in to comment.