Search in sources :

Example 6 with PostOffice

use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.

the class ClusterTestBase method waitForMessages.

protected void waitForMessages(final int node, final String address, final int count) throws Exception {
    ActiveMQServer server = servers[node];
    if (server == null) {
        throw new IllegalArgumentException("No server at " + node);
    }
    PostOffice po = server.getPostOffice();
    long start = System.currentTimeMillis();
    int messageCount = 0;
    do {
        messageCount = getMessageCount(po, address);
        if (messageCount == count) {
            return;
        }
        Thread.sleep(10);
    } while (System.currentTimeMillis() - start < ActiveMQTestBase.WAIT_TIMEOUT);
    throw new IllegalStateException("Timed out waiting for messages (messageCount = " + messageCount + ", expecting = " + count);
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice)

Example 7 with PostOffice

use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.

the class ClusterTestBase method debugBindings.

protected String debugBindings(final ActiveMQServer server, final String address) throws Exception {
    StringWriter str = new StringWriter();
    PrintWriter out = new PrintWriter(str);
    if (server == null) {
        return "server is shutdown";
    }
    PostOffice po = server.getPostOffice();
    if (po == null) {
        return "server is shutdown";
    }
    Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
    out.println("=======================================================================");
    out.println("Binding information for address = " + address + " on " + server);
    for (Binding binding : bindings.getBindings()) {
        QueueBinding qBinding = (QueueBinding) binding;
        out.println("Binding = " + qBinding + ", queue=" + qBinding.getQueue());
    }
    out.println("=======================================================================");
    return str.toString();
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) StringWriter(java.io.StringWriter) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) PrintWriter(java.io.PrintWriter)

Example 8 with PostOffice

use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.

the class ActiveMQTestBase method printBindings.

public void printBindings(ActiveMQServer server, String address) throws Exception {
    PostOffice po = server.getPostOffice();
    Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
    System.err.println("=======================================================================");
    System.err.println("Binding information for address = " + address + " for server " + server);
    for (Binding binding : bindings.getBindings()) {
        QueueBinding qBinding = (QueueBinding) binding;
        System.err.println("Binding = " + qBinding + ", queue=" + qBinding.getQueue());
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 9 with PostOffice

use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.

the class ActiveMQTestBase method waitForBindings.

/**
 * @param server                the server where's being checked
 * @param address               the name of the address being checked
 * @param local                 if true we are looking for local bindings, false we are looking for remoting servers
 * @param expectedBindingCount  the expected number of counts
 * @param expectedConsumerCount the expected number of consumers
 * @param timeout               the timeout used on the check
 * @return
 * @throws Exception
 * @throws InterruptedException
 */
protected boolean waitForBindings(final ActiveMQServer server, final String address, final boolean local, final int expectedBindingCount, final int expectedConsumerCount, long timeout) throws Exception {
    final PostOffice po = server.getPostOffice();
    long start = System.currentTimeMillis();
    int bindingCount = 0;
    int totConsumers = 0;
    do {
        bindingCount = 0;
        totConsumers = 0;
        Bindings bindings = po.getBindingsForAddress(new SimpleString(address));
        for (Binding binding : bindings.getBindings()) {
            if (binding.isConnected() && (binding instanceof LocalQueueBinding && local || binding instanceof RemoteQueueBinding && !local)) {
                QueueBinding qBinding = (QueueBinding) binding;
                bindingCount++;
                totConsumers += qBinding.consumerCount();
            }
        }
        if (bindingCount == expectedBindingCount && totConsumers == expectedConsumerCount) {
            return true;
        }
        Thread.sleep(10);
    } while (System.currentTimeMillis() - start < timeout);
    String msg = "Timed out waiting for bindings (bindingCount = " + bindingCount + " (expecting " + expectedBindingCount + ") " + ", totConsumers = " + totConsumers + " (expecting " + expectedConsumerCount + ")" + ")";
    log.error(msg);
    return false;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)

Example 10 with PostOffice

use of org.apache.activemq.artemis.core.postoffice.PostOffice in project activemq-artemis by apache.

the class DuplicateDetectionUnitTest method testReloadDuplication.

// Public --------------------------------------------------------
@Test
public void testReloadDuplication() throws Exception {
    JournalStorageManager journal = null;
    try {
        clearDataRecreateServerDirs();
        SimpleString ADDRESS = new SimpleString("address");
        Configuration configuration = createDefaultInVMConfig();
        PostOffice postOffice = new FakePostOffice();
        ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(ActiveMQDefaultConfiguration.getDefaultScheduledThreadPoolMaxSize(), ActiveMQThreadFactory.defaultThreadFactory());
        journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
        journal.start();
        journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        HashMap<SimpleString, List<Pair<byte[], Long>>> mapDups = new HashMap<>();
        FakePagingManager pagingManager = new FakePagingManager();
        journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
        Assert.assertEquals(0, mapDups.size());
        DuplicateIDCacheImpl cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
        for (int i = 0; i < 100; i++) {
            cacheID.addToCache(RandomUtil.randomBytes());
        }
        journal.stop();
        journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
        journal.start();
        journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
        Assert.assertEquals(1, mapDups.size());
        List<Pair<byte[], Long>> values = mapDups.get(ADDRESS);
        Assert.assertEquals(10, values.size());
        cacheID = new DuplicateIDCacheImpl(ADDRESS, 10, journal, true);
        cacheID.load(values);
        for (int i = 0; i < 100; i++) {
            cacheID.addToCache(RandomUtil.randomBytes(), null);
        }
        journal.stop();
        mapDups.clear();
        journal = new JournalStorageManager(configuration, EmptyCriticalAnalyzer.getInstance(), factory, factory);
        journal.start();
        journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
        journal.loadMessageJournal(postOffice, pagingManager, new ResourceManagerImpl(0, 0, scheduledThreadPool), null, mapDups, null, null, new PostOfficeJournalLoader(postOffice, pagingManager, null, null, null, null, null, null));
        Assert.assertEquals(1, mapDups.size());
        values = mapDups.get(ADDRESS);
        Assert.assertEquals(10, values.size());
        scheduledThreadPool.shutdown();
    } finally {
        if (journal != null) {
            try {
                journal.stop();
            } catch (Throwable ignored) {
            }
        }
    }
}
Also used : PostOfficeJournalLoader(org.apache.activemq.artemis.core.server.impl.PostOfficeJournalLoader) GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQDefaultConfiguration(org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration) HashMap(java.util.HashMap) ResourceManagerImpl(org.apache.activemq.artemis.core.transaction.impl.ResourceManagerImpl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) PostOffice(org.apache.activemq.artemis.core.postoffice.PostOffice) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) DuplicateIDCacheImpl(org.apache.activemq.artemis.core.postoffice.impl.DuplicateIDCacheImpl) FakePagingManager(org.apache.activemq.artemis.tests.unit.util.FakePagingManager) ArrayList(java.util.ArrayList) List(java.util.List) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) Pair(org.apache.activemq.artemis.api.core.Pair) Test(org.junit.Test)

Aggregations

PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)12 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)9 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)6 Binding (org.apache.activemq.artemis.core.postoffice.Binding)5 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)5 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)5 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)4 RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)4 Test (org.junit.Test)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)3 ArrayList (java.util.ArrayList)3 Filter (org.apache.activemq.artemis.core.filter.Filter)3 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)3 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)3 QueueConfig (org.apache.activemq.artemis.core.server.QueueConfig)3 HierarchicalRepository (org.apache.activemq.artemis.core.settings.HierarchicalRepository)3 ExecutorFactory (org.apache.activemq.artemis.utils.ExecutorFactory)3 File (java.io.File)2