Search in sources :

Example 86 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class ActiveMQServerControlImpl method listAddresses.

@Override
public String listAddresses(String options, int page, int pageSize) throws Exception {
    checkStarted();
    clearIO();
    try {
        final Set<SimpleString> addresses = server.getPostOffice().getAddresses();
        List<AddressInfo> addressInfo = new ArrayList<>();
        for (SimpleString address : addresses) {
            AddressInfo info = server.getPostOffice().getAddressInfo(address);
            // ignore if no longer available
            if (info != null) {
                addressInfo.add(info);
            }
        }
        AddressView view = new AddressView(server);
        view.setCollection(addressInfo);
        view.setOptions(options);
        return view.getResultsAsJson(page, pageSize);
    } finally {
        blockOnIO();
    }
}
Also used : ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AddressView(org.apache.activemq.artemis.core.management.impl.view.AddressView) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo)

Example 87 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class WildcardAddressManagerUnitTest method testWildCardAddressRemoval.

/**
 * Test for ARTEMIS-1610
 * @throws Exception
 */
@SuppressWarnings("unchecked")
@Test
public void testWildCardAddressRemoval() throws Exception {
    WildcardAddressManager ad = new WildcardAddressManager(new BindingFactoryFake(), null);
    ad.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("Queue1.#"), RoutingType.ANYCAST));
    ad.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("Topic1.#"), RoutingType.MULTICAST));
    ad.addBinding(new BindingFake("Topic1.topic", "two"));
    ad.addBinding(new BindingFake("Queue1.#", "one"));
    Field wildcardAddressField = WildcardAddressManager.class.getDeclaredField("wildCardAddresses");
    wildcardAddressField.setAccessible(true);
    Map<SimpleString, Address> wildcardAddresses = (Map<SimpleString, Address>) wildcardAddressField.get(ad);
    // Calling this method will trigger the wildcard to be added to the wildcard map internal
    // to WildcardAddressManager
    ad.getBindingsForRoutingAddress(SimpleString.toSimpleString("Topic1.#"));
    // Remove the address
    ad.removeAddressInfo(SimpleString.toSimpleString("Topic1.#"));
    // Verify the address was cleaned up properly
    assertEquals(1, wildcardAddresses.size());
    assertNull(ad.getAddressInfo(SimpleString.toSimpleString("Topic1.#")));
    assertNull(wildcardAddresses.get(SimpleString.toSimpleString("Topic1.#")));
}
Also used : Field(java.lang.reflect.Field) WildcardAddressManager(org.apache.activemq.artemis.core.postoffice.impl.WildcardAddressManager) Address(org.apache.activemq.artemis.core.postoffice.Address) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Map(java.util.Map) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 88 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class WildcardAddressManagerUnitTest method testWildCardAddressRemovalDifferentWildcard.

@Test
public void testWildCardAddressRemovalDifferentWildcard() throws Exception {
    final WildcardConfiguration configuration = new WildcardConfiguration();
    configuration.setAnyWords('>');
    WildcardAddressManager ad = new WildcardAddressManager(new BindingFactoryFake(), configuration, null);
    ad.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("Topic1.>"), RoutingType.MULTICAST));
    ad.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("Topic1.test"), RoutingType.MULTICAST));
    ad.addBinding(new BindingFake("Topic1.>", "one"));
    assertEquals(1, ad.getBindingsForRoutingAddress(SimpleString.toSimpleString("Topic1.>")).getBindings().size());
    assertEquals(1, ad.getBindingsForRoutingAddress(SimpleString.toSimpleString("Topic1.test")).getBindings().size());
    assertEquals(0, ad.getDirectBindings(SimpleString.toSimpleString("Topic1.test")).getBindings().size());
    assertEquals(1, ad.getDirectBindings(SimpleString.toSimpleString("Topic1.>")).getBindings().size());
    // Remove the address
    ad.removeAddressInfo(SimpleString.toSimpleString("Topic1.test"));
    // should still have 1 address and binding
    assertEquals(1, ad.getAddresses().size());
    assertEquals(1, ad.getBindings().size());
    ad.removeBinding(SimpleString.toSimpleString("one"), null);
    ad.removeAddressInfo(SimpleString.toSimpleString("Topic1.>"));
    assertEquals(0, ad.getAddresses().size());
    assertEquals(0, ad.getBindings().size());
}
Also used : WildcardAddressManager(org.apache.activemq.artemis.core.postoffice.impl.WildcardAddressManager) WildcardConfiguration(org.apache.activemq.artemis.core.config.WildcardConfiguration) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 89 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class WildcardAddressManagerUnitTest method testWildCardAddressDirectBindings.

