Search in sources :

Example 11 with QueueBinding

use of org.apache.activemq.artemis.core.postoffice.QueueBinding 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 12 with QueueBinding

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

the class ActiveMQTestBase method getLocalQueueBindings.

private List<QueueBinding> getLocalQueueBindings(final PostOffice postOffice, final String address) throws Exception {
    ArrayList<QueueBinding> bindingsFound = new ArrayList<>();
    Bindings bindings = postOffice.getBindingsForAddress(new SimpleString(address));
    for (Binding binding : bindings.getBindings()) {
        if (binding instanceof LocalQueueBinding) {
            bindingsFound.add((QueueBinding) binding);
        }
    }
    return bindingsFound;
}
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) ArrayList(java.util.ArrayList) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 13 with QueueBinding

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

the class QueueConfigRestartTest method testQueueConfigExclusiveAndRestart.

@Test
public void testQueueConfigExclusiveAndRestart() throws Exception {
    ActiveMQServer server = createServer(true);
    server.start();
    SimpleString address = new SimpleString("test.address");
    SimpleString queue = new SimpleString("test.queue");
    server.createQueue(address, RoutingType.MULTICAST, queue, null, null, true, false, false, false, false, 10, true, true, true, true);
    QueueBinding queueBinding1 = (QueueBinding) server.getPostOffice().getBinding(queue);
    Assert.assertTrue(queueBinding1.getQueue().isExclusive());
    server.stop();
    server.start();
    QueueBinding queueBinding2 = (QueueBinding) server.getPostOffice().getBinding(queue);
    Assert.assertTrue(queueBinding2.getQueue().isExclusive());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 14 with QueueBinding

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

the class QueueConfigRestartTest method testQueueConfigUserAndRestart.

@Test
public void testQueueConfigUserAndRestart() throws Exception {
    ActiveMQServer server = createServer(true);
    server.start();
    SimpleString address = new SimpleString("test.address");
    SimpleString queue = new SimpleString("test.queue");
    server.createQueue(address, RoutingType.MULTICAST, queue, null, SimpleString.toSimpleString("bob"), true, false, false, 10, true, true);
    QueueBinding queueBinding1 = (QueueBinding) server.getPostOffice().getBinding(queue);
    Assert.assertEquals(SimpleString.toSimpleString("bob"), queueBinding1.getQueue().getUser());
    server.stop();
    server.start();
    QueueBinding queueBinding2 = (QueueBinding) server.getPostOffice().getBinding(queue);
    Assert.assertTrue(queueBinding2.getQueue().isPurgeOnNoConsumers());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Test(org.junit.Test)

Example 15 with QueueBinding

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

the class PostOfficeImpl method listQueuesForAddress.

@Override
public List<Queue> listQueuesForAddress(SimpleString address) throws Exception {
    Bindings bindingsForAddress = getBindingsForAddress(address);
    List<Queue> queues = new ArrayList<>();
    for (Binding b : bindingsForAddress.getBindings()) {
        if (b instanceof QueueBinding) {
            Queue q = ((QueueBinding) b).getQueue();
            queues.add(q);
        }
    }
    return queues;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) ArrayList(java.util.ArrayList) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) Queue(org.apache.activemq.artemis.core.server.Queue)

Aggregations

QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)20 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)15 Binding (org.apache.activemq.artemis.core.postoffice.Binding)14 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)13 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)8 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)8 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)6 RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)6 ArrayList (java.util.ArrayList)5 Queue (org.apache.activemq.artemis.core.server.Queue)5 PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4 RoutingType (org.apache.activemq.artemis.api.core.RoutingType)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 File (java.io.File)2 ManagementFactory (java.lang.management.ManagementFactory)2 URL (java.net.URL)2 AccessController (java.security.AccessController)2 PrivilegedAction (java.security.PrivilegedAction)2