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);
}
}
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;
}
}
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();
}
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);
}
}
Aggregations