Search in sources :

Example 26 with Error

use of org.apache.qpid.server.protocol.v1_0.type.transport.Error 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 27 with Error

use of org.apache.qpid.server.protocol.v1_0.type.transport.Error in project qpid-broker-j by apache.

the class SendingLinkEndpoint method createConsumerTarget.

private void createConsumerTarget() throws AmqpErrorException {
    final Source source = getSource();
    _consumerTarget = new ConsumerTarget_1_0(this, _destination instanceof ExchangeSendingDestination || source.getDistributionMode() != StdDistMode.COPY);
    try {
        final String name = getTarget().getAddress() == null ? getLinkName() : getTarget().getAddress();
        _consumer = _destination.getMessageSource().addConsumer(_consumerTarget, _consumerFilters, Message_1_0.class, name, _consumerOptions, getPriority());
        _consumerTarget.updateNotifyWorkDesired();
    } catch (MessageSource.ExistingExclusiveConsumer e) {
        String msg = "Cannot add a consumer to the destination as there is already an exclusive consumer";
        throw new AmqpErrorException(new Error(AmqpError.RESOURCE_LOCKED, msg), e);
    } catch (MessageSource.ExistingConsumerPreventsExclusive e) {
        String msg = "Cannot add an exclusive consumer to the destination as there is already a consumer";
        throw new AmqpErrorException(new Error(AmqpError.RESOURCE_LOCKED, msg), e);
    } catch (MessageSource.ConsumerAccessRefused e) {
        String msg = "Cannot add an exclusive consumer to the destination as there is an incompatible exclusivity policy";
        throw new AmqpErrorException(new Error(AmqpError.RESOURCE_LOCKED, msg), e);
    } catch (MessageSource.QueueDeleted e) {
        String msg = "Cannot add a consumer to the destination as the destination has been deleted";
        throw new AmqpErrorException(new Error(AmqpError.RESOURCE_DELETED, msg), e);
    }
}
Also used : MessageSource(org.apache.qpid.server.message.MessageSource) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) 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) 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)

Example 28 with Error

use of org.apache.qpid.server.protocol.v1_0.type.transport.Error in project qpid-broker-j by apache.

the class SendingLinkEndpoint method receiveFlow.

@Override
public void receiveFlow(final Flow flow) {
    UnsignedInteger receiverDeliveryCount = flow.getDeliveryCount();
    UnsignedInteger receiverLinkCredit = flow.getLinkCredit();
    setDrain(flow.getDrain());
    Map<Symbol, Object> properties = flow.getProperties();
    if (properties != null) {
        final Binary transactionId = (Binary) properties.get(Symbol.valueOf("txn-id"));
        if (transactionId != null) {
            try {
                getSession().getTransaction(transactionId);
            } catch (UnknownTransactionException e) {
                close(new Error(TransactionError.UNKNOWN_ID, e.getMessage()));
                return;
            }
        }
        _transactionId = transactionId;
    }
    if (receiverDeliveryCount == null) {
        setLinkCredit(receiverLinkCredit);
    } else {
        // 2.6.7 Flow Control : link_credit_snd := delivery_count_rcv + link_credit_rcv - delivery_count_snd
        UnsignedInteger limit = receiverDeliveryCount.add(receiverLinkCredit);
        if (limit.compareTo(getDeliveryCount().unsignedIntegerValue()) <= 0) {
            setLinkCredit(UnsignedInteger.valueOf(0));
        } else {
            setLinkCredit(limit.subtract(getDeliveryCount().unsignedIntegerValue()));
        }
    }
    // send flow when echo=true or drain=true but link credit is zero
    boolean sendFlow = Boolean.TRUE.equals(flow.getEcho()) || (Boolean.TRUE.equals(flow.getDrain()) && getLinkCredit().equals(UnsignedInteger.ZERO));
    flowStateChanged();
    if (sendFlow) {
        sendFlow();
    }
}
Also used : Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) 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) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 29 with Error

use of org.apache.qpid.server.protocol.v1_0.type.transport.Error in project qpid-broker-j by apache.

the class Session_1_0 method end.

public void end(final End end) {
    switch(_sessionState) {
        case BEGIN_SENT:
            _connection.sendEnd(_sendingChannel, end, false);
            _sessionState = SessionState.END_PIPE;
            break;
        case ACTIVE:
            detachLinks();
            _connection.sendEnd(_sendingChannel, end, true);
            _sessionState = SessionState.END_SENT;
            break;
        default:
            End reply = new End();
            Error error = new Error();
            error.setCondition(AmqpError.ILLEGAL_STATE);
            error.setDescription("END called on Session which has not been opened");
            reply.setError(error);
            _connection.sendEnd(_sendingChannel, reply, true);
            break;
    }
}
Also used : Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) SessionError(org.apache.qpid.server.protocol.v1_0.type.transport.SessionError) LinkError(org.apache.qpid.server.protocol.v1_0.type.transport.LinkError) End(org.apache.qpid.server.protocol.v1_0.type.transport.End)

Example 30 with Error

use of org.apache.qpid.server.protocol.v1_0.type.transport.Error in project qpid-broker-j by apache.

the class StandardReceivingLinkEndpoint method recoverLink.

@Override
protected void recoverLink(final Attach attach) throws AmqpErrorException {
    if (getTarget() == null) {
        throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, String.format("Link '%s' not found", getLinkName())));
    }
    attach.setTarget(getTarget());
    receiveAttach(attach);
}
Also used : AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)

Aggregations

Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)49 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)40 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)30 Test (org.junit.Test)30 FrameTransport (org.apache.qpid.tests.protocol.v1_0.FrameTransport)28 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)22 Interaction (org.apache.qpid.tests.protocol.v1_0.Interaction)17 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)15 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)15 Detach (org.apache.qpid.server.protocol.v1_0.type.transport.Detach)15 End (org.apache.qpid.server.protocol.v1_0.type.transport.End)15 Attach (org.apache.qpid.server.protocol.v1_0.type.transport.Attach)14 Close (org.apache.qpid.server.protocol.v1_0.type.transport.Close)14 Disposition (org.apache.qpid.server.protocol.v1_0.type.transport.Disposition)14 Open (org.apache.qpid.server.protocol.v1_0.type.transport.Open)13 Begin (org.apache.qpid.server.protocol.v1_0.type.transport.Begin)12 Flow (org.apache.qpid.server.protocol.v1_0.type.transport.Flow)12 LinkError (org.apache.qpid.server.protocol.v1_0.type.transport.LinkError)12 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)11 InetSocketAddress (java.net.InetSocketAddress)10