Search in sources :

Example 16 with QueueBinding

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

the class AddressControlImpl method getNumberOfMessages.

@Override
public long getNumberOfMessages() throws Exception {
    clearIO();
    long totalMsgs = 0;
    try {
        Bindings bindings = postOffice.getBindingsForAddress(addressInfo.getName());
        for (Binding binding : bindings.getBindings()) {
            if (binding instanceof QueueBinding) {
                totalMsgs += ((QueueBinding) binding).getQueue().getMessageCount();
            }
        }
        return totalMsgs;
    } catch (Throwable t) {
        throw new IllegalStateException(t.getMessage());
    } finally {
        blockOnIO();
    }
}
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) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 17 with QueueBinding

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

the class QueueConfigRestartTest method testQueueConfigLastValueAndRestart.

@Test
public void testQueueConfigLastValueAndRestart() 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, false, true, true);
    QueueBinding queueBinding1 = (QueueBinding) server.getPostOffice().getBinding(queue);
    Assert.assertTrue(queueBinding1.getQueue().isLastValue());
    server.stop();
    server.start();
    QueueBinding queueBinding2 = (QueueBinding) server.getPostOffice().getBinding(queue);
    Assert.assertTrue(queueBinding2.getQueue().isLastValue());
}
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 18 with QueueBinding

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

the class QueueConfigRestartTest method testQueueConfigPurgeOnNoConsumerAndRestart.

// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testQueueConfigPurgeOnNoConsumerAndRestart() 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, 10, true, true);
    QueueBinding queueBinding1 = (QueueBinding) server.getPostOffice().getBinding(queue);
    Assert.assertTrue(queueBinding1.getQueue().isPurgeOnNoConsumers());
    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 19 with QueueBinding

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

the class ServerSessionImpl method createConsumer.

@Override
public ServerConsumer createConsumer(final long consumerID, final SimpleString queueName, final SimpleString filterString, final boolean browseOnly, final boolean supportLargeMessage, final Integer credits) throws Exception {
    final SimpleString unPrefixedQueueName = removePrefix(queueName);
    Binding binding = postOffice.getBinding(unPrefixedQueueName);
    if (binding == null || binding.getType() != BindingType.LOCAL_QUEUE) {
        throw ActiveMQMessageBundle.BUNDLE.noSuchQueue(unPrefixedQueueName);
    }
    SimpleString address = removePrefix(binding.getAddress());
    if (browseOnly) {
        try {
            securityCheck(address, queueName, CheckType.BROWSE, this);
        } catch (Exception e) {
            securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.BROWSE, this);
        }
    } else {
        try {
            securityCheck(address, queueName, CheckType.CONSUME, this);
        } catch (Exception e) {
            securityCheck(address.concat(".").concat(unPrefixedQueueName), queueName, CheckType.CONSUME, this);
        }
    }
    Filter filter = FilterImpl.createFilter(filterString);
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeCreateConsumer(consumerID, (QueueBinding) binding, filterString, browseOnly, supportLargeMessage));
    }
    ServerConsumer consumer = new ServerConsumerImpl(consumerID, this, (QueueBinding) binding, filter, started, browseOnly, storageManager, callback, preAcknowledge, strictUpdateDeliveryCount, managementService, supportLargeMessage, credits, server);
    consumers.put(consumer.getID(), consumer);
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterCreateConsumer(consumer));
    }
    if (!browseOnly) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, address);
        props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
        props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
        props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
        Queue theQueue = (Queue) binding.getBindable();
        props.putIntProperty(ManagementHelper.HDR_CONSUMER_COUNT, theQueue.getConsumerCount());
        // HORNETQ-946
        props.putSimpleStringProperty(ManagementHelper.HDR_USER, SimpleString.toSimpleString(username));
        props.putSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(this.remotingConnection.getRemoteAddress()));
        props.putSimpleStringProperty(ManagementHelper.HDR_SESSION_NAME, SimpleString.toSimpleString(name));
        if (filterString != null) {
            props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
        }
        Notification notification = new Notification(null, CoreNotificationType.CONSUMER_CREATED, props);
        if (logger.isDebugEnabled()) {
            logger.debug("Session with user=" + username + ", connection=" + this.remotingConnection + " created a consumer on queue " + unPrefixedQueueName + ", filter = " + filterString);
        }
        managementService.sendNotification(notification);
    }
    return consumer;
}
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) Filter(org.apache.activemq.artemis.core.filter.Filter) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ServerConsumer(org.apache.activemq.artemis.core.server.ServerConsumer) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Queue(org.apache.activemq.artemis.core.server.Queue) ActiveMQXAException(org.apache.activemq.artemis.core.exception.ActiveMQXAException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) XAException(javax.transaction.xa.XAException) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) ActiveMQIOErrorException(org.apache.activemq.artemis.api.core.ActiveMQIOErrorException) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 20 with QueueBinding

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

the class ActiveMQTestBase method getMessageCount.

/**
 * @param address
 * @param postOffice
 * @return
 * @throws Exception
 */
protected int getMessageCount(final PostOffice postOffice, final String address) throws Exception {
    int messageCount = 0;
    List<QueueBinding> bindings = getLocalQueueBindings(postOffice, address);
    for (QueueBinding qBinding : bindings) {
        qBinding.getQueue().flushExecutor();
        messageCount += getMessageCount(qBinding.getQueue());
    }
    return messageCount;
}
Also used : 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)

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