org.apache.activemq.broker.artemiswrapper.ArtemisBrokerWrapper

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

1. BrokerService#makeSureDestinationExists()

Project: activemq-artemis
Source File: BrokerService.java
View license
public void makeSureDestinationExists(ActiveMQDestination activemqDestination) throws Exception {
    ArtemisBrokerWrapper hqBroker = (ArtemisBrokerWrapper) this.broker;
    //it can be null
    if (activemqDestination == null) {
        return;
    }
    if (activemqDestination.isQueue()) {
        String qname = activemqDestination.getPhysicalName();
        System.out.println("physical name: " + qname);
        hqBroker.makeSureQueueExists(qname);
    }
}

2. RemoveDestinationTest#destinationPresentInAdminView()

View license
private boolean destinationPresentInAdminView(ActiveMQTopic amqTopic) throws Exception {
    boolean found = false;
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    PostOffice po = wrapper.getServer().getPostOffice();
    Set<SimpleString> addressSet = po.getAddresses();
    Iterator<SimpleString> iter = addressSet.iterator();
    String addressToFind = "jms.topic." + amqTopic.getPhysicalName();
    while (iter.hasNext()) {
        if (addressToFind.equals(iter.next().toString())) {
            found = true;
            break;
        }
    }
    return found;
}

3. BrokerTest#testQueueTransactedAck()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testQueueTransactedAck() throws Exception {
    // Setup a first connection
    StubConnection connection1 = createConnection();
    ConnectionInfo connectionInfo1 = createConnectionInfo();
    SessionInfo sessionInfo1 = createSessionInfo(connectionInfo1);
    ProducerInfo producerInfo1 = createProducerInfo(sessionInfo1);
    connection1.send(connectionInfo1);
    connection1.send(sessionInfo1);
    connection1.send(producerInfo1);
    destination = createDestinationInfo(connection1, connectionInfo1, destinationType);
    ConsumerInfo consumerInfo1 = createConsumerInfo(sessionInfo1, destination);
    consumerInfo1.setPrefetchSize(100);
    connection1.send(consumerInfo1);
    // Send the messages
    for (int i = 0; i < 4; i++) {
        Message message = createMessage(producerInfo1, destination, deliveryMode);
        connection1.send(message);
    }
    // Begin the transaction.
    LocalTransactionId txid = createLocalTransaction(sessionInfo1);
    connection1.send(createBeginTransaction(connectionInfo1, txid));
    // Acknowledge the first 2 messages.
    for (int i = 0; i < 2; i++) {
        Message m1 = receiveMessage(connection1);
        assertNotNull("m1 is null for index: " + i, m1);
        MessageAck ack = createAck(consumerInfo1, m1, 1, MessageAck.STANDARD_ACK_TYPE);
        ack.setTransactionId(txid);
        connection1.request(ack);
    }
    // Commit the transaction.
    connection1.send(createCommitTransaction1Phase(connectionInfo1, txid));
    //due to async tx operations, we need some time for message count to go down
    Thread.sleep(1000);
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    long messageCount = wrapper.getAMQueueMessageCount(destination);
    // The queue should now only have the remaining 2 messages
    assertEquals(2, messageCount);
}

4. BrokerTest#testQueueAckRemovesMessage()

Project: activemq-artemis
Source File: BrokerTest.java
View license
public void testQueueAckRemovesMessage() throws Exception {
    // Start a producer and consumer
    StubConnection connection = createConnection();
    ConnectionInfo connectionInfo = createConnectionInfo();
    SessionInfo sessionInfo = createSessionInfo(connectionInfo);
    ProducerInfo producerInfo = createProducerInfo(sessionInfo);
    connection.send(connectionInfo);
    connection.send(sessionInfo);
    connection.send(producerInfo);
    destination = createDestinationInfo(connection, connectionInfo, destinationType);
    Message message1 = createMessage(producerInfo, destination, deliveryMode);
    Message message2 = createMessage(producerInfo, destination, deliveryMode);
    connection.send(message1);
    connection.send(message2);
    // Make sure the message was delivered.
    ConsumerInfo consumerInfo = createConsumerInfo(sessionInfo, destination);
    connection.request(consumerInfo);
    Message m = receiveMessage(connection);
    assertNotNull(m);
    assertEquals(m.getMessageId(), message1.getMessageId());
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    long messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 2);
    connection.send(createAck(consumerInfo, m, 1, MessageAck.DELIVERED_ACK_TYPE));
    messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 2);
    connection.send(createAck(consumerInfo, m, 1, MessageAck.STANDARD_ACK_TYPE));
    //give some time for broker to count down
    Thread.sleep(2000);
    messageCount = wrapper.getAMQueueMessageCount(destination);
    assertTrue(messageCount == 1);
}

