From c2ad0c32512e5265fa5482a0e49aa13f359acb8f Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Wed, 24 Feb 2016 17:25:01 -0500 Subject: [PATCH] AMQ-6183 Add isDispatchSync to the subscription view and deprecate the meaningless one in the producer view --- .../activemq/broker/jmx/ProducerView.java | 5 +- .../broker/jmx/ProducerViewMBean.java | 2 + .../activemq/broker/jmx/SubscriptionView.java | 9 ++++ .../broker/jmx/SubscriptionViewMBean.java | 6 +++ .../apache/activemq/broker/jmx/MBeanTest.java | 49 ++++++++++++++++++- 5 files changed, 67 insertions(+), 4 deletions(-) diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ProducerView.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ProducerView.java index e211b753be..788616cab3 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ProducerView.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ProducerView.java @@ -124,16 +124,15 @@ public class ProducerView implements ProducerViewMBean { } @Override + @Deprecated public boolean isDispatchAsync() { - if (info != null) { - return info.isDispatchAsync(); - } return false; } /** * @return pretty print */ + @Override public String toString() { return "ProducerView: " + getClientId() + ":" + getConnectionId(); } diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ProducerViewMBean.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ProducerViewMBean.java index cdf375451f..b9d662aa6d 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ProducerViewMBean.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/ProducerViewMBean.java @@ -73,8 +73,10 @@ public interface ProducerViewMBean { int getProducerWindowSize(); /** + * @deprecated This value is no longer used for producers. * @return if the Producer is configured for Async dispatch */ + @Deprecated @MBeanInfo("Is the producer configured for Async Dispatch") boolean isDispatchAsync(); diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/SubscriptionView.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/SubscriptionView.java index 85f1f14e42..663220e7a3 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/SubscriptionView.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/SubscriptionView.java @@ -266,6 +266,15 @@ public class SubscriptionView implements SubscriptionViewMBean { return info != null ? info.isNoLocal() : false; } + /** + * @return whether or not the subscriber is configured for async dispatch + */ + @Override + public boolean isDispatchAsync() { + ConsumerInfo info = getConsumerInfo(); + return info != null ? info.isDispatchAsync() : false; + } + /** * @return the maximum number of pending messages allowed in addition to the * prefetch size. If enabled to a non-zero value then this will diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/SubscriptionViewMBean.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/SubscriptionViewMBean.java index f1dbf26faf..189bebbb3f 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/SubscriptionViewMBean.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/SubscriptionViewMBean.java @@ -160,6 +160,12 @@ public interface SubscriptionViewMBean { @MBeanInfo("The subscription ignores local messages.") boolean isNoLocal(); + /** + * @return if the Consumer is configured for Async dispatch + */ + @MBeanInfo("Is the consumer configured for Async Dispatch") + boolean isDispatchAsync(); + /** * @return the maximum number of pending messages allowed in addition to the * prefetch size. If enabled to a non-zero value then this will diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java index b2d690e7f4..e03cb4626e 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java @@ -1790,4 +1790,51 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { assertEquals(1, subscriberView.getDequeueCounter()); } } -} + + public void testSubscriptionViewProperties() throws Exception { + connection = createConnection(); + connection.start(); + + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + + Topic topic1 = session.createTopic("test.topic1?consumer.dispatchAsync=false&consumer.retroactive=true"); + Topic topic2 = session.createTopic("test.topic2?consumer.dispatchAsync=true&consumer.retroactive=false&consumer.exclusive=true"); + MessageConsumer consumer1 = session.createConsumer(topic1); + MessageConsumer consumer2 = session.createConsumer(topic2); + + assertNotNull(consumer1); + assertNotNull(consumer2); + + ObjectName topicObjName = assertRegisteredObjectName( + domain + ":type=Broker,brokerName=localhost,destinationType=Topic,destinationName=" + topic1.getTopicName()); + final TopicViewMBean topic1View = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, topicObjName, TopicViewMBean.class, true); + ArrayList subscriberViews = new ArrayList(); + for (ObjectName name : topic1View.getSubscriptions()) { + subscriberViews.add(MBeanServerInvocationHandler.newProxyInstance(mbeanServer, name, SubscriptionViewMBean.class, true)); + } + + assertEquals(1, subscriberViews.size()); + + SubscriptionViewMBean subscription = subscriberViews.get(0); + + assertFalse(subscription.isDispatchAsync()); + assertTrue(subscription.isRetroactive()); + assertFalse(subscription.isExclusive()); + + topicObjName = assertRegisteredObjectName( + domain + ":type=Broker,brokerName=localhost,destinationType=Topic,destinationName=" + topic2.getTopicName()); + final TopicViewMBean topic2View = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, topicObjName, TopicViewMBean.class, true); + subscriberViews = new ArrayList(); + for (ObjectName name : topic2View.getSubscriptions()) { + subscriberViews.add(MBeanServerInvocationHandler.newProxyInstance(mbeanServer, name, SubscriptionViewMBean.class, true)); + } + + assertEquals(1, subscriberViews.size()); + + subscription = subscriberViews.get(0); + + assertTrue(subscription.isDispatchAsync()); + assertFalse(subscription.isRetroactive()); + assertTrue(subscription.isExclusive()); + } +} \ No newline at end of file