activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r1296711 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/jmx/SubscriptionView.java main/java/org/apache/activemq/broker/jmx/SubscriptionViewMBean.java test/java/org/apache/activemq/broker/jmx/MBeanTest.java
Date Sat, 03 Mar 2012 21:51:39 GMT
Author: tabish
Date: Sat Mar  3 21:51:38 2012
New Revision: 1296711

URL: http://svn.apache.org/viewvc?rev=1296711&view=rev
Log:
fix for: https://issues.apache.org/jira/browse/AMQ-1907

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionView.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionViewMBean.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionView.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionView.java?rev=1296711&r1=1296710&r2=1296711&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionView.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionView.java
Sat Mar  3 21:51:38 2012
@@ -16,14 +16,22 @@
  */
 package org.apache.activemq.broker.jmx;
 
+import java.io.IOException;
+import java.util.Set;
+
 import javax.jms.InvalidSelectorException;
+import javax.management.ObjectName;
 
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.broker.ConnectionContext;
 import org.apache.activemq.broker.region.Subscription;
 import org.apache.activemq.command.ActiveMQDestination;
 import org.apache.activemq.command.ActiveMQQueue;
 import org.apache.activemq.command.ActiveMQTopic;
 import org.apache.activemq.command.ConsumerInfo;
 import org.apache.activemq.filter.DestinationFilter;
+import org.apache.activemq.util.IOExceptionSupport;
+import org.apache.activemq.util.JMXSupport;
 
 /**
  *
@@ -53,6 +61,44 @@ public class SubscriptionView implements
     }
 
     /**
+     * @returns the ObjectName of the Connection that created this subscription
+     */
+    public ObjectName getConnection() {
+        ObjectName result = null;
+
+        if (clientId != null && subscription != null) {
+            ConnectionContext ctx = subscription.getContext();
+            if (ctx != null && ctx.getBroker() != null && ctx.getBroker().getBrokerService()
!= null) {
+                BrokerService service = ctx.getBroker().getBrokerService();
+                ManagementContext managementCtx = service.getManagementContext();
+                if (managementCtx != null) {
+
+                    try {
+                        ObjectName query = createConnectionQueury(managementCtx, service.getBrokerName());
+                        Set<ObjectName> names = managementCtx.queryNames(query, null);
+                        if (names.size() == 1) {
+                            result = names.iterator().next();
+                        }
+                    } catch (Exception e) {
+                    }
+                }
+            }
+        }
+        return result;
+    }
+
+    private ObjectName createConnectionQueury(ManagementContext ctx, String brokerName) throws
IOException {
+        try {
+            return new ObjectName(ctx.getJmxDomainName() + ":" + "BrokerName="
+                                  + JMXSupport.encodeObjectNamePart(brokerName) + ","
+                                  + "Type=Connection," + "ConnectorName=*,"
+                                  + "Connection=" + JMXSupport.encodeObjectNamePart(clientId));
+        } catch (Throwable e) {
+            throw IOExceptionSupport.create(e);
+        }
+    }
+
+    /**
      * @return the id of the Connection the Subscription is on
      */
     public String getConnectionId() {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionViewMBean.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionViewMBean.java?rev=1296711&r1=1296710&r2=1296711&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionViewMBean.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/jmx/SubscriptionViewMBean.java
Sat Mar  3 21:51:38 2012
@@ -17,6 +17,7 @@
 package org.apache.activemq.broker.jmx;
 
 import javax.jms.InvalidSelectorException;
+import javax.management.ObjectName;
 
 /**
  *
@@ -213,4 +214,14 @@ public interface SubscriptionViewMBean {
      */
     @MBeanInfo("User Name used to authorize creation of this Subscription")
     String getUserName();
+
+    /**
+     * Returns the ObjectName of the Connection that created this Subscription.
+     * This value can be null if for instance this is an off-line durable subscription.
+     *
+     * @return the name of the Connection that created this Subscription.
+     */
+    @MBeanInfo("ObjectName of the Connection that created this Subscription")
+    ObjectName getConnection();
+
 }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java?rev=1296711&r1=1296710&r2=1296711&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java
Sat Mar  3 21:51:38 2012
@@ -894,6 +894,37 @@ public class MBeanTest extends EmbeddedB
         assertTrue("dest has some memory usage", queue.getMemoryPercentUsage() > 0);
     }
 
+    public void testSubscriptionViewToConnectionMBean() throws Exception {
+
+        connection = connectionFactory.createConnection("admin", "admin");
+        connection.setClientID("MBeanTest");
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        Destination queue = session.createQueue(getDestinationString() + ".Queue");
+        @SuppressWarnings("unused")
+        MessageConsumer queueConsumer = session.createConsumer(queue);
+
+        ObjectName brokerName = assertRegisteredObjectName(domain + ":Type=Broker,BrokerName=localhost");
+        BrokerViewMBean broker = (BrokerViewMBean)MBeanServerInvocationHandler.newProxyInstance(mbeanServer,
brokerName, BrokerViewMBean.class, true);
+
+        Thread.sleep(100);
+
+        assertTrue(broker.getQueueSubscribers().length == 1);
+
+        ObjectName subscriptionName = broker.getQueueSubscribers()[0];
+
+        SubscriptionViewMBean subscriberView =
+            (SubscriptionViewMBean)MBeanServerInvocationHandler.newProxyInstance(
+                    mbeanServer, subscriptionName, SubscriptionViewMBean.class, true);
+        assertNotNull(subscriberView);
+
+        ObjectName connectionName = subscriberView.getConnection();
+        assertNotNull(connectionName);
+        ConnectionViewMBean connectionView =
+            (ConnectionViewMBean)MBeanServerInvocationHandler.newProxyInstance(
+                    mbeanServer, connectionName, ConnectionViewMBean.class, true);
+        assertNotNull(connectionView);
+    }
+
     public void testUserNamePopulated() throws Exception {
         doTestUserNameInMBeans(true);
     }



Mime
View raw message