Search in sources :

Example 31 with MessageDestination

use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.

the class AbstractExchange method bind.

@Override
public boolean bind(final String destination, String bindingKey, Map<String, Object> arguments, boolean replaceExistingArguments) {
    MessageDestination messageDestination = getAttainedMessageDestination(destination);
    if (messageDestination == null) {
        throw new IllegalArgumentException(String.format("Destination '%s' is not found.", destination));
    }
    if (bindingKey == null) {
        bindingKey = "";
    }
    if (arguments == null) {
        arguments = Collections.emptyMap();
    }
    Binding newBinding = new BindingImpl(bindingKey, destination, arguments);
    boolean modified = false;
    for (Binding b : _bindings) {
        if (b.getBindingKey().equals(bindingKey) && b.getDestination().equals(messageDestination.getName())) {
            if (replaceExistingArguments) {
                _bindings.remove(b);
                modified = true;
                break;
            } else {
                return false;
            }
        }
    }
    _bindings.add(newBinding);
    if (isDurable() && messageDestination.isDurable()) {
        final Collection<Binding> durableBindings = getDurableBindings();
        attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
    }
    final BindingIdentifier bindingIdentifier = new BindingIdentifier(bindingKey, messageDestination);
    if (modified) {
        onBindingUpdated(bindingIdentifier, arguments);
    } else {
        final Map<String, Object> bindArguments = BIND_ARGUMENTS_CREATOR.createMap(bindingKey, destination, arguments);
        getEventLogger().message(_logSubject, BindingMessages.CREATED(String.valueOf(bindArguments)));
        onBind(bindingIdentifier, arguments);
        messageDestination.linkAdded(this, newBinding);
    }
    return true;
}
Also used : Binding(org.apache.qpid.server.model.Binding) AlternateBinding(org.apache.qpid.server.model.AlternateBinding) BindingImpl(org.apache.qpid.server.binding.BindingImpl) MessageDestination(org.apache.qpid.server.message.MessageDestination) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Example 32 with MessageDestination

use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.

the class FanoutExchangeImpl method doRoute.