@Test
public void testWildCardAddressDirectBindings() throws Exception {
    final WildcardConfiguration configuration = new WildcardConfiguration();
    configuration.setAnyWords('>');
    WildcardAddressManager ad = new WildcardAddressManager(new BindingFactoryFake(), configuration, null);
    ad.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("Topic1.>"), RoutingType.MULTICAST));
    ad.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("Topic1.test"), RoutingType.MULTICAST));
    ad.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("Topic1.test.test1"), RoutingType.MULTICAST));
    ad.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("Topic1.test.test2"), RoutingType.MULTICAST));
    ad.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("Topic2.>"), RoutingType.MULTICAST));
    ad.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("Topic2.test"), RoutingType.MULTICAST));
    ad.addBinding(new BindingFake("Topic1.>", "one"));
    ad.addBinding(new BindingFake("Topic1.test", "two"));
    ad.addBinding(new BindingFake("Topic2.test", "three"));
    assertEquals(1, ad.getBindingsForRoutingAddress(SimpleString.toSimpleString("Topic1.>")).getBindings().size());
    assertEquals(2, ad.getBindingsForRoutingAddress(SimpleString.toSimpleString("Topic1.test")).getBindings().size());
    assertEquals(1, ad.getBindingsForRoutingAddress(SimpleString.toSimpleString("Topic1.test.test1")).getBindings().size());
    assertEquals(1, ad.getBindingsForRoutingAddress(SimpleString.toSimpleString("Topic1.test.test2")).getBindings().size());
    assertEquals(1, ad.getDirectBindings(SimpleString.toSimpleString("Topic1.>")).getBindings().size());
    assertEquals(1, ad.getDirectBindings(SimpleString.toSimpleString("Topic1.test")).getBindings().size());
    assertEquals(0, ad.getDirectBindings(SimpleString.toSimpleString("Topic1.test1")).getBindings().size());
    assertEquals(0, ad.getDirectBindings(SimpleString.toSimpleString("Topic1.test2")).getBindings().size());
    assertEquals(0, ad.getDirectBindings(SimpleString.toSimpleString("Topic2.>")).getBindings().size());
    assertEquals(1, ad.getDirectBindings(SimpleString.toSimpleString("Topic2.test")).getBindings().size());
}
Also used : WildcardAddressManager(org.apache.activemq.artemis.core.postoffice.impl.WildcardAddressManager) WildcardConfiguration(org.apache.activemq.artemis.core.config.WildcardConfiguration) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 90 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class PagingTest method testFirstPageCompleteNotDeleted.

// First page is complete but it wasn't deleted
@Test
public void testFirstPageCompleteNotDeleted() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    final int numberOfMessages = 20;
    locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    server.addAddressInfo(new AddressInfo(PagingTest.ADDRESS, RoutingType.ANYCAST));
    Queue queue = server.createQueue(ADDRESS, RoutingType.ANYCAST, ADDRESS, null, true, false);
    queue.getPageSubscription().getPagingStore().startPaging();
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    ClientMessage message = null;
    byte[] body = new byte[MESSAGE_SIZE];
    ByteBuffer bb = ByteBuffer.wrap(body);
    for (int j = 1; j <= MESSAGE_SIZE; j++) {
        bb.put(getSamplebyte(j));
    }
    for (int i = 0; i < numberOfMessages; i++) {
        message = session.createMessage(true);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(body);
        message.putIntProperty("count", i);
        producer.send(message);
        if ((i + 1) % 5 == 0) {
            session.commit();
            queue.getPageSubscription().getPagingStore().forceAnotherPage();
        }
    }
    session.commit();
    producer.close();
    session.close();
    // This will make the cursor to set the page complete and not actually delete it
    queue.getPageSubscription().getPagingStore().disableCleanup();
    session = sf.createSession(false, false, false);
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    session.start();
    for (int i = 0; i < 5; i++) {
        ClientMessage msg = consumer.receive(2000);
        assertNotNull(msg);
        assertEquals(i, msg.getIntProperty("count").intValue());
        msg.individualAcknowledge();
        System.out.println(msg);
    }
    session.commit();
    session.close();
    server.stop();
    server.start();
    sf = createSessionFactory(locator);
    session = sf.createSession(false, false, false);
    consumer = session.createConsumer(ADDRESS);
    session.start();
    for (int i = 5; i < numberOfMessages; i++) {
        ClientMessage msg = consumer.receive(2000);
        assertNotNull(msg);
        assertEquals(i, msg.getIntProperty("count").intValue());
        msg.acknowledge();
        System.out.println(msg);
    }
    assertNull(consumer.receiveImmediate());
    session.commit();
    session.close();
    sf.close();
    locator.close();
}
Also used : DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ByteBuffer(java.nio.ByteBuffer) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Aggregations

AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)116 Test (org.junit.Test)89 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)73 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)32 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)24 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)23 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)23 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)22 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)21 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)19 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)18 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)17 JsonObject (javax.json.JsonObject)16 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)16 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)16 JsonArray (javax.json.JsonArray)15 Queue (org.apache.activemq.artemis.core.server.Queue)15 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)13 Configuration (org.apache.activemq.artemis.core.config.Configuration)12 Session (javax.jms.Session)11