org.apache.activemq.broker.jmx.BrokerViewMBean

Here are the examples of the java api class org.apache.activemq.broker.jmx.BrokerViewMBean taken from open source projects.

1. MQTTNetworkOfBrokersFailoverTest#assertOneDurableSubOn()

View license
@SuppressWarnings("unused")
private void assertOneDurableSubOn(BrokerService broker, String subName) throws Exception {
    BrokerViewMBean brokerView = broker.getAdminView();
    ObjectName[] activeDurableSubs = brokerView.getDurableTopicSubscribers();
    ObjectName[] inactiveDurableSubs = brokerView.getInactiveDurableTopicSubscribers();
    ObjectName[] allDurables = (ObjectName[]) ArrayUtils.addAll(activeDurableSubs, inactiveDurableSubs);
    assertEquals(1, allDurables.length);
    // at this point our assertions should prove that we have only on durable sub
    DurableSubscriptionViewMBean durableSubView = (DurableSubscriptionViewMBean) broker.getManagementContext().newProxyInstance(allDurables[0], DurableSubscriptionViewMBean.class, true);
    assertEquals(subName, durableSubView.getClientId());
}

2. ActiveMQBroker#getBrokerName()

View license
@Override
public String getBrokerName() throws MessageQueueJmxException {
    String settingsName = settingsDao.getBrokerName();
    String viewBeanName = "";
    if (settingsName == null) {
        settingsName = "";
    }
    BrokerViewMBean viewMBean;
    viewMBean = getMBean(brokerViewBeanObjectName, BrokerViewMBean.class);
    if (viewMBean != null) {
        viewBeanName = viewMBean.getBrokerName();
        if (!StringUtils.equals(settingsName, viewBeanName)) {
            settingsName += " (" + viewBeanName + ")";
        }
    }
    return settingsName;
}

3. ActiveMQBroker#getBrokerQueues()

View license
@Override
public Set<BrokerQueue> getBrokerQueues() throws MessageQueueJmxException {
    Set<BrokerQueue> res = new HashSet<BrokerQueue>();
    ObjectName[] queueObjects = new ObjectName[0];
    BrokerViewMBean viewMBean = getMBean(brokerViewBeanObjectName, BrokerViewMBean.class);
    if (viewMBean != null) {
        queueObjects = viewMBean.getQueues();
    }
    for (ObjectName objectName : queueObjects) {
        QueueViewMBean queue = getMBean(objectName, QueueViewMBean.class);
        BrokerQueue brokerQueue = new BrokerQueue();
        brokerQueue.setName(queue.getName());
        brokerQueue.setDispatchedMessagesCount(queue.getDequeueCount());
        brokerQueue.setPendingMessagesCount(queue.getQueueSize());
        res.add(brokerQueue);
    }
    return res;
}

4. ActiveMQBroker#getMessageHandlerConsumers()

View license
@Override
public MessageHandlerMQConsumer[] getMessageHandlerConsumers() throws MessageQueueJmxException {
    Set<MessageHandlerMQConsumer> res = new HashSet<MessageHandlerMQConsumer>();
    ObjectName[] subscriberObjects = new ObjectName[0];
    BrokerViewMBean viewMBean = getMBean(brokerViewBeanObjectName, BrokerViewMBean.class);
    if (viewMBean != null) {
        subscriberObjects = viewMBean.getQueueSubscribers();
    }
    for (ObjectName objectName : subscriberObjects) {
        SubscriptionViewMBean subscriber = getMBean(objectName, SubscriptionViewMBean.class);
        MessageHandlerMQConsumer consumer = new MessageHandlerMQConsumer();
        consumer.setSelector(subscriber.getSelector());
        consumer.setDispatchedMessagesCount(subscriber.getDequeueCounter());
        consumer.setPendingMessagesCount(subscriber.getMessageCountAwaitingAcknowledge());
        res.add(consumer);
    }
    MessageHandlerMQConsumer[] sortedRes = new MessageHandlerMQConsumer[res.size()];
    res.toArray(sortedRes);
    Arrays.sort(sortedRes);
    return sortedRes;
}

5. JmsDurableSubscriberTest#testDurableSubscriptionUnsubscribe()

View license
@Test(timeout = 60000)
public void testDurableSubscriptionUnsubscribe() throws Exception {
    connection = createAmqpConnection();
    connection.setClientID("DURABLE-AMQP");
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Topic topic = session.createTopic(name.getMethodName());
    session.createDurableSubscriber(topic, getSubscriptionName()).close();
    BrokerViewMBean broker = getProxyToBroker();
    assertEquals(1, broker.getInactiveDurableTopicSubscribers().length);
    session.unsubscribe(getSubscriptionName());
    assertEquals(0, broker.getInactiveDurableTopicSubscribers().length);
    assertEquals(0, broker.getDurableTopicSubscribers().length);
}

6. JmsDurableSubscriberTest#testDurableSubscriptionUnsubscribeNoExistingSubThrowsJMSEx()

View license
@Test(timeout = 60000)
public void testDurableSubscriptionUnsubscribeNoExistingSubThrowsJMSEx() throws Exception {
    connection = createAmqpConnection();
    connection.setClientID("DURABLE-AMQP");
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    BrokerViewMBean broker = getProxyToBroker();
    assertEquals(0, broker.getDurableTopicSubscribers().length);
    assertEquals(0, broker.getInactiveDurableTopicSubscribers().length);
    try {
        session.unsubscribe(getSubscriptionName());
        fail("Should have thrown an InvalidDestinationException");
    } catch (InvalidDestinationException ide) {
    }
}

