mirror of https://github.com/apache/activemq.git
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@443534 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
220ad62a50
commit
c9b89056f7
|
@ -186,6 +186,23 @@ public class BrokerService implements Service, Serializable {
|
|||
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,19 +1032,51 @@ public class BrokerService implements Service, Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
@ -1039,7 +1088,7 @@ public class BrokerService implements Service, Serializable {
|
|||
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 @@ public class BrokerService implements Service, Serializable {
|
|||
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 @@ public class BrokerService implements Service, Serializable {
|
|||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue