Search in sources :

Example 51 with Binding

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

the class PostOfficeImpl method sendQueueInfoToQueue.

@Override
public void sendQueueInfoToQueue(final SimpleString queueName, final SimpleString address) throws Exception {
    // We send direct to the queue so we can send it to the same queue that is bound to the notifications address -
    // this is crucial for ensuring
    // that queue infos and notifications are received in a contiguous consistent stream
    Binding binding = addressManager.getBinding(queueName);
    if (binding == null) {
        throw new IllegalStateException("Cannot find queue " + queueName);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("PostOffice.sendQueueInfoToQueue on server=" + this.server + ", queueName=" + queueName + " and address=" + address);
    }
    Queue queue = (Queue) binding.getBindable();
    // Need to lock to make sure all queue info and notifications are in the correct order with no gaps
    synchronized (notificationLock) {
        // First send a reset message
        Message message = new CoreMessage(storageManager.generateID(), 50);
        message.setAddress(queueName);
        message.putBooleanProperty(PostOfficeImpl.HDR_RESET_QUEUE_DATA, true);
        routeQueueInfo(message, queue, false);
        for (QueueInfo info : queueInfos.values()) {
            if (logger.isTraceEnabled()) {
                logger.trace("QueueInfo on sendQueueInfoToQueue = " + info);
            }
            if (info.matchesAddress(address)) {
                message = createQueueInfoMessage(CoreNotificationType.BINDING_ADDED, queueName);
                message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
                message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
                message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
                message.putLongProperty(ManagementHelper.HDR_BINDING_ID, info.getID());
                message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, info.getFilterString());
                message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
                routeQueueInfo(message, queue, true);
                int consumersWithFilters = info.getFilterStrings() != null ? info.getFilterStrings().size() : 0;
                for (int i = 0; i < info.getNumberOfConsumers() - consumersWithFilters; i++) {
                    message = createQueueInfoMessage(CoreNotificationType.CONSUMER_CREATED, queueName);
                    message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
                    message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
                    message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
                    message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
                    routeQueueInfo(message, queue, true);
                }
                if (info.getFilterStrings() != null) {
                    for (SimpleString filterString : info.getFilterStrings()) {
                        message = createQueueInfoMessage(CoreNotificationType.CONSUMER_CREATED, queueName);
                        message.putStringProperty(ManagementHelper.HDR_ADDRESS, info.getAddress());
                        message.putStringProperty(ManagementHelper.HDR_CLUSTER_NAME, info.getClusterName());
                        message.putStringProperty(ManagementHelper.HDR_ROUTING_NAME, info.getRoutingName());
                        message.putStringProperty(ManagementHelper.HDR_FILTERSTRING, filterString);
                        message.putIntProperty(ManagementHelper.HDR_DISTANCE, info.getDistance());
                        routeQueueInfo(message, queue, true);
                    }
                }
            }
        }
        Message completeMessage = new CoreMessage(storageManager.generateID(), 50);
        completeMessage.setAddress(queueName);
        completeMessage.putBooleanProperty(PostOfficeImpl.HDR_RESET_QUEUE_DATA_COMPLETE, true);
        routeQueueInfo(completeMessage, queue, false);
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) QueueInfo(org.apache.activemq.artemis.core.postoffice.QueueInfo) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Example 52 with Binding

use of org.apache.activemq.artemis.core.postoffice.Binding 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)

Example 53 with Binding

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

the class WildcardAddressManager method getBindingsForRoutingAddress.

@Override
public Bindings getBindingsForRoutingAddress(final SimpleString address) throws Exception {
    Bindings bindings = super.getBindingsForRoutingAddress(address);
    // this should only happen if we're routing to an address that has no mappings when we're running checkAllowable
    if (bindings == null && !wildCardAddresses.isEmpty()) {
        Address add = addAndUpdateAddressMap(address);
        if (!add.containsWildCard()) {
            for (Address destAdd : add.getLinkedAddresses()) {
                Bindings b = super.getBindingsForRoutingAddress(destAdd.getAddress());
                if (b != null) {
                    Collection<Binding> theBindings = b.getBindings();
                    for (Binding theBinding : theBindings) {
                        super.addMappingInternal(address, theBinding);
                    }
                    super.getBindingsForRoutingAddress(address).setMessageLoadBalancingType(b.getMessageLoadBalancingType());
                }
            }
        }
        bindings = super.getBindingsForRoutingAddress(address);
    }
    return bindings;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) Address(org.apache.activemq.artemis.core.postoffice.Address) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings)

Example 54 with Binding

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

the class SimpleAddressManager method removeMapping.

protected Binding removeMapping(final SimpleString bindableName, final Bindings bindings) {
    Binding theBinding = null;
    for (Binding binding : bindings.getBindings()) {
        if (binding.getUniqueName().equals(CompositeAddress.extractQueueName(bindableName))) {
            theBinding = binding;
            break;
        }
    }
    if (theBinding == null) {
        throw new IllegalStateException("Cannot find binding " + bindableName);
    }
    bindings.removeBinding(theBinding);
    return theBinding;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding)

Example 55 with Binding

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

the class BindingsImpl method removeBinding.

@Override
public void removeBinding(final Binding binding) {
    if (binding.isExclusive()) {
        exclusiveBindings.remove(binding);
    } else {
        SimpleString routingName = binding.getRoutingName();
        List<Binding> bindings = routingNameBindingMap.get(routingName);
        if (bindings != null) {
            bindings.remove(binding);
            if (bindings.isEmpty()) {
                routingNameBindingMap.remove(routingName);
            }
        }
    }
    bindingsMap.remove(binding.getID());
    if (logger.isTraceEnabled()) {
        logger.trace("Removing binding " + binding + " from " + this + " bindingTable: " + debugBindings());
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Aggregations

Binding (org.apache.activemq.artemis.core.postoffice.Binding)81 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)52 LocalQueueBinding (org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding)29 QueueBinding (org.apache.activemq.artemis.core.postoffice.QueueBinding)28 Test (org.junit.Test)25 Bindings (org.apache.activemq.artemis.core.postoffice.Bindings)24 Queue (org.apache.activemq.artemis.core.server.Queue)24 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)18 RemoteQueueBinding (org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)17 ArrayList (java.util.ArrayList)12 Filter (org.apache.activemq.artemis.core.filter.Filter)10 DivertBinding (org.apache.activemq.artemis.core.postoffice.impl.DivertBinding)10 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)9 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)9 Map (java.util.Map)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)8 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)7 PostOffice (org.apache.activemq.artemis.core.postoffice.PostOffice)7 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)7