5. JMSConsumerTest#createManagedDestinationOnServer()

View license
private void createManagedDestinationOnServer(ActiveMQDestination destination) throws Exception {
    String destName = destination.getPhysicalName();
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    MBeanServer beanServer = wrapper.getMbeanServer();
    ObjectName objName = ObjectNameBuilder.DEFAULT.getJMSServerObjectName();
    JMSServerControl serverControl = MBeanServerInvocationHandler.newProxyInstance(beanServer, objName, JMSServerControl.class, false);
    serverControl.createQueue(destName);
}

6. JMSConsumerTest#createJMSQueueControl()

View license
private JMSQueueControl createJMSQueueControl(String destName) throws Exception {
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    MBeanServer beanServer = wrapper.getMbeanServer();
    ObjectName objName = ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(destName);
    return MBeanServerInvocationHandler.newProxyInstance(beanServer, objName, JMSQueueControl.class, false);
}

7. JMSConsumerTest#createJMSTopicControl()

View license
private TopicControl createJMSTopicControl(String destName) throws Exception {
    ArtemisBrokerWrapper wrapper = (ArtemisBrokerWrapper) broker.getBroker();
    MBeanServer beanServer = wrapper.getMbeanServer();
    ObjectName objName = ObjectNameBuilder.DEFAULT.getJMSTopicObjectName(destName);
    return MBeanServerInvocationHandler.newProxyInstance(beanServer, objName, TopicControl.class, false);
}

8. OptimizedAckTest#testReceivedMessageStillInflight()

View license
public void testReceivedMessageStillInflight() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < 10; i++) {
        producer.send(session.createTextMessage("Hello" + i));
    }
    MessageConsumer consumer = session.createConsumer(queue);
    //check queue delivering count is 10
    ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
    Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("jms.queue.test"));
    final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
    assertTrue("deliverying count is 10", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 10 == coreQueue.getDeliveringCount();
        }
    }));
    for (int i = 0; i < 6; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
    }
    for (int i = 6; i < 10; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                return 3 == coreQueue.getDeliveringCount();
            }
        }));
    }
}

9. OptimizedAckTest#testVerySlowReceivedMessageStillInflight()

View license
public void testVerySlowReceivedMessageStillInflight() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < 10; i++) {
        producer.send(session.createTextMessage("Hello" + i));
    }
    MessageConsumer consumer = session.createConsumer(queue);
    //check queue delivering count is 10
    ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
    Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("jms.queue.test"));
    final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
    assertTrue("prefetch full", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 10 == coreQueue.getDeliveringCount();
        }
    }));
    for (int i = 0; i < 6; i++) {
        Thread.sleep(400);
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
    }
    for (int i = 6; i < 10; i++) {
        Thread.sleep(400);
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                return 3 == coreQueue.getDeliveringCount();
            }
        }));
    }
}

10. OptimizedAckTest#testReceivedMessageNotInFlightAfterScheduledAckFires()

View license
public void testReceivedMessageNotInFlightAfterScheduledAckFires() throws Exception {
    connection.setOptimizedAckScheduledAckInterval(TimeUnit.SECONDS.toMillis(10));
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < 10; i++) {
        producer.send(session.createTextMessage("Hello" + i));
    }
    MessageConsumer consumer = session.createConsumer(queue);
    ArtemisBrokerWrapper broker = (ArtemisBrokerWrapper) ArtemisBrokerHelper.getBroker().getBroker();
    Binding binding = broker.getServer().getPostOffice().getBinding(new SimpleString("jms.queue.test"));
    final QueueImpl coreQueue = (QueueImpl) binding.getBindable();
    assertTrue("prefetch full", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 10 == coreQueue.getDeliveringCount();
        }
    }));
    for (int i = 0; i < 6; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertEquals("all prefetch is still in flight: " + i, 10, coreQueue.getDeliveringCount());
    }
    for (int i = 6; i < 10; i++) {
        javax.jms.Message msg = consumer.receive(4000);
        assertNotNull(msg);
        assertTrue("most are acked but 3 remain", Wait.waitFor(new Wait.Condition() {

            @Override
            public boolean isSatisified() throws Exception {
                return 3 == coreQueue.getDeliveringCount();
            }
        }));
    }
    assertTrue("After delay the scheduled ack should ack all inflight.", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            LOG.info("inflight count: " + coreQueue.getDeliveringCount());
            return 0 == coreQueue.getDeliveringCount();
        }
    }));
}