diff options
author | Marnie McCormack <marnie@apache.org> | 2010-07-05 20:00:54 +0000 |
---|---|---|
committer | Marnie McCormack <marnie@apache.org> | 2010-07-05 20:00:54 +0000 |
commit | 3c57e4b18865b717404ea41efbd4b80516a92a33 (patch) | |
tree | 4ca087388cc0ee54ef99961f48b4340c08d05feb /java | |
parent | 0f7f0aa39aabb79d49f0fb7294fa233d3f8d5981 (diff) | |
download | qpid-python-3c57e4b18865b717404ea41efbd4b80516a92a33.tar.gz |
QPID-2700 Patch for ability to remove bindings from exchanges and additional tests for direct and topic exchange add/remove logic from Andrew Kennedy
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@960678 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
6 files changed, 141 insertions, 6 deletions
diff --git a/java/broker-plugins/extras/src/main/java/org/apache/qpid/extras/exchanges/diagnostic/DiagnosticExchange.java b/java/broker-plugins/extras/src/main/java/org/apache/qpid/extras/exchanges/diagnostic/DiagnosticExchange.java index 4ab8a072b1..5d2c0dd5b2 100644 --- a/java/broker-plugins/extras/src/main/java/org/apache/qpid/extras/exchanges/diagnostic/DiagnosticExchange.java +++ b/java/broker-plugins/extras/src/main/java/org/apache/qpid/extras/exchanges/diagnostic/DiagnosticExchange.java @@ -102,6 +102,17 @@ public class DiagnosticExchange extends AbstractExchange { // No Op } + + /** + * This exchange type doesn't support queues. + * + * @see #createNewBinding(String, String) + */ + @Override + public void removeBinding(String queueName, String binding) throws JMException + { + // No Op + } } diff --git a/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchangeMBean.java b/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchangeMBean.java index 0dca91b7be..c69d499674 100644 --- a/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchangeMBean.java +++ b/java/broker/src/main/java/org/apache/qpid/server/exchange/AbstractExchangeMBean.java @@ -20,6 +20,9 @@ */ package org.apache.qpid.server.exchange; +import java.util.Collections; +import java.util.Map; + import org.apache.qpid.AMQException; import org.apache.qpid.AMQSecurityException; import org.apache.qpid.server.management.AMQManagedObject; @@ -28,6 +31,7 @@ import org.apache.qpid.server.management.ManagedObjectRegistry; import org.apache.qpid.server.registry.ApplicationRegistry; import org.apache.qpid.server.virtualhost.VirtualHost; import org.apache.qpid.server.queue.AMQQueue; +import org.apache.qpid.server.binding.BindingFactory; import org.apache.qpid.server.logging.actors.CurrentActor; import org.apache.qpid.server.logging.actors.ManagementActor; import org.apache.qpid.management.common.mbeans.ManagedExchange; @@ -147,4 +151,31 @@ public abstract class AbstractExchangeMBean<T extends AbstractExchange> extends } CurrentActor.remove(); } + + /** + * Removes a queue binding from the exchange. + * + * @see BindingFactory#removeBinding(String, AMQQueue, Exchange, Map) + */ + public void removeBinding(String queueName, String binding) throws JMException + { + VirtualHost vhost = getExchange().getVirtualHost(); + AMQQueue queue = vhost.getQueueRegistry().getQueue(new AMQShortString(queueName)); + if (queue == null) + { + throw new JMException("Queue \"" + queueName + "\" is not registered with the exchange."); + } + + CurrentActor.set(new ManagementActor(_logActor.getRootMessageLogger())); + try + { + vhost.getBindingFactory().removeBinding(binding, queue, _exchange, Collections.<String, Object>emptyMap()); + } + catch (AMQException ex) + { + JMException jme = new JMException(ex.toString()); + throw new MBeanException(jme, "Error removing binding " + binding); + } + CurrentActor.remove(); + } } diff --git a/java/broker/src/test/java/org/apache/qpid/server/exchange/ExchangeMBeanTest.java b/java/broker/src/test/java/org/apache/qpid/server/exchange/ExchangeMBeanTest.java index e3e736509e..b51c88680e 100644 --- a/java/broker/src/test/java/org/apache/qpid/server/exchange/ExchangeMBeanTest.java +++ b/java/broker/src/test/java/org/apache/qpid/server/exchange/ExchangeMBeanTest.java @@ -36,6 +36,7 @@ import org.apache.qpid.framing.AMQShortString; import javax.management.openmbean.TabularData; import java.util.ArrayList; +import java.util.Collections; /** * Unit test class for testing different Exchange MBean operations @@ -126,6 +127,84 @@ public class ExchangeMBeanTest extends InternalBrokerBaseCase assertTrue(!mbean.isDurable()); assertTrue(mbean.isAutoDelete()); } + + /** + * Test adding bindings and removing them from the topic exchange via JMX. + * <p> + * QPID-2700 + */ + public void testTopicBindings() throws Exception + { + int bindings = _queue.getBindingCount(); + + Exchange exchange = _queue.getVirtualHost().getExchangeRegistry().getExchange(new AMQShortString("amq.topic")); + ManagedExchange mbean = (ManagedExchange) ((AbstractExchange) exchange).getManagedObject(); + + mbean.createNewBinding(_queue.getName(), "robot.#"); + mbean.createNewBinding(_queue.getName(), "#.kitten"); + + assertEquals("Should have added two bindings", bindings + 2, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "robot.#"); + + assertEquals("Should have one extra binding", bindings + 1, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "#.kitten"); + + assertEquals("Should have original number of binding", bindings, _queue.getBindingCount()); + } + + /** + * Test adding bindings and removing them from the default exchange via JMX. + * <p> + * QPID-2700 + */ + public void testDefaultBindings() throws Exception + { + int bindings = _queue.getBindingCount(); + + Exchange exchange = _queue.getVirtualHost().getExchangeRegistry().getDefaultExchange(); + ManagedExchange mbean = (ManagedExchange) ((AbstractExchange) exchange).getManagedObject(); + + mbean.createNewBinding(_queue.getName(), "robot"); + mbean.createNewBinding(_queue.getName(), "kitten"); + + assertEquals("Should have added two bindings", bindings + 2, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "robot"); + + assertEquals("Should have one extra binding", bindings + 1, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "kitten"); + + assertEquals("Should have original number of binding", bindings, _queue.getBindingCount()); + } + + /** + * Test adding bindings and removing them from the topic exchange via JMX. + * <p> + * QPID-2700 + */ + public void testTopicBindings() throws Exception + { + int bindings = _queue.getBindingCount(); + + Exchange exchange = _queue.getVirtualHost().getExchangeRegistry().getExchange(new AMQShortString("amq.topic")); + ManagedExchange mbean = (ManagedExchange) ((AbstractExchange) exchange).getManagedObject(); + + mbean.createNewBinding(_queue.getName(), "robot.#"); + mbean.createNewBinding(_queue.getName(), "#.kitten"); + + assertEquals("Should have added two bindings", bindings + 2, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "robot.#"); + + assertEquals("Should have one extra binding", bindings + 1, _queue.getBindingCount()); + + mbean.removeBinding(_queue.getName(), "#.kitten"); + + assertEquals("Should have original number of binding", bindings, _queue.getBindingCount()); + } @Override public void setUp() throws Exception diff --git a/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedExchange.java b/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedExchange.java index 1ed09f4456..50acc264e6 100644 --- a/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedExchange.java +++ b/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedExchange.java @@ -32,9 +32,8 @@ import org.apache.qpid.management.common.mbeans.annotations.MBeanOperationParame /** * The management interface exposed to allow management of an Exchange. - * @author Robert J. Greig - * @author Bhupendra Bhardwaj - * @version 0.1 + * + * @version 1.8 */ public interface ManagedExchange { @@ -105,5 +104,20 @@ public interface ManagedExchange void createNewBinding(@MBeanOperationParameter(name= ManagedQueue.TYPE, description="Queue name") String queueName, @MBeanOperationParameter(name="Binding", description="New binding")String binding) throws JMException; - + + /** + * Removes an exchange binding from a queue. + * + * @param exchangeName the Exchange name + * @param routingKey the routing key + * @throws IOException + * @throws JMException + * @since 1.8 + */ + @MBeanOperation(name="removeBinding", + description="Removes an exchange binding from the Queue", + impact= MBeanOperationInfo.ACTION) + void removeBinding(@MBeanOperationParameter(name= ManagedQueue.TYPE, description="Queue name") String queueName, + @MBeanOperationParameter(name="Binding", description="New binding")String binding) + throws IOException, JMException; } diff --git a/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ServerInformation.java b/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ServerInformation.java index c6f7829e59..f61c41dea9 100644 --- a/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ServerInformation.java +++ b/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ServerInformation.java @@ -42,7 +42,7 @@ public interface ServerInformation * Qpid JMX API 1.1 can be assumed. */ int QPID_JMX_API_MAJOR_VERSION = 1; - int QPID_JMX_API_MINOR_VERSION = 7; + int QPID_JMX_API_MINOR_VERSION = 8; /** diff --git a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ApplicationRegistry.java b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ApplicationRegistry.java index 13485df718..0d9f2ff678 100644 --- a/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ApplicationRegistry.java +++ b/java/management/eclipse-plugin/src/main/java/org/apache/qpid/management/ui/ApplicationRegistry.java @@ -47,7 +47,7 @@ public abstract class ApplicationRegistry //max supported broker management interface supported by this release of the management console public static final int SUPPORTED_QPID_JMX_API_MAJOR_VERSION = 1; - public static final int SUPPORTED_QPID_JMX_API_MINOR_VERSION = 7; + public static final int SUPPORTED_QPID_JMX_API_MINOR_VERSION = 8; public static final String DATA_DIR = System.getProperty("user.home") + File.separator + ".qpidmc"; |