use of org.apache.qpid.server.filter.selector.TokenMgrError in project qpid-broker-j by apache.
the class SendingLinkEndpoint method prepareConsumerOptionsAndFilters.
private void prepareConsumerOptionsAndFilters(final SendingDestination destination) throws AmqpErrorException {
// TODO QPID-7952: this method might modify the source. this is not good encapsulation. furthermore if it does so then it should inform the link/linkregistry about it!
_destination = destination;
final Source source = getSource();
EnumSet<ConsumerOption> options = EnumSet.noneOf(ConsumerOption.class);
boolean noLocal = false;
JMSSelectorFilter messageFilter = null;
if (destination instanceof ExchangeSendingDestination) {
options.add(ConsumerOption.ACQUIRES);
options.add(ConsumerOption.SEES_REQUEUES);
} else if (destination instanceof StandardSendingDestination) {
MessageSource messageSource = _destination.getMessageSource();
if (messageSource instanceof Queue && ((Queue<?>) messageSource).getAvailableAttributes().contains("topic")) {
source.setDistributionMode(StdDistMode.COPY);
}
Map<Symbol, Filter> filters = source.getFilter();
Map<Symbol, Filter> actualFilters = new HashMap<>();
if (filters != null) {
for (Map.Entry<Symbol, Filter> entry : filters.entrySet()) {
if (entry.getValue() instanceof NoLocalFilter) {
actualFilters.put(entry.getKey(), entry.getValue());
noLocal = true;
} else if (messageFilter == null && entry.getValue() instanceof org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) {
org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter selectorFilter = (org.apache.qpid.server.protocol.v1_0.type.messaging.JMSSelectorFilter) entry.getValue();
try {
messageFilter = new JMSSelectorFilter(selectorFilter.getValue());
actualFilters.put(entry.getKey(), entry.getValue());
} catch (ParseException | SelectorParsingException | TokenMgrError e) {
Error error = new Error();
error.setCondition(AmqpError.INVALID_FIELD);
error.setDescription("Invalid JMS Selector: " + selectorFilter.getValue());
error.setInfo(Collections.singletonMap(Symbol.valueOf("field"), Symbol.valueOf("filter")));
throw new AmqpErrorException(error);
}
}
}
}
source.setFilter(actualFilters.isEmpty() ? null : actualFilters);
if (source.getDistributionMode() != StdDistMode.COPY) {
options.add(ConsumerOption.ACQUIRES);
options.add(ConsumerOption.SEES_REQUEUES);
}
} else {
throw new ConnectionScopedRuntimeException("Unknown destination type");
}
if (noLocal) {
options.add(ConsumerOption.NO_LOCAL);
}
FilterManager filters = null;
if (messageFilter != null) {
filters = new FilterManager();
filters.add(messageFilter.getName(), messageFilter);
}
_consumerOptions = options;
_consumerFilters = filters;
}
Aggregations