activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject svn commit: r1179355 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/network/ test/java/org/apache/activemq/network/
Date Wed, 05 Oct 2011 18:10:09 GMT
Author: gtully
Date: Wed Oct  5 18:10:08 2011
New Revision: 1179355

URL: http://svn.apache.org/viewvc?rev=1179355&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3523 - NetworkConnector MBean unregistration can
fail with a transport disconnect - leaving dangling mbean, fix and test

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/MBeanNetworkListener.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/NetworkBridge.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/FailoverStaticNetworkTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java?rev=1179355&r1=1179354&r2=1179355&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/DemandForwardingBridgeSupport.java
Wed Oct  5 18:10:08 2011
@@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicLong;
 
+import javax.management.ObjectName;
 import org.apache.activemq.Service;
 import org.apache.activemq.advisory.AdvisorySupport;
 import org.apache.activemq.broker.BrokerService;
@@ -131,6 +132,7 @@ public abstract class DemandForwardingBr
     private final AtomicBoolean started = new AtomicBoolean();
     private TransportConnection duplexInitiatingConnection;
     private BrokerService brokerService = null;
+    private ObjectName mbeanObjectName;
 
     public DemandForwardingBridgeSupport(NetworkBridgeConfiguration configuration, Transport
localBroker, Transport remoteBroker) {
         this.configuration = configuration;
@@ -1289,4 +1291,12 @@ public abstract class DemandForwardingBr
     public void setBrokerService(BrokerService brokerService) {
         this.brokerService = brokerService;
     }
+
+    public void setMbeanObjectName(ObjectName objectName) {
+        this.mbeanObjectName = objectName;
+    }
+
+    public ObjectName getMbeanObjectName() {
+        return mbeanObjectName;
+    }
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/MBeanNetworkListener.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/MBeanNetworkListener.java?rev=1179355&r1=1179354&r2=1179355&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/MBeanNetworkListener.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/MBeanNetworkListener.java
Wed Oct  5 18:10:08 2011
@@ -57,6 +57,10 @@ public class MBeanNetworkListener implem
         try {
             ObjectName objectName = createNetworkBridgeObjectName(bridge);
             AnnotatedMBean.registerMBean(brokerService.getManagementContext(), view, objectName);
+            bridge.setMbeanObjectName(objectName);
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("registered: " + bridge + " as: " + objectName);
+            }
         } catch (Throwable e) {
             LOG.debug("Network bridge could not be registered in JMX: " + e.getMessage(),
e);
         }
@@ -68,8 +72,10 @@ public class MBeanNetworkListener implem
             return;
         }
         try {
-            ObjectName objectName = createNetworkBridgeObjectName(bridge);
-            brokerService.getManagementContext().unregisterMBean(objectName);
+            ObjectName objectName = bridge.getMbeanObjectName();
+            if (objectName != null) {
+                brokerService.getManagementContext().unregisterMBean(objectName);
+            }
         } catch (Throwable e) {
             LOG.debug("Network bridge could not be unregistered in JMX: " + e.getMessage(),
e);
         }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/NetworkBridge.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/NetworkBridge.java?rev=1179355&r1=1179354&r2=1179355&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/NetworkBridge.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/network/NetworkBridge.java
Wed Oct  5 18:10:08 2011
@@ -16,6 +16,7 @@
  */
 package org.apache.activemq.network;
 
+import javax.management.ObjectName;
 import org.apache.activemq.Service;
 
 
@@ -56,4 +57,8 @@ public interface NetworkBridge extends S
     long getEnqueueCounter();
 
     long getDequeueCounter();
+
+    void setMbeanObjectName(ObjectName objectName);
+
+    ObjectName getMbeanObjectName();
 }

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/FailoverStaticNetworkTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/FailoverStaticNetworkTest.java?rev=1179355&r1=1179354&r2=1179355&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/FailoverStaticNetworkTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/network/FailoverStaticNetworkTest.java
Wed Oct  5 18:10:08 2011
@@ -18,11 +18,14 @@ package org.apache.activemq.network;
 
 import java.net.URI;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.Vector;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import javax.jms.Connection;
@@ -30,6 +33,7 @@ import javax.jms.ConnectionFactory;
 import javax.jms.JMSException;
 import javax.jms.MessageConsumer;
 import javax.jms.Session;
+import javax.management.ObjectName;
 import javax.net.ssl.KeyManager;
 import javax.net.ssl.TrustManager;
 
@@ -66,7 +70,7 @@ public class FailoverStaticNetworkTest {
     protected BrokerService createBroker(String scheme, String listenPort, String[] networkToPorts,
                                          HashMap<String, String> networkProps) throws
Exception {
         BrokerService broker = new BrokerService();
-        broker.setUseJmx(false);
+        //broker.setUseJmx(false);
         broker.getManagementContext().setCreateConnector(false);
         broker.setSslContext(sslContext);
         broker.setDeleteAllMessagesOnStartup(true);
@@ -155,6 +159,10 @@ public class FailoverStaticNetworkTest {
         brokerB.start();
         doTestNetworkSendReceive();
 
+        // check mbean
+        Set<String> bridgeNames = getNetworkBridgeMBeanName(brokerB);
+        assertEquals("only one bridgeName: " + bridgeNames, 1, bridgeNames.size());
+
         LOG.info("stopping brokerA");
         brokerA.stop();
         brokerA.waitUntilStopped();
@@ -164,6 +172,21 @@ public class FailoverStaticNetworkTest {
         brokerA.start();
 
         doTestNetworkSendReceive();
+
+        Set<String> otherBridgeNames = getNetworkBridgeMBeanName(brokerB);
+        assertEquals("only one bridgeName: " + otherBridgeNames, 1, otherBridgeNames.size());
+
+        assertTrue("there was an addition", bridgeNames.addAll(otherBridgeNames));
+    }
+
+    private Set<String> getNetworkBridgeMBeanName(BrokerService brokerB) throws Exception
{
+        Set<String> names = new HashSet<String>();
+        for (ObjectName objectName : brokerB.getManagementContext().queryNames(null, null))
{
+            if ("NetworkBridge".equals(objectName.getKeyProperty("Type"))) {
+                names.add(objectName.getKeyProperty("Name"));
+            }
+        }
+        return names;
     }
 
     @Test



Mime
View raw message