diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java index 0e1dc4a55b..3ae2d218bc 100755 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java @@ -242,20 +242,20 @@ public class BrokerView implements BrokerViewMBean { } public void addTopic(String name) throws Exception { - broker.addDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQTopic(name),true); + broker.getContextBroker().addDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQTopic(name),true); } public void addQueue(String name) throws Exception { - broker.addDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQQueue(name),true); + broker.getContextBroker().addDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQQueue(name),true); } public void removeTopic(String name) throws Exception { - broker.removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQTopic(name), + broker.getContextBroker().removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQTopic(name), 1000); } public void removeQueue(String name) throws Exception { - broker.removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQQueue(name), + broker.getContextBroker().removeDestination(getConnectionContext(broker.getContextBroker()), new ActiveMQQueue(name), 1000); } diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/advisory/AdvisoryBrokerTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/advisory/AdvisoryBrokerTest.java index c65dc53931..4bb6a7c624 100755 --- a/activemq-core/src/test/java/org/apache/activemq/broker/advisory/AdvisoryBrokerTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/advisory/AdvisoryBrokerTest.java @@ -30,6 +30,10 @@ import org.apache.activemq.command.ProducerInfo; import org.apache.activemq.command.RemoveInfo; import org.apache.activemq.command.SessionInfo; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + public class AdvisoryBrokerTest extends BrokerTestSupport { public void testConnectionAdvisories() throws Exception { diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/advisory/AdvisoryJmxTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/advisory/AdvisoryJmxTest.java new file mode 100644 index 0000000000..90d7283566 --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/broker/advisory/AdvisoryJmxTest.java @@ -0,0 +1,88 @@ +/** + * 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.broker.advisory; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.EmbeddedBrokerTestSupport; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.jmx.BrokerViewMBean; +import org.apache.activemq.broker.jmx.ManagementContext; +import org.apache.activemq.broker.jmx.QueueViewMBean; +import org.apache.activemq.command.ActiveMQMessage; +import org.apache.activemq.command.DestinationInfo; + +import javax.jms.*; +import javax.management.MBeanServerConnection; +import javax.management.MBeanServerInvocationHandler; +import javax.management.ObjectName; +import javax.management.remote.JMXConnector; +import javax.management.remote.JMXConnectorFactory; +import javax.management.remote.JMXServiceURL; + +public class AdvisoryJmxTest extends EmbeddedBrokerTestSupport { + + protected BrokerService createBroker() throws Exception { + BrokerService answer = new BrokerService(); + answer.setPersistent(isPersistent()); + answer.addConnector(bindAddress); + ManagementContext context = new ManagementContext(); + context.setConnectorPort(1199); + answer.setManagementContext(context); + return answer; + } + + public void testCreateDeleteDestinations() throws Exception { + JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi"); + JMXConnector connector = JMXConnectorFactory.connect(url, null); + connector.connect(); + MBeanServerConnection connection = connector.getMBeanServerConnection(); + ObjectName name = new ObjectName("org.apache.activemq:Type=Broker,BrokerName=localhost"); + BrokerViewMBean brokerMbean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true); + Connection conn = createConnection(); + Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageConsumer consumer = sess.createConsumer(sess.createTopic("ActiveMQ.Advisory.Queue")); + conn.start(); + Destination dest = sess.createQueue("test"); + + brokerMbean.addQueue("test"); + + ActiveMQMessage msg = (ActiveMQMessage)consumer.receive(1000); + assertNotNull(msg); + assertTrue(msg.getDataStructure() instanceof DestinationInfo); + assertEquals(((DestinationInfo)msg.getDataStructure()).getDestination(), dest); + assertEquals(((DestinationInfo)msg.getDataStructure()).getOperationType(), 0); + + brokerMbean.removeQueue("test"); + + msg = (ActiveMQMessage)consumer.receive(1000); + assertNotNull(msg); + assertTrue(msg.getDataStructure() instanceof DestinationInfo); + assertEquals(((DestinationInfo)msg.getDataStructure()).getDestination(), dest); + assertEquals(((DestinationInfo)msg.getDataStructure()).getOperationType(), 1); + + + brokerMbean.addQueue("test"); + msg = (ActiveMQMessage)consumer.receive(1000); + assertNotNull(msg); + assertTrue(msg.getDataStructure() instanceof DestinationInfo); + assertEquals(((DestinationInfo)msg.getDataStructure()).getDestination(), dest); + assertEquals(((DestinationInfo)msg.getDataStructure()).getOperationType(), 0); + assertEquals(((DestinationInfo)msg.getDataStructure()).getOperationType(), 0); + } + + +}