Search in sources :

Example 6 with ManagementContext

use of org.apache.activemq.broker.jmx.ManagementContext in project activemq-artemis by apache.

the class AdvisoryJmxTest method createBroker.

@Override
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;
}
Also used : ManagementContext(org.apache.activemq.broker.jmx.ManagementContext) BrokerService(org.apache.activemq.broker.BrokerService)

Example 7 with ManagementContext

use of org.apache.activemq.broker.jmx.ManagementContext in project activemq-artemis by apache.

the class DiscoveryNetworkReconnectTest method setUp.

@Before
public void setUp() throws Exception {
    context = new JUnit4Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    brokerA = new BrokerService();
    brokerA.setBrokerName("BrokerA");
    configure(brokerA);
    brokerA.addConnector("tcp://localhost:0");
    brokerA.start();
    brokerA.waitUntilStarted();
    proxy = new SocketProxy(brokerA.getTransportConnectors().get(0).getConnectUri());
    managementContext = context.mock(ManagementContext.class);
    context.checking(new Expectations() {

        {
            allowing(managementContext).getJmxDomainName();
            will(returnValue("Test"));
            allowing(managementContext).setBrokerName("BrokerNC");
            allowing(managementContext).start();
            allowing(managementContext).isCreateConnector();
            allowing(managementContext).stop();
            allowing(managementContext).isConnectorStarted();
            // expected MBeans
            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC"))));
            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=Health"))));
            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC"))));
            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=Log4JConfiguration"))));
            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.Connection"))));
            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.NetworkBridge"))));
            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.MasterBroker"))));
            allowing(managementContext).registerMBean(with(any(Object.class)), with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=jobScheduler,jobSchedulerName=JMS"))));
            atLeast(maxReconnects - 1).of(managementContext).registerMBean(with(any(Object.class)), with(new NetworkBridgeObjectNameMatcher<>(new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC,networkBridge=localhost/127.0.0.1_" + proxy.getUrl().getPort()))));
            will(new CustomAction("signal register network mbean") {

                @Override
                public Object invoke(Invocation invocation) throws Throwable {
                    LOG.info("Mbean Registered: " + invocation.getParameter(0));
                    mbeanRegistered.release();
                    return new ObjectInstance((ObjectName) invocation.getParameter(1), "discription");
                }
            });
            atLeast(maxReconnects - 1).of(managementContext).unregisterMBean(with(new NetworkBridgeObjectNameMatcher<>(new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC,networkBridge=localhost/127.0.0.1_" + proxy.getUrl().getPort()))));
            will(new CustomAction("signal unregister network mbean") {

                @Override
                public Object invoke(Invocation invocation) throws Throwable {
                    LOG.info("Mbean Unregistered: " + invocation.getParameter(0));
                    mbeanUnregistered.release();
                    return null;
                }
            });
            allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC"))));
            allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=Health"))));
            allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,connector=networkConnectors,networkConnectorName=NC"))));
            allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,service=Log4JConfiguration"))));
            allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.Connection"))));
            allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.NetworkBridge"))));
            allowing(managementContext).unregisterMBean(with(equal(new ObjectName("Test:type=Broker,brokerName=BrokerNC,destinationType=Topic,destinationName=ActiveMQ.Advisory.MasterBroker"))));
        }
    });
    brokerB = new BrokerService();
    brokerB.setManagementContext(managementContext);
    brokerB.setBrokerName("BrokerNC");
    configure(brokerB);
}
Also used : Expectations(org.jmock.Expectations) JUnit4Mockery(org.jmock.integration.junit4.JUnit4Mockery) Invocation(org.jmock.api.Invocation) CustomAction(org.jmock.lib.action.CustomAction) ObjectInstance(javax.management.ObjectInstance) ManagementContext(org.apache.activemq.broker.jmx.ManagementContext) SocketProxy(org.apache.activemq.util.SocketProxy) BrokerService(org.apache.activemq.broker.BrokerService) ObjectName(javax.management.ObjectName) Before(org.junit.Before)

Aggregations

ManagementContext (org.apache.activemq.broker.jmx.ManagementContext)7 BrokerService (org.apache.activemq.broker.BrokerService)4 ObjectName (javax.management.ObjectName)3 ArrayList (java.util.ArrayList)2 QueueViewMBean (org.apache.activemq.broker.jmx.QueueViewMBean)2 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)2 KahaDBPersistenceAdapter (org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)2 LevelDBPersistenceAdapter (org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter)2 Hashtable (java.util.Hashtable)1 LinkedList (java.util.LinkedList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Connection (javax.jms.Connection)1 Session (javax.jms.Session)1 ObjectInstance (javax.management.ObjectInstance)1 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)1 TransportConnector (org.apache.activemq.broker.TransportConnector)1 ActiveMQQueue (org.apache.activemq.command.ActiveMQQueue)1 TransportServer (org.apache.activemq.transport.TransportServer)1 TcpTransportServer (org.apache.activemq.transport.tcp.TcpTransportServer)1 SocketProxy (org.apache.activemq.util.SocketProxy)1