activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r443534 - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/BrokerService.java test/java/org/apache/activemq/broker/BrokerServiceTest.java
Date Fri, 15 Sep 2006 00:31:47 GMT
Author: jlim
Date: Thu Sep 14 17:31:46 2006
New Revision: 443534

URL: http://svn.apache.org/viewvc?view=rev&rev=443534
Log:
fix for http://issues.apache.org/activemq/browse/AMQ-922

Added:
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/BrokerServiceTest.java
Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java?view=diff&rev=443534&r1=443533&r2=443534
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/BrokerService.java
Thu Sep 14 17:31:46 2006
@@ -186,6 +186,23 @@
         return connector;
     }
 
+
+    /**
+     * Stops and removes a transport connector from the broker.
+     * 
+     * @param connector
+     * @return true if the connector has been previously added to the broker
+     * @throws Exception
+     */
+    public boolean removeConnector(TransportConnector connector) throws Exception {     
  
+        boolean rc = transportConnectors.remove(connector);
+        if( rc ) {
+           unregisterConnectorMBean(connector);
+        }
+        return rc;
+        
+    }
+
     /**
      * Adds a new network connector using the given discovery address
      *
@@ -1015,20 +1032,52 @@
         }
     }
 
-    protected void registerConnectorMBean(TransportConnector connector, ObjectName objectName)
throws IOException, URISyntaxException {
+    protected TransportConnector registerConnectorMBean(TransportConnector connector) throws
IOException  {
         MBeanServer mbeanServer = getManagementContext().getMBeanServer();
         if (mbeanServer != null) {
-            ConnectorViewMBean view = new ConnectorView(connector);
+
             try {
+                ObjectName objectName = createConnectorObjectName(connector);
+                connector = connector.asManagedConnector(getManagementContext().getMBeanServer(),
objectName);
+                ConnectorViewMBean view = new ConnectorView(connector);            
                 mbeanServer.registerMBean(view, objectName);
                 registeredMBeanNames.add(objectName);
+                return connector;
             }
             catch (Throwable e) {
-                throw IOExceptionSupport.create("Broker could not be registered in JMX: "
+ e.getMessage(), e);
+                throw IOExceptionSupport.create("Transport Connector could not be registered
in JMX: " + e.getMessage(), e);
             }
         }
+        return connector;
+    }
+    
+    protected void unregisterConnectorMBean(TransportConnector connector) throws IOException
{
+        if (isUseJmx()) {
+	        MBeanServer mbeanServer = getManagementContext().getMBeanServer();
+	        if (mbeanServer != null) {
+	            try {
+	                ObjectName objectName = createConnectorObjectName(connector);
+	
+	                if( registeredMBeanNames.remove(objectName) ) {
+	                       mbeanServer.unregisterMBean(objectName);
+	                }
+	            }
+	            catch (Throwable e) {
+	                throw IOExceptionSupport.create("Transport Connector could not be registered
in JMX: " + e.getMessage(), e);
+	            }
+	        }
+        }
     }
 
+	private ObjectName createConnectorObjectName(TransportConnector connector) throws MalformedObjectNameException
{
+		return new ObjectName(
+		        managementContext.getJmxDomainName()+":"+
+		        "BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
+		        "Type=Connector,"+
+		        "ConnectorName="+JMXSupport.encodeObjectNamePart(connector.getName())
+		        );
+	}    
+
     protected void registerNetworkConnectorMBean(NetworkConnector connector) throws IOException
{
         MBeanServer mbeanServer = getManagementContext().getMBeanServer();
         if (mbeanServer != null) {
@@ -1039,7 +1088,7 @@
                 registeredMBeanNames.add(objectName);
             }
             catch (Throwable e) {
-                throw IOExceptionSupport.create("Broker could not be registered in JMX: "
+ e.getMessage(), e);
+                throw IOExceptionSupport.create("Network Connector could not be registered
in JMX: " + e.getMessage(), e);
             }
         }
     }
@@ -1056,13 +1105,12 @@
             if (mbeanServer != null) {
                 try {
                     ObjectName objectName = createNetworkConnectorObjectName(connector);
-                    if (registeredMBeanNames.contains(objectName)) {
-                        registeredMBeanNames.remove(objectName);
+                    if (registeredMBeanNames.remove(objectName)) {
                         mbeanServer.unregisterMBean(objectName);
                     }
                 }
                 catch (Exception e) {
-                    log.error("Failed to unregister MBean: " + e, e);
+                    log.error("Network Connector could not be unregistered from JMX: " +
e, e);
                 }
             }
         }
@@ -1425,16 +1473,7 @@
         }
         
         if (isUseJmx()) {
-            
-            ObjectName objectName = new ObjectName(
-                    managementContext.getJmxDomainName()+":"+
-                    "BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
-                    "Type=Connector,"+
-                    "ConnectorName="+JMXSupport.encodeObjectNamePart(connector.getName())
-                    );
-            
-            connector = connector.asManagedConnector(getManagementContext().getMBeanServer(),
objectName);
-            registerConnectorMBean(connector, objectName);
+            connector = registerConnectorMBean(connector);
         }        
         connector.start();
     }

Added: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/BrokerServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/BrokerServiceTest.java?view=auto&rev=443534
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/BrokerServiceTest.java
(added)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/broker/BrokerServiceTest.java
Thu Sep 14 17:31:46 2006
@@ -0,0 +1,76 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.broker;
+
+import org.apache.activemq.network.NetworkConnector;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the BrokerService class 
+ * @author chirino
+ */
+public class BrokerServiceTest extends TestCase {
+
+	public void testAddRemoveTransportsWithJMX() throws Exception {
+		BrokerService service = new BrokerService();
+		service.setUseJmx(true);
+		service.setPersistent(false);
+		TransportConnector connector = service.addConnector("tcp://localhost:0");
+		service.start();
+		
+		service.removeConnector(connector);
+		connector.stop();
+		service.stop();
+	}
+	
+	public void testAddRemoveTransportsWithoutJMX() throws Exception {
+		BrokerService service = new BrokerService();
+		service.setPersistent(false);
+		service.setUseJmx(false);
+		TransportConnector connector = service.addConnector("tcp://localhost:0");
+		service.start();
+		
+		service.removeConnector(connector);
+		connector.stop();
+		service.stop();
+	}
+	
+	public void testAddRemoveNetworkWithJMX() throws Exception {
+		BrokerService service = new BrokerService();
+		service.setPersistent(false);
+		service.setUseJmx(true);
+		NetworkConnector connector = service.addNetworkConnector("multicast://default");
+		service.start();
+		
+		service.removeNetworkConnector(connector);
+		connector.stop();
+		service.stop();
+	}
+	
+	public void testAddRemoveNetworkWithoutJMX() throws Exception {
+		BrokerService service = new BrokerService();
+		service.setPersistent(false);
+		service.setUseJmx(false);
+		NetworkConnector connector = service.addNetworkConnector("multicast://default");
+		service.start();
+		
+		service.removeNetworkConnector(connector);
+		connector.stop();
+		service.stop();
+	}
+}



Mime
View raw message