Search in sources :

Example 1 with Binding

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

the class PostOfficeImpl method removeAddressInfo.

@Override
public AddressInfo removeAddressInfo(SimpleString address, boolean force) throws Exception {
    synchronized (addressLock) {
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.beforeRemoveAddress(address));
        }
        final Bindings bindingsForAddress = getDirectBindings(address);
        if (force) {
            for (Binding binding : bindingsForAddress.getBindings()) {
                if (binding instanceof QueueBinding) {
                    ((QueueBinding) binding).getQueue().deleteQueue(true);
                }
            }
        } else {
            if (bindingsForAddress.getBindings().size() > 0) {
                throw ActiveMQMessageBundle.BUNDLE.addressHasBindings(address);
            }
        }
        managementService.unregisterAddress(address);
        final AddressInfo addressInfo = addressManager.removeAddressInfo(address);
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.afterRemoveAddress(address, addressInfo));
        }
        return addressInfo;
    }
}
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) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo)

Example 2 with Binding

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

the class PostOfficeImpl method removeBinding.

@Override
public synchronized Binding removeBinding(final SimpleString uniqueName, Transaction tx, boolean deleteData) throws Exception {
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.beforeRemoveBinding(uniqueName, tx, deleteData));
    }
    addressSettingsRepository.clearCache();
    Binding binding = addressManager.removeBinding(uniqueName, tx);
    if (binding == null) {
        throw new ActiveMQNonExistentQueueException();
    }
    if (deleteData && addressManager.getBindingsForRoutingAddress(binding.getAddress()) == null) {
        pagingManager.deletePageStore(binding.getAddress());
        deleteDuplicateCache(binding.getAddress());
    }
    if (binding.getType() == BindingType.LOCAL_QUEUE) {
        Queue queue = (Queue) binding.getBindable();
        managementService.unregisterQueue(uniqueName, binding.getAddress(), queue.getRoutingType());
    } else if (binding.getType() == BindingType.DIVERT) {
        managementService.unregisterDivert(uniqueName, binding.getAddress());
    }
    if (binding.getType() != BindingType.DIVERT) {
        TypedProperties props = new TypedProperties();
        props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());
        props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
        props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
        props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
        props.putLongProperty(ManagementHelper.HDR_BINDING_ID, binding.getID());
        if (binding.getFilter() == null) {
            props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, null);
        } else {
            props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, binding.getFilter().getFilterString());
        }
        managementService.sendNotification(new Notification(null, CoreNotificationType.BINDING_REMOVED, props));
    }
    binding.close();
    if (server.hasBrokerPlugins()) {
        server.callBrokerPlugins(plugin -> plugin.afterRemoveBinding(binding, tx, deleteData));
    }
    return binding;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) TypedProperties(org.apache.activemq.artemis.utils.collections.TypedProperties) Queue(org.apache.activemq.artemis.core.server.Queue) Notification(org.apache.activemq.artemis.core.server.management.Notification)

Example 3 with Binding

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

the class WildcardAddressManager method removeBinding.

/**
 * If the address is a wild card then the binding will be removed from the actual mappings for any linked address.
 * otherwise it will be removed as normal.
 *
 * @param uniqueName the name of the binding to remove
 * @return true if this was the last mapping for a specific address
 */
@Override
public Binding removeBinding(final SimpleString uniqueName, Transaction tx) throws Exception {
    Binding binding = super.removeBinding(uniqueName, tx);
    if (binding != null) {
        Address add = getAddress(binding.getAddress());
        if (add.containsWildCard()) {
            for (Address theAddress : add.getLinkedAddresses()) {
                super.removeBindingInternal(theAddress.getAddress(), uniqueName);
            }
        }
        removeAndUpdateAddressMap(add);
    }
    return binding;
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) Address(org.apache.activemq.artemis.core.postoffice.Address)

Example 4 with Binding

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

the class BindingsImpl method routeFromCluster.

private void routeFromCluster(final Message message, final RoutingContext context, final byte[] ids) throws Exception {
    byte[] idsToAck = (byte[]) message.removeProperty(Message.HDR_ROUTE_TO_ACK_IDS);
    List<Long> idsToAckList = new ArrayList<>();
    if (idsToAck != null) {
        ByteBuffer buff = ByteBuffer.wrap(idsToAck);
        while (buff.hasRemaining()) {
            long bindingID = buff.getLong();
            idsToAckList.add(bindingID);
        }
    }
    ByteBuffer buff = ByteBuffer.wrap(ids);
    while (buff.hasRemaining()) {
        long bindingID = buff.getLong();
        Binding binding = bindingsMap.get(bindingID);
        if (binding != null) {
            if (idsToAckList.contains(bindingID)) {
                binding.routeWithAck(message, context);
            } else {
                binding.route(message, context);
            }
        } else {
            ActiveMQServerLogger.LOGGER.bindingNotFound(bindingID, message.toString(), this.toString());
        }
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ByteBuffer(java.nio.ByteBuffer)

Example 5 with Binding

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

the class BindingsImpl method route.

private void route(final Message message, final RoutingContext context, final boolean groupRouting) throws Exception {
    /* This is a special treatment for scaled-down messages involving SnF queues.
       * See org.apache.activemq.artemis.core.server.impl.ScaleDownHandler.scaleDownMessages() for the logic that sends messages with this property
       */
    byte[] ids = (byte[]) message.removeExtraBytesProperty(Message.HDR_SCALEDOWN_TO_IDS);
    if (ids != null) {
        ByteBuffer buffer = ByteBuffer.wrap(ids);
        while (buffer.hasRemaining()) {
            long id = buffer.getLong();
            for (Map.Entry<Long, Binding> entry : bindingsMap.entrySet()) {
                if (entry.getValue() instanceof RemoteQueueBinding) {
                    RemoteQueueBinding remoteQueueBinding = (RemoteQueueBinding) entry.getValue();
                    if (remoteQueueBinding.getRemoteQueueID() == id) {
                        message.putBytesProperty(Message.HDR_ROUTE_TO_IDS, ByteBuffer.allocate(8).putLong(remoteQueueBinding.getID()).array());
                    }
                }
            }
        }
    }
    boolean routed = false;
    for (Binding binding : exclusiveBindings) {
        if (binding.getFilter() == null || binding.getFilter().match(message)) {
            binding.getBindable().route(message, context);
            routed = true;
        }
    }
    if (!routed) {
        // Remove the ids now, in order to avoid double check
        ids = message.removeExtraBytesProperty(Message.HDR_ROUTE_TO_IDS);
        // Fetch the groupId now, in order to avoid double checking
        SimpleString groupId = message.getGroupID();
        if (ids != null) {
            routeFromCluster(message, context, ids);
        } else if (groupingHandler != null && groupRouting && groupId != null) {
            routeUsingStrictOrdering(message, context, groupingHandler, groupId, 0);
        } else {
            if (logger.isTraceEnabled()) {
                logger.trace("Routing message " + message + " on binding=" + this);
            }
            for (Map.Entry<SimpleString, List<Binding>> entry : routingNameBindingMap.entrySet()) {
                SimpleString routingName = entry.getKey();
                List<Binding> bindings = entry.getValue();
                if (bindings == null) {
                    // ConcurrentHashMap behaviour!
                    continue;
                }
                Binding theBinding = getNextBinding(message, routingName, bindings);
                if (theBinding != null) {
                    theBinding.route(message, context);
                }
            }
        }
    }
}
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) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ByteBuffer(java.nio.ByteBuffer) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RemoteQueueBinding(org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding)

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