Search in sources :

Example 1 with TopicExchangeResult

use of org.apache.qpid.server.exchange.topic.TopicExchangeResult in project qpid-broker-j by apache.

the class TopicExchangeImpl method bind.

private synchronized void bind(final BindingIdentifier binding, Map<String, Object> arguments) throws AMQInvalidArgumentException {
    final String bindingKey = binding.getBindingKey();
    MessageDestination messageDestination = binding.getDestination();
    LOGGER.debug("Registering messageDestination {} with routing key {}", messageDestination.getName(), bindingKey);
    String routingKey = TopicNormalizer.normalize(bindingKey);
    TopicExchangeResult result = _topicExchangeResults.get(routingKey);
    if (_bindings.containsKey(binding)) {
        updateTopicExchangeResult(result, binding, arguments);
    } else {
        if (result == null) {
            result = new TopicExchangeResult();
            if (FilterSupport.argumentsContainFilter(arguments)) {
                result.addFilteredDestination(messageDestination, FilterSupport.createMessageFilter(arguments, messageDestination));
            } else {
                result.addUnfilteredDestination(messageDestination);
            }
            _parser.addBinding(routingKey, result);
            _topicExchangeResults.put(routingKey, result);
        } else {
            if (FilterSupport.argumentsContainFilter(arguments)) {
                result.addFilteredDestination(messageDestination, FilterSupport.createMessageFilter(arguments, messageDestination));
            } else {
                result.addUnfilteredDestination(messageDestination);
            }
        }
        _bindings.put(binding, arguments);
        result.addBinding(binding, arguments);
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) TopicExchangeResult(org.apache.qpid.server.exchange.topic.TopicExchangeResult)

Example 2 with TopicExchangeResult

use of org.apache.qpid.server.exchange.topic.TopicExchangeResult in project qpid-broker-j by apache.

the class TopicExchangeImpl method unbind.

private synchronized boolean unbind(final BindingIdentifier binding) {
    if (_bindings.containsKey(binding)) {
        Map<String, Object> bindingArgs = _bindings.remove(binding);
        LOGGER.debug("deregisterQueue args: {}", bindingArgs);
        String bindingKey = TopicNormalizer.normalize(binding.getBindingKey());
        TopicExchangeResult result = _topicExchangeResults.get(bindingKey);
        result.removeBinding(binding);
        if (FilterSupport.argumentsContainFilter(bindingArgs)) {
            try {
                result.removeFilteredDestination(binding.getDestination(), FilterSupport.createMessageFilter(bindingArgs, binding.getDestination()));
            } catch (AMQInvalidArgumentException e) {
                return false;
            }
        } else {
            result.removeUnfilteredDestination(binding.getDestination());
        }
        // shall we delete the result from _topicExchangeResults if result is empty?
        return true;
    } else {
        return false;
    }
}
Also used : AMQInvalidArgumentException(org.apache.qpid.server.filter.AMQInvalidArgumentException) TopicExchangeResult(org.apache.qpid.server.exchange.topic.TopicExchangeResult)

Example 3 with TopicExchangeResult

use of org.apache.qpid.server.exchange.topic.TopicExchangeResult 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 4 with TopicExchangeResult

use of org.apache.qpid.server.exchange.topic.TopicExchangeResult in project qpid-broker-j by apache.

the class TopicExchangeImpl method onBindingUpdated.

@Override
protected synchronized void onBindingUpdated(final BindingIdentifier binding, final Map<String, Object> newArguments) throws AMQInvalidArgumentException {
    final String bindingKey = binding.getBindingKey();
    final MessageDestination destination = binding.getDestination();
    LOGGER.debug("Updating binding of queue {} with routing key {}", destination.getName(), bindingKey);
    String routingKey = TopicNormalizer.normalize(bindingKey);
    if (_bindings.containsKey(binding)) {
        TopicExchangeResult result = _topicExchangeResults.get(routingKey);
        updateTopicExchangeResult(result, binding, newArguments);
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) TopicExchangeResult(org.apache.qpid.server.exchange.topic.TopicExchangeResult)

Aggregations

TopicExchangeResult (org.apache.qpid.server.exchange.topic.TopicExchangeResult)4 MessageDestination (org.apache.qpid.server.message.MessageDestination)3 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TopicMatcherResult (org.apache.qpid.server.exchange.topic.TopicMatcherResult)1 AMQInvalidArgumentException (org.apache.qpid.server.filter.AMQInvalidArgumentException)1