7. JmsSessionTest#testDeleteTemporaryQueue()

Project: qpid-jms
Source File: JmsSessionTest.java
View license
@Test(timeout = 30000)
public void testDeleteTemporaryQueue() throws Exception {
    connection = createAmqpConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    assertNotNull(queue);
    assertTrue(queue instanceof TemporaryQueue);
    final BrokerViewMBean broker = getProxyToBroker();
    assertEquals(1, broker.getTemporaryQueues().length);
    TemporaryQueue tempQueue = (TemporaryQueue) queue;
    tempQueue.delete();
    assertTrue("Temp Queue should be deleted.", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return broker.getTemporaryQueues().length == 0;
        }
    }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(50)));
}

8. JmsSessionTest#testDeleteTemporaryTopic()

Project: qpid-jms
Source File: JmsSessionTest.java
View license
@Test(timeout = 30000)
public void testDeleteTemporaryTopic() throws Exception {
    connection = createAmqpConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = session.createTemporaryTopic();
    assertNotNull(topic);
    assertTrue(topic instanceof TemporaryTopic);
    final BrokerViewMBean broker = getProxyToBroker();
    assertEquals(1, broker.getTemporaryTopics().length);
    TemporaryTopic tempTopic = (TemporaryTopic) topic;
    tempTopic.delete();
    assertTrue("Temp Topic should be deleted.", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return broker.getTemporaryTopics().length == 0;
        }
    }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(50)));
}

9. AdvisoryJmxTest#testCreateDeleteDestinations()

View license
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 = 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);
}

10. JmxCreateNCTest#testBridgeRegistration()

View license
@Test
public void testBridgeRegistration() throws Exception {
    BrokerService broker = new BrokerService();
    broker.setBrokerName(BROKER_NAME);
    // explicitly set this so no funny issues
    broker.setUseJmx(true);
    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());
}

11. MQTTNetworkOfBrokersFailoverTest#assertQueueExistsOn()

View license
private void assertQueueExistsOn(BrokerService broker, String queueName) throws Exception {
    BrokerViewMBean brokerView = broker.getAdminView();
    ObjectName[] queueNames = brokerView.getQueues();
    assertEquals(1, queueNames.length);
    assertTrue(queueNames[0].toString().contains(queueName));
}

12. ManagementContextXBeanConfigTest#assertAuthentication()

View license
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 = MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true);
    LOG.info("Broker " + mbean.getBrokerId() + " - " + mbean.getBrokerName());
}

13. JmsDurableSubscriberTest#testDurableSubscriptionUnsubscribeInUseThrowsAndRecovers()

View license
@Test(timeout = 60000)
public void testDurableSubscriptionUnsubscribeInUseThrowsAndRecovers() throws Exception {
    connection = createAmqpConnection();
    connection.setClientID("DURABLE-AMQP");
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Topic topic = session.createTopic(name.getMethodName());
    MessageConsumer consumer = session.createDurableSubscriber(topic, getSubscriptionName());
    assertNotNull(consumer);
    BrokerViewMBean broker = getProxyToBroker();
    assertEquals(1, broker.getDurableTopicSubscribers().length);
    assertEquals(0, broker.getInactiveDurableTopicSubscribers().length);
    try {
        session.unsubscribe(getSubscriptionName());
        fail("Should have thrown a JMSException");
    } catch (JMSException ex) {
    }
    assertEquals(1, broker.getDurableTopicSubscribers().length);
    assertEquals(0, broker.getInactiveDurableTopicSubscribers().length);
    consumer.close();
    assertEquals(0, broker.getDurableTopicSubscribers().length);
    assertEquals(1, broker.getInactiveDurableTopicSubscribers().length);
    session.unsubscribe(getSubscriptionName());
    assertEquals(0, broker.getDurableTopicSubscribers().length);
    assertEquals(0, broker.getInactiveDurableTopicSubscribers().length);
}

14. JmsSessionTest#testCreateTemporaryQueue()

Project: qpid-jms
Source File: JmsSessionTest.java
View license
@Test(timeout = 30000)
public void testCreateTemporaryQueue() throws Exception {
    connection = createAmqpConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    assertNotNull(queue);
    assertTrue(queue instanceof TemporaryQueue);
    final BrokerViewMBean broker = getProxyToBroker();
    assertEquals(1, broker.getTemporaryQueues().length);
}

15. JmsSessionTest#testCreateTemporaryTopic()

Project: qpid-jms
Source File: JmsSessionTest.java
View license
@Test(timeout = 30000)
public void testCreateTemporaryTopic() throws Exception {
    connection = createAmqpConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = session.createTemporaryTopic();
    assertNotNull(topic);
    assertTrue(topic instanceof TemporaryTopic);
    final BrokerViewMBean broker = getProxyToBroker();
    assertEquals(1, broker.getTemporaryTopics().length);
}

16. QpidJmsTestSupport#getProxyToBroker()

Project: qpid-jms
Source File: QpidJmsTestSupport.java
View license
protected BrokerViewMBean getProxyToBroker(BrokerService broker) throws MalformedObjectNameException, JMSException {
    ObjectName brokerViewMBean = broker.getBrokerObjectName();
    BrokerViewMBean proxy = (BrokerViewMBean) brokerService.getManagementContext().newProxyInstance(brokerViewMBean, BrokerViewMBean.class, true);
    return proxy;
}