Package org.apache.activemq.broker.jmx

Examples of org.apache.activemq.broker.jmx.BrokerViewMBean


        }

        Set<ObjectName> brokers = connection.queryNames(name, null);
        Set<ObjectName> masterBrokers = new HashSet<ObjectName>();
        for (ObjectName objectName : brokers) {
            BrokerViewMBean mbean = MBeanServerInvocationHandler.newProxyInstance(connection, objectName, BrokerViewMBean.class, true);
            if (!mbean.isSlave())
                masterBrokers.add(objectName);
        }
        return masterBrokers;
    }
View Full Code Here


    public abstract Set queryNames(ObjectName name, QueryExp query) throws Exception;
    public abstract Object newProxyInstance( ObjectName objectName, Class interfaceClass, boolean notificationBroadcaster) throws Exception;

    @Override
    public Collection<QueueViewMBean> getQueues() throws Exception {
        BrokerViewMBean broker = getBrokerAdmin();
        if (broker == null) {
            return Collections.EMPTY_LIST;
        }
        ObjectName[] queues = broker.getQueues();
        return getManagedObjects(queues, QueueViewMBean.class);
    }
View Full Code Here

        return getManagedObjects(queues, QueueViewMBean.class);
    }

    @Override
    public Collection<TopicViewMBean> getTopics() throws Exception {
        BrokerViewMBean broker = getBrokerAdmin();
        if (broker == null) {
            return Collections.EMPTY_LIST;
        }
        ObjectName[] queues = broker.getTopics();
        return getManagedObjects(queues, TopicViewMBean.class);
    }
View Full Code Here

        return getManagedObjects(queues, TopicViewMBean.class);
    }

    @Override
    public Collection<DurableSubscriptionViewMBean> getDurableTopicSubscribers() throws Exception {
        BrokerViewMBean broker = getBrokerAdmin();
        if (broker == null) {
            return Collections.EMPTY_LIST;
        }
        ObjectName[] queues = broker.getDurableTopicSubscribers();
        return getManagedObjects(queues, DurableSubscriptionViewMBean.class);
    }
View Full Code Here

        return getManagedObjects(queues, DurableSubscriptionViewMBean.class);
    }

    @Override
    public Collection<DurableSubscriptionViewMBean> getInactiveDurableTopicSubscribers() throws Exception {
        BrokerViewMBean broker = getBrokerAdmin();
        if (broker == null) {
            return Collections.EMPTY_LIST;
        }
        ObjectName[] queues = broker.getInactiveDurableTopicSubscribers();
        return getManagedObjects(queues, DurableSubscriptionViewMBean.class);
    }
View Full Code Here

    // -------------------------------------------------------------------------
    public BrokerViewMBean getBrokerAdmin() throws Exception {
        if (brokerFacade == null) {
            throw new IllegalArgumentException("No brokerFacade injected!");
        }
        BrokerViewMBean answer = brokerFacade.getBrokerAdmin();
        if (answer == null) {
            throw new IllegalArgumentException("No brokerAdmin on the injected brokerFacade: " + brokerFacade);
        }
        return answer;
    }
View Full Code Here

        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);
View Full Code Here

    // -------------------------------------------------------------------------
    public BrokerViewMBean getBrokerAdmin() throws Exception {
        if (brokerFacade == null) {
            throw new IllegalArgumentException("No brokerFacade injected!");
        }
        BrokerViewMBean answer = brokerFacade.getBrokerAdmin();
        if (answer == null) {
            throw new IllegalArgumentException("No brokerAdmin on the injected brokerFacade: " + brokerFacade);
        }
        return answer;
    }
View Full Code Here

    public void assertAuthentication(JMXConnector connector) throws Exception {
        connector.connect();
        MBeanServerConnection connection = connector.getMBeanServerConnection();
        ObjectName name = new ObjectName("test.domain:type=Broker,brokerName=localhost");
        BrokerViewMBean mbean = (BrokerViewMBean) MBeanServerInvocationHandler
                .newProxyInstance(connection, name, BrokerViewMBean.class, true);
        LOG.info("Broker " + mbean.getBrokerId() + " - " + mbean.getBrokerName());
    }
