Search in sources :

Example 1 with JMSSelectorFilter

use of org.apache.qpid.server.filter.JMSSelectorFilter 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;
}
Also used : ConsumerOption(org.apache.qpid.server.consumer.ConsumerOption) MessageSource(org.apache.qpid.server.message.MessageSource) BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) FilterManager(org.apache.qpid.server.filter.FilterManager) SelectorParsingException(org.apache.qpid.server.filter.SelectorParsingException) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Queue(org.apache.qpid.server.model.Queue) JMSSelectorFilter(org.apache.qpid.server.filter.JMSSelectorFilter) NoLocalFilter(org.apache.qpid.server.protocol.v1_0.type.messaging.NoLocalFilter) MessageSource(org.apache.qpid.server.message.MessageSource) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) ParseException(org.apache.qpid.server.filter.selector.ParseException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 2 with JMSSelectorFilter

use of org.apache.qpid.server.filter.JMSSelectorFilter in project qpid-broker-j by apache.

the class QueueConsumerImpl method createAttributeMap.

private static Map<String, Object> createAttributeMap(final AMQPSession<?, ?> session, String linkName, FilterManager filters, EnumSet<ConsumerOption> optionSet, Integer priority) {
    Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put(ID, UUID.randomUUID());
    String name = session.getAMQPConnection().getConnectionId() + "|" + session.getChannelId() + "|" + linkName;
    attributes.put(NAME, name);
    attributes.put(EXCLUSIVE, optionSet.contains(ConsumerOption.EXCLUSIVE));
    attributes.put(NO_LOCAL, optionSet.contains(ConsumerOption.NO_LOCAL));
    attributes.put(DISTRIBUTION_MODE, optionSet.contains(ConsumerOption.ACQUIRES) ? "MOVE" : "COPY");
    attributes.put(DURABLE, optionSet.contains(ConsumerOption.DURABLE));
    attributes.put(LIFETIME_POLICY, LifetimePolicy.DELETE_ON_SESSION_END);
    if (priority != null) {
        attributes.put(PRIORITY, priority);
    }
    if (filters != null) {
        Iterator<MessageFilter> iter = filters.filters();
        while (iter.hasNext()) {
            MessageFilter filter = iter.next();
            if (filter instanceof JMSSelectorFilter) {
                attributes.put(SELECTOR, ((JMSSelectorFilter) filter).getSelector());
                break;
            }
        }
    }
    return attributes;
}
Also used : JMSSelectorFilter(org.apache.qpid.server.filter.JMSSelectorFilter) HashMap(java.util.HashMap) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) MessageFilter(org.apache.qpid.server.filter.MessageFilter)

Aggregations

HashMap (java.util.HashMap)2 JMSSelectorFilter (org.apache.qpid.server.filter.JMSSelectorFilter)2 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 ConsumerOption (org.apache.qpid.server.consumer.ConsumerOption)1 FilterManager (org.apache.qpid.server.filter.FilterManager)1 MessageFilter (org.apache.qpid.server.filter.MessageFilter)1 SelectorParsingException (org.apache.qpid.server.filter.SelectorParsingException)1 ParseException (org.apache.qpid.server.filter.selector.ParseException)1 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)1 MessageSource (org.apache.qpid.server.message.MessageSource)1 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)1 Queue (org.apache.qpid.server.model.Queue)1 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)1 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)1 NoLocalFilter (org.apache.qpid.server.protocol.v1_0.type.messaging.NoLocalFilter)1 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)1 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)1 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)1