Search in sources :

Example 1 with TopicMatcherResult

use of org.apache.qpid.server.exchange.topic.TopicMatcherResult 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)

Aggregations

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