Fix for https://issues.apache.org/jira/browse/AMQ-4823 NetworkConnector not registered in JMX when created from Broker View + unit tests

This commit is contained in:
Christian Posta 2013-10-24 10:36:00 -07:00
parent ec97d0aad0
commit c2eb4863a8
3 changed files with 69 additions and 1 deletions

View File

@ -2061,7 +2061,7 @@ public class BrokerService implements Service {
return BrokerMBeanSupport.createConnectorName(getBrokerObjectName(), "clientConnectors", connector.getName());
}
protected void registerNetworkConnectorMBean(NetworkConnector connector) throws IOException {
public void registerNetworkConnectorMBean(NetworkConnector connector) throws IOException {
NetworkConnectorViewMBean view = new NetworkConnectorView(connector);
try {
ObjectName objectName = createNetworkConnectorObjectName(connector);

View File

@ -352,6 +352,7 @@ public class BrokerView implements BrokerViewMBean {
if (connector == null) {
throw new NoSuchElementException("Not connector matched the given name: " + discoveryAddress);
}
brokerService.registerNetworkConnectorMBean(connector);
connector.start();
return connector.getName();
}

View File

@ -0,0 +1,67 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.jmx;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.NetworkConnectorViewMBean;
import org.junit.Test;
import javax.management.ObjectName;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* This test shows that when we create a network connector via JMX,
* the NC/bridge shows up in the MBean Server
*
* @author <a href="http://www.christianposta.com/blog">Christian Posta</a>
*/
public class JmxCreateNCTest {
private static final String BROKER_NAME = "jmx-broker";
@Test
public void testBridgeRegistration() throws Exception {
BrokerService broker = new BrokerService();
broker.setBrokerName(BROKER_NAME);
broker.setUseJmx(true); // explicitly set this so no funny issues
broker.start();
broker.waitUntilStarted();
// now create network connector over JMX
ObjectName brokerObjectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + BROKER_NAME);
BrokerViewMBean proxy = (BrokerViewMBean) broker.getManagementContext().newProxyInstance(brokerObjectName,
BrokerViewMBean.class, true);
assertNotNull("We could not retrieve the broker from JMX", proxy);
// let's add the NC
String connectoName = proxy.addNetworkConnector("static:(tcp://localhost:61617)");
assertEquals("NC", connectoName);
// Make sure we can retrieve the NC through JMX
ObjectName networkConnectorObjectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + BROKER_NAME +
",connector=networkConnectors,networkConnectorName=" + connectoName);
NetworkConnectorViewMBean nc = (NetworkConnectorViewMBean) broker.getManagementContext().newProxyInstance(networkConnectorObjectName,
NetworkConnectorViewMBean.class, true);
assertNotNull(nc);
assertEquals("NC", nc.getName());
}
}