@Override
protected <M extends ServerMessage<? extends StorableMessageMetaData>> void doRoute(final M message, final String routingAddress, final InstanceProperties instanceProperties, final RoutingResult<M> result) {
    BindingSet bindingSet = _bindingSet;
    if (!bindingSet._unfilteredDestinations.isEmpty()) {
        for (MessageDestination destination : bindingSet._unfilteredDestinations.keySet()) {
            Set<String> replacementRoutingKeys = new HashSet<>(bindingSet._unfilteredDestinations.get(destination).values());
            replacementRoutingKeys.forEach(replacementRoutingKey -> result.add(destination.route(message, replacementRoutingKey == null ? routingAddress : replacementRoutingKey, instanceProperties)));
        }
    }
    final Map<MessageDestination, Map<BindingIdentifier, FilterManagerReplacementRoutingKeyTuple>> filteredDestinations = bindingSet._filteredDestinations;
    if (!filteredDestinations.isEmpty()) {
        for (Map.Entry<MessageDestination, Map<BindingIdentifier, FilterManagerReplacementRoutingKeyTuple>> entry : filteredDestinations.entrySet()) {
            MessageDestination destination = entry.getKey();
            final Map<BindingIdentifier, FilterManagerReplacementRoutingKeyTuple> bindingMessageFilterMap = entry.getValue();
            for (FilterManagerReplacementRoutingKeyTuple tuple : bindingMessageFilterMap.values()) {
                FilterManager filter = tuple.getFilterManager();
                if (filter.allAllow(Filterable.Factory.newInstance(message, instanceProperties))) {
                    String routingKey = tuple.getReplacementRoutingKey() == null ? routingAddress : tuple.getReplacementRoutingKey();
                    result.add(destination.route(message, routingKey, instanceProperties));
                }
            }
        }
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) FilterManager(org.apache.qpid.server.filter.FilterManager)

Example 33 with MessageDestination

use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.

the class HeadersExchangeImpl method doRoute.

@Override
public <M extends ServerMessage<? extends StorableMessageMetaData>> void doRoute(M payload, String routingKey, final InstanceProperties instanceProperties, RoutingResult<M> routingResult) {
    LOGGER.debug("Exchange {}: routing message with headers {}", getName(), payload.getMessageHeader());
    for (HeadersBinding hb : _bindingHeaderMatchers) {
        if (hb.matches(Filterable.Factory.newInstance(payload, instanceProperties))) {
            MessageDestination destination = hb.getBinding().getDestination();
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Exchange '{}' delivering message with headers '{}' to '{}'", getName(), payload.getMessageHeader(), destination.getName());
            }
            String actualRoutingKey = hb.getReplacementRoutingKey() == null ? routingKey : hb.getReplacementRoutingKey();
            routingResult.add(destination.route(payload, actualRoutingKey, instanceProperties));
        }
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination)

Example 34 with MessageDestination

use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.

the class TopicExchangeImpl method getMatchedDestinations.

private Map<MessageDestination, Set<String>> getMatchedDestinations(Filterable message, String routingKey) {
    Collection<TopicMatcherResult> results = _parser.parse(routingKey);
    if (!results.isEmpty()) {
        Map<MessageDestination, Set<String>> matchedDestinations = new HashMap<>();
        for (TopicMatcherResult result : results) {
            TopicExchangeResult topicExchangeResult = (TopicExchangeResult) result;
            Map<MessageDestination, String> destinations = topicExchangeResult.processMessage(message);
            if (!destinations.isEmpty()) {
                destinations.forEach((destination, replacementKey) -> {
                    Set<String> currentKeys = matchedDestinations.get(destination);
                    if (currentKeys == null) {
                        matchedDestinations.put(destination, Collections.singleton(replacementKey));
                    } else if (!currentKeys.contains(replacementKey)) {
                        Set<String> newKeys = new HashSet<>(currentKeys);
                        newKeys.add(replacementKey);
                        matchedDestinations.put(destination, newKeys);
                    }
                });
            }
        }
        return matchedDestinations;
    }
    return Collections.emptyMap();
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) TopicMatcherResult(org.apache.qpid.server.exchange.topic.TopicMatcherResult) TopicExchangeResult(org.apache.qpid.server.exchange.topic.TopicExchangeResult)

Example 35 with MessageDestination

use of org.apache.qpid.server.message.MessageDestination in project qpid-broker-j by apache.

the class TopicExchangeImpl method doRoute.

@Override
public <M extends ServerMessage<? extends StorableMessageMetaData>> void doRoute(M payload, String routingAddress, InstanceProperties instanceProperties, RoutingResult<M> result) {
    final String routingKey = routingAddress == null ? "" : routingAddress;
    final Map<MessageDestination, Set<String>> matchedDestinations = getMatchedDestinations(Filterable.Factory.newInstance(payload, instanceProperties), routingKey);
    for (Map.Entry<MessageDestination, Set<String>> entry : matchedDestinations.entrySet()) {
        MessageDestination destination = entry.getKey();
        Set<String> replacementKeys = entry.getValue();
        replacementKeys.forEach(replacementKey -> result.add(destination.route(payload, replacementKey == null ? routingAddress : replacementKey, instanceProperties)));
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MessageDestination (org.apache.qpid.server.message.MessageDestination)40 DestinationAddress (org.apache.qpid.server.model.DestinationAddress)11 Queue (org.apache.qpid.server.model.Queue)11 Exchange (org.apache.qpid.server.model.Exchange)10 HashMap (java.util.HashMap)6 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)6 Map (java.util.Map)5 AlternateBinding (org.apache.qpid.server.model.AlternateBinding)5 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)5 AccessControlException (java.security.AccessControlException)4 HashSet (java.util.HashSet)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 RoutingResult (org.apache.qpid.server.message.RoutingResult)4 Binding (org.apache.qpid.server.model.Binding)4 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)4 Set (java.util.Set)3 TopicExchangeResult (org.apache.qpid.server.exchange.topic.TopicExchangeResult)3 InstanceProperties (org.apache.qpid.server.message.InstanceProperties)3 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)3 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)3