View Full Code Here

        stompConnection.setVersion(Stomp.V1_1);

        String domain = "org.apache.activemq";
        ObjectName brokerName = new ObjectName(domain + ":type=Broker,brokerName=localhost");

        BrokerViewMBean view = (BrokerViewMBean)brokerService.getManagementContext().newProxyInstance(brokerName, BrokerViewMBean.class, true);

        String connectFrame = "STOMP\n" +
                "login:system\n" + "passcode:manager\n" + "accept-version:1.1\n" +
                "host:localhost\n" + "client-id:test\n" + "\n" + Stomp.NULL;
        stompConnection.sendFrame(connectFrame);

        String frame = stompConnection.receiveFrame();
        LOG.debug("Broker sent: " + frame);

        assertTrue(frame.startsWith("CONNECTED"));
        assertEquals(view.getDurableTopicSubscribers().length, 0);

        // subscribe to first destination durably
        frame = "SUBSCRIBE\n" +
                "destination:/topic/" + getQueueName() + "1" + "\n" +
                "ack:auto\n" + "receipt:1\n" + "id:durablesub-1\n" +
                "activemq.subscriptionName:test1\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);

        StompFrame receipt = stompConnection.receive();
        LOG.debug("Broker sent: " + receipt);
        assertTrue(receipt.getAction().startsWith("RECEIPT"));
        assertEquals("1", receipt.getHeaders().get("receipt-id"));
        assertEquals(view.getDurableTopicSubscribers().length, 1);

        // subscribe to second destination durably
        frame = "SUBSCRIBE\n" +
                "destination:/topic/" + getQueueName() + "2" + "\n" +
                "ack:auto\n" + "receipt:2\n" + "id:durablesub-2\n" +
                "activemq.subscriptionName:test2\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);

        receipt = stompConnection.receive();
        LOG.debug("Broker sent: " + receipt);
        assertTrue(receipt.getAction().startsWith("RECEIPT"));
        assertEquals("2", receipt.getHeaders().get("receipt-id"));
        assertEquals(view.getDurableTopicSubscribers().length, 2);

        frame = "DISCONNECT\nclient-id:test\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);
        try {
            Thread.sleep(400);
        } catch (InterruptedException e){}

        // reconnect and send some messages to the offline subscribers and then try to get
        // them after subscribing again.
        stompConnect();
        stompConnection.sendFrame(connectFrame);
        frame = stompConnection.receiveFrame();
        LOG.debug("Broker sent: " + frame);
        assertTrue(frame.startsWith("CONNECTED"));
        assertEquals(view.getDurableTopicSubscribers().length, 0);
        assertEquals(view.getInactiveDurableTopicSubscribers().length, 2);

        // unsubscribe from topic 1
        frame = "UNSUBSCRIBE\n" + "destination:/topic/" + getQueueName() + "1\n" +
                "id:durablesub-1\n" + "receipt:3\n" +
                "activemq.subscriptionName:test1\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);
        receipt = stompConnection.receive();
        LOG.debug("Broker sent: " + frame);
        assertTrue(receipt.getAction().startsWith("RECEIPT"));
        assertEquals("3", receipt.getHeaders().get("receipt-id"));

        assertEquals(view.getInactiveDurableTopicSubscribers().length, 1);

        // unsubscribe from topic 2
        frame = "UNSUBSCRIBE\n" + "destination:/topic/" + getQueueName() + "2\n" +
                "id:durablesub-2\n" + "receipt:4\n" +
                "activemq.subscriptionName:test2\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);
        receipt = stompConnection.receive();
        LOG.debug("Broker sent: " + frame);
        assertTrue(receipt.getAction().startsWith("RECEIPT"));
        assertEquals("4", receipt.getHeaders().get("receipt-id"));

        assertEquals(view.getInactiveDurableTopicSubscribers().length, 0);

        frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
        stompConnection.sendFrame(frame);
    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.broker.jmx.BrokerViewMBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.