Fix for https://issues.apache.org/jira/browse/AMQ-4823 NetworkConnector not registered in JMX when created from Broker View + unit tests
Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/81ebd58f Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/81ebd58f Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/81ebd58f Branch: refs/heads/activemq-5.9 Commit: 81ebd58f861c0579854eba5917b200f4097ba91a Parents: 5b6202b Author: Christian Posta <[email protected]> Authored: Thu Oct 24 10:36:00 2013 -0700 Committer: Hadrian Zbarcea <[email protected]> Committed: Tue Mar 11 21:02:33 2014 -0400 ---------------------------------------------------------------------- .../apache/activemq/broker/BrokerService.java | 2 +- .../apache/activemq/broker/jmx/BrokerView.java | 1 + .../apache/activemq/jmx/JmxCreateNCTest.java | 67 ++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/81ebd58f/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java ---------------------------------------------------------------------- diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java b/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java index 93ca692..eecab9d 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java @@ -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); http://git-wip-us.apache.org/repos/asf/activemq/blob/81ebd58f/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java ---------------------------------------------------------------------- diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java index 91e9609..5bad48b 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java @@ -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(); } http://git-wip-us.apache.org/repos/asf/activemq/blob/81ebd58f/activemq-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java ---------------------------------------------------------------------- diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java new file mode 100644 index 0000000..e96c596 --- /dev/null +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java @@ -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()); + } +}
