Search in sources :

Example 6 with ActiveMQAMQPException

use of org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException in project activemq-artemis by apache.

the class AMQPSessionContext method addReceiver.

public void addReceiver(Receiver receiver) throws Exception {
    try {
        ProtonServerReceiverContext protonReceiver = new ProtonServerReceiverContext(sessionSPI, connection, this, receiver);
        protonReceiver.initialise();
        receivers.put(receiver, protonReceiver);
        ServerProducer serverProducer = new ServerProducerImpl(receiver.getName(), "AMQP", receiver.getTarget().getAddress());
        sessionSPI.addProducer(serverProducer);
        receiver.setContext(protonReceiver);
        connection.lock();
        try {
            receiver.open();
        } finally {
            connection.unlock();
        }
    } catch (ActiveMQAMQPException e) {
        receivers.remove(receiver);
        receiver.setTarget(null);
        receiver.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage()));
        connection.lock();
        try {
            receiver.close();
        } finally {
            connection.unlock();
        }
    }
}
Also used : ServerProducerImpl(org.apache.activemq.artemis.core.server.impl.ServerProducerImpl) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) ServerProducer(org.apache.activemq.artemis.core.server.ServerProducer)

Example 7 with ActiveMQAMQPException

use of org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException in project activemq-artemis by apache.

the class AMQPSessionContext method addSender.

public void addSender(Sender sender) throws Exception {
    // TODO: Remove this check when we have support for global link names
    boolean outgoing = (sender.getContext() != null && sender.getContext().equals(true));
    ProtonServerSenderContext protonSender = outgoing ? new ProtonClientSenderContext(connection, sender, this, sessionSPI) : new ProtonServerSenderContext(connection, sender, this, sessionSPI);
    try {
        protonSender.initialise();
        senders.put(sender, protonSender);
        serverSenders.put(protonSender.getBrokerConsumer(), protonSender);
        sender.setContext(protonSender);
        connection.lock();
        try {
            sender.open();
        } finally {
            connection.unlock();
        }
        protonSender.start();
    } catch (ActiveMQAMQPException e) {
        senders.remove(sender);
        sender.setSource(null);
        sender.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage()));
        connection.lock();
        try {
            sender.close();
        } finally {
            connection.unlock();
        }
    }
}
Also used : ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) ProtonClientSenderContext(org.apache.activemq.artemis.protocol.amqp.client.ProtonClientSenderContext) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException)

Example 8 with ActiveMQAMQPException

use of org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException in project activemq-artemis by apache.

the class ProtonServerSenderContext method close.

/*
    * close the session
    */
@Override
public void close(boolean remoteLinkClose) throws ActiveMQAMQPException {
    try {
        closed = true;
        sessionSPI.closeSender(brokerConsumer);
        // any durable resources for say pub subs
        if (remoteLinkClose) {
            Source source = (Source) sender.getSource();
            if (source != null && source.getAddress() != null && multicast) {
                SimpleString queueName = SimpleString.toSimpleString(source.getAddress());
                QueueQueryResult result = sessionSPI.queueQuery(queueName, routingTypeToUse, false);
                if (result.isExists() && source.getDynamic()) {
                    sessionSPI.deleteQueue(queueName);
                } else {
                    if (source.getDurable() == TerminusDurability.NONE && tempQueueName != null && (source.getExpiryPolicy() == TerminusExpiryPolicy.LINK_DETACH || source.getExpiryPolicy() == TerminusExpiryPolicy.SESSION_END)) {
                        sessionSPI.removeTemporaryQueue(tempQueueName);
                    } else {
                        String clientId = getClientId();
                        String pubId = sender.getName();
                        if (pubId.contains("|")) {
                            pubId = pubId.split("\\|")[0];
                        }
                        SimpleString queue = createQueueName(connection.isUseCoreSubscriptionNaming(), clientId, pubId, shared, global, isVolatile);
                        result = sessionSPI.queueQuery(queue, multicast ? RoutingType.MULTICAST : RoutingType.ANYCAST, false);
                        // only delete if it isn't volatile and has no consumers
                        if (result.isExists() && !isVolatile && result.getConsumerCount() == 0) {
                            sessionSPI.deleteQueue(queue);
                        }
                    }
                }
            } else if (source != null && source.getDynamic() && (source.getExpiryPolicy() == TerminusExpiryPolicy.LINK_DETACH || source.getExpiryPolicy() == TerminusExpiryPolicy.SESSION_END)) {
                try {
                    sessionSPI.removeTemporaryQueue(SimpleString.toSimpleString(source.getAddress()));
                } catch (Exception e) {
                // ignore on close, its temp anyway and will be removed later
                }
            }
        }
    } catch (Exception e) {
        log.warn(e.getMessage(), e);
        throw new ActiveMQAMQPInternalErrorException(e.getMessage());
    }
}
Also used : ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Source(org.apache.qpid.proton.amqp.messaging.Source) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) FilterException(org.apache.activemq.artemis.selector.filter.FilterException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) ActiveMQAMQPIllegalStateException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException)

Example 9 with ActiveMQAMQPException

use of org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException in project activemq-artemis by apache.

the class ProtonServerSenderContext method onMessage.

@Override
public void onMessage(Delivery delivery) throws ActiveMQAMQPException {
    if (closed) {
        return;
    }
    OperationContext oldContext = sessionSPI.recoverContext();
    try {
        Message message = ((MessageReference) delivery.getContext()).getMessage();
        boolean preSettle = sender.getRemoteSenderSettleMode() == SenderSettleMode.SETTLED;
        DeliveryState remoteState;
        connection.lock();
        try {
            remoteState = delivery.getRemoteState();
        } finally {
            connection.unlock();
        }
        boolean settleImmediate = true;
        if (remoteState instanceof Accepted) {
            // acking again would show an exception but would have no negative effect but best to handle anyway.
            if (delivery.isSettled()) {
                return;
            }
            // from dealer, a perf hit but a must
            try {
                sessionSPI.ack(null, brokerConsumer, message);
            } catch (Exception e) {
                log.warn(e.toString(), e);
                throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.errorAcknowledgingMessage(message.toString(), e.getMessage());
            }
        } else if (remoteState instanceof TransactionalState) {
            // When the message arrives with a TransactionState disposition the ack should
            // enlist the message into the transaction associated with the given txn ID.
            TransactionalState txState = (TransactionalState) remoteState;
            ProtonTransactionImpl tx = (ProtonTransactionImpl) this.sessionSPI.getTransaction(txState.getTxnId(), false);
            if (txState.getOutcome() != null) {
                settleImmediate = false;
                Outcome outcome = txState.getOutcome();
                if (outcome instanceof Accepted) {
                    if (!delivery.remotelySettled()) {
                        TransactionalState txAccepted = new TransactionalState();
                        txAccepted.setOutcome(Accepted.getInstance());
                        txAccepted.setTxnId(txState.getTxnId());
                        connection.lock();
                        try {
                            delivery.disposition(txAccepted);
                        } finally {
                            connection.unlock();
                        }
                    }
                    // from dealer, a perf hit but a must
                    try {
                        sessionSPI.ack(tx, brokerConsumer, message);
                        tx.addDelivery(delivery, this);
                    } catch (Exception e) {
                        throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.errorAcknowledgingMessage(message.toString(), e.getMessage());
                    }
                }
            }
        } else if (remoteState instanceof Released) {
            try {
                sessionSPI.cancel(brokerConsumer, message, false);
            } catch (Exception e) {
                throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.errorCancellingMessage(message.toString(), e.getMessage());
            }
        } else if (remoteState instanceof Rejected) {
            try {
                sessionSPI.reject(brokerConsumer, message);
            } catch (Exception e) {
                throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.errorCancellingMessage(message.toString(), e.getMessage());
            }
        } else if (remoteState instanceof Modified) {
            try {
                Modified modification = (Modified) remoteState;
                if (Boolean.TRUE.equals(modification.getUndeliverableHere())) {
                    message.rejectConsumer(brokerConsumer.sequentialID());
                }
                if (Boolean.TRUE.equals(modification.getDeliveryFailed())) {
                    sessionSPI.cancel(brokerConsumer, message, true);
                } else {
                    sessionSPI.cancel(brokerConsumer, message, false);
                }
            } catch (Exception e) {
                throw ActiveMQAMQPProtocolMessageBundle.BUNDLE.errorCancellingMessage(message.toString(), e.getMessage());
            }
        } else {
            log.debug("Received null or unknown disposition for delivery update: " + remoteState);
            return;
        }
        if (!preSettle) {
            protonSession.replaceTag(delivery.getTag());
        }
        if (settleImmediate) {
            settle(delivery);
        }
    } finally {
        sessionSPI.afterIO(new IOCallback() {

            @Override
            public void done() {
                connection.flush();
            }

            @Override
            public void onError(int errorCode, String errorMessage) {
                connection.flush();
            }
        });
        sessionSPI.resetContext(oldContext);
    }
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) Released(org.apache.qpid.proton.amqp.messaging.Released) Modified(org.apache.qpid.proton.amqp.messaging.Modified) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) Message(org.apache.activemq.artemis.api.core.Message) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) IOCallback(org.apache.activemq.artemis.core.io.IOCallback) Accepted(org.apache.qpid.proton.amqp.messaging.Accepted) ActiveMQAMQPNotFoundException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) FilterException(org.apache.activemq.artemis.selector.filter.FilterException) ActiveMQAMQPInternalErrorException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) ActiveMQAMQPResourceLimitExceededException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException) ActiveMQAMQPIllegalStateException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) TransactionalState(org.apache.qpid.proton.amqp.transaction.TransactionalState) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) Outcome(org.apache.qpid.proton.amqp.messaging.Outcome) ProtonTransactionImpl(org.apache.activemq.artemis.protocol.amqp.proton.transaction.ProtonTransactionImpl)

Aggregations

ActiveMQAMQPException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException)9 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)5 ActiveMQAMQPInternalErrorException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException)5 ActiveMQAMQPNotFoundException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPNotFoundException)5 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)4 ActiveMQAMQPIllegalStateException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPIllegalStateException)4 ActiveMQAMQPResourceLimitExceededException (org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPResourceLimitExceededException)4 FilterException (org.apache.activemq.artemis.selector.filter.FilterException)4 ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 IOCallback (org.apache.activemq.artemis.core.io.IOCallback)2 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)2 Accepted (org.apache.qpid.proton.amqp.messaging.Accepted)2 Rejected (org.apache.qpid.proton.amqp.messaging.Rejected)2 Source (org.apache.qpid.proton.amqp.messaging.Source)2 TransactionalState (org.apache.qpid.proton.amqp.transaction.TransactionalState)2 Receiver (org.apache.qpid.proton.engine.Receiver)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1