Search in sources :

Example 16 with AmqpErrorException

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

the class SendingLinkEndpoint method recoverLink.

@Override
protected void recoverLink(final Attach attach) throws AmqpErrorException {
    Source source = getSource();
    if (source == null && attach.getDesiredCapabilities() != null) {
        List<Symbol> capabilities = Arrays.asList(attach.getDesiredCapabilities());
        if (capabilities.contains(Session_1_0.GLOBAL_CAPABILITY) && capabilities.contains(Session_1_0.SHARED_CAPABILITY) && getLinkName().endsWith("|global")) {
            NamedAddressSpace namedAddressSpace = getSession().getConnection().getAddressSpace();
            Collection<Link_1_0<? extends BaseSource, ? extends BaseTarget>> links = namedAddressSpace.findSendingLinks(ANY_CONTAINER_ID, Pattern.compile("^" + Pattern.quote(getLinkName()) + "$"));
            for (Link_1_0<? extends BaseSource, ? extends BaseTarget> link : links) {
                BaseSource baseSource = link.getSource();
                if (baseSource instanceof Source) {
                    Source linkSource = (Source) baseSource;
                    source = new Source(linkSource);
                    getLink().setSource(source);
                    break;
                }
            }
        }
    }
    if (source == null) {
        throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, ""));
    }
    attach.setSource(source);
    receiveAttach(attach);
}
Also used : BaseSource(org.apache.qpid.server.protocol.v1_0.type.BaseSource) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) 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) BaseTarget(org.apache.qpid.server.protocol.v1_0.type.BaseTarget)

Example 17 with AmqpErrorException

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

the class SendingLinkEndpoint method attachReceived.

@Override
public void attachReceived(final Attach attach) throws AmqpErrorException {
    super.attachReceived(attach);
    Target target = (Target) attach.getTarget();
    Source source = getSource();
    if (source == null) {
        source = new Source();
        Source attachSource = (Source) attach.getSource();
        final Modified defaultOutcome = new Modified();
        defaultOutcome.setDeliveryFailed(true);
        source.setDefaultOutcome(defaultOutcome);
        source.setOutcomes(Accepted.ACCEPTED_SYMBOL, Released.RELEASED_SYMBOL, Rejected.REJECTED_SYMBOL);
        source.setAddress(attachSource.getAddress());
        source.setDynamic(attachSource.getDynamic());
        if (Boolean.TRUE.equals(attachSource.getDynamic()) && attachSource.getDynamicNodeProperties() != null) {
            Map<Symbol, Object> dynamicNodeProperties = new HashMap<>();
            if (attachSource.getDynamicNodeProperties().containsKey(Session_1_0.LIFETIME_POLICY)) {
                dynamicNodeProperties.put(Session_1_0.LIFETIME_POLICY, attachSource.getDynamicNodeProperties().get(Session_1_0.LIFETIME_POLICY));
            }
            source.setDynamicNodeProperties(dynamicNodeProperties);
        }
        source.setDurable(TerminusDurability.min(attachSource.getDurable(), getLink().getHighestSupportedTerminusDurability()));
        source.setExpiryPolicy(attachSource.getExpiryPolicy());
        source.setDistributionMode(attachSource.getDistributionMode());
        source.setFilter(attachSource.getFilter());
        source.setCapabilities(attachSource.getCapabilities());
        final SendingDestination destination = getSession().getSendingDestination(getLink(), source);
        source.setCapabilities(destination.getCapabilities());
        getLink().setSource(source);
        prepareConsumerOptionsAndFilters(destination);
    }
    getLink().setTarget(target);
    final MessageInstanceConsumer oldConsumer = getConsumer();
    createConsumerTarget();
    _resumeAcceptedTransfers.clear();
    _resumeFullTransfers.clear();
    final NamedAddressSpace addressSpace = getSession().getConnection().getAddressSpace();
    // TODO: QPID-7845 : Resuming links is unsupported at the moment. Thus, cleaning up unsettled deliveries unconditionally.
    cleanUpUnsettledDeliveries();
    getSession().addDeleteTask(_cleanUpUnsettledDeliveryTask);
    Map<Binary, OutgoingDelivery> unsettledCopy = new HashMap<>(_unsettled);
    Map<Binary, DeliveryState> remoteUnsettled = attach.getUnsettled() == null ? Collections.emptyMap() : new HashMap<>(attach.getUnsettled());
    final boolean isUnsettledComplete = !Boolean.TRUE.equals(attach.getIncompleteUnsettled());
    for (Map.Entry<Binary, OutgoingDelivery> entry : unsettledCopy.entrySet()) {
        Binary deliveryTag = entry.getKey();
        final MessageInstance queueEntry = entry.getValue().getMessageInstance();
        if (!remoteUnsettled.containsKey(deliveryTag) && isUnsettledComplete) {
            queueEntry.setRedelivered();
            queueEntry.release(oldConsumer);
            _unsettled.remove(deliveryTag);
        } else if (remoteUnsettled.get(deliveryTag) instanceof Outcome) {
            Outcome outcome = (Outcome) remoteUnsettled.get(deliveryTag);
            if (outcome instanceof Accepted) {
                if (oldConsumer.acquires()) {
                    AutoCommitTransaction txn = new AutoCommitTransaction(addressSpace.getMessageStore());
                    if (queueEntry.acquire() || queueEntry.isAcquired()) {
                        txn.dequeue(Collections.singleton(queueEntry), new ServerTransaction.Action() {

                            @Override
                            public void postCommit() {
                                queueEntry.delete();
                            }

                            @Override
                            public void onRollback() {
                            }
                        });
                    }
                }
            } else if (outcome instanceof Released) {
                if (oldConsumer.acquires()) {
                    AutoCommitTransaction txn = new AutoCommitTransaction(addressSpace.getMessageStore());
                    txn.dequeue(Collections.singleton(queueEntry), new ServerTransaction.Action() {

                        @Override
                        public void postCommit() {
                            queueEntry.release(oldConsumer);
                        }

                        @Override
                        public void onRollback() {
                        }
                    });
                }
            }
            // TODO: QPID-7845: Handle rejected and modified outcome
            remoteUnsettled.remove(deliveryTag);
            _resumeAcceptedTransfers.add(deliveryTag);
        } else {
            _resumeFullTransfers.add(queueEntry);
        // TODO:QPID-7845: exists in receivers map, but not yet got an outcome ... should resend with resume = true
        }
    }
    getConsumerTarget().updateNotifyWorkDesired();
}
Also used : AsyncAutoCommitTransaction(org.apache.qpid.server.txn.AsyncAutoCommitTransaction) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) Action(org.apache.qpid.server.util.Action) Modified(org.apache.qpid.server.protocol.v1_0.type.messaging.Modified) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer) 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) MessageInstance(org.apache.qpid.server.message.MessageInstance) BaseTarget(org.apache.qpid.server.protocol.v1_0.type.BaseTarget) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) Released(org.apache.qpid.server.protocol.v1_0.type.messaging.Released) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Outcome(org.apache.qpid.server.protocol.v1_0.type.Outcome) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Example 18 with AmqpErrorException

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

the class Session_1_0 method getReceivingDestination.

public ReceivingDestination getReceivingDestination(final Link_1_0<?, ?> link, final Target target) throws AmqpErrorException {
    final ReceivingDestination destination;
    if (target != null) {
        if (Boolean.TRUE.equals(target.getDynamic())) {
            MessageDestination tempDestination = createDynamicDestination(link, target.getDynamicNodeProperties(), target.getCapabilities());
            if (tempDestination != null) {
                target.setAddress(_primaryDomain + tempDestination.getName());
            } else {
                throw new AmqpErrorException(AmqpError.INTERNAL_ERROR, "Cannot create dynamic destination");
            }
        }
        String addr = target.getAddress();
        if (addr == null || "".equals(addr.trim())) {
            destination = new AnonymousRelayDestination(getAddressSpace(), target, _connection.getEventLogger());
        } else {
            DestinationAddress destinationAddress = new DestinationAddress(getAddressSpace(), addr);
            MessageDestination messageDestination = destinationAddress.getMessageDestination();
            if (messageDestination != null) {
                destination = new NodeReceivingDestination(destinationAddress, target.getDurable(), target.getExpiryPolicy(), target.getCapabilities(), _connection.getEventLogger());
            } else {
                destination = null;
            }
        }
    } else {
        destination = null;
    }
    if (destination == null) {
        throw new AmqpErrorException(AmqpError.NOT_FOUND, String.format("Could not find destination for target '%s'", target));
    }
    return destination;
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) DestinationAddress(org.apache.qpid.server.model.DestinationAddress)

Example 19 with AmqpErrorException

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

the class Session_1_0 method createDynamicDestination.

private MessageDestination createDynamicDestination(final Link_1_0<?, ?> link, Map properties, final Symbol[] capabilities) throws AmqpErrorException {
    final Set<Symbol> capabilitySet = capabilities == null ? Collections.emptySet() : Sets.newHashSet(capabilities);
    boolean isTopic = capabilitySet.contains(Symbol.valueOf("temporary-topic")) || capabilitySet.contains(Symbol.valueOf("topic"));
    final String destName = (isTopic ? "TempTopic" : "TempQueue") + UUID.randomUUID().toString();
    try {
        Map<String, Object> attributes = convertDynamicNodePropertiesToAttributes(link, properties, destName);
        Class<? extends MessageDestination> clazz = isTopic ? Exchange.class : MessageDestination.class;
        if (isTopic) {
            attributes.put(Exchange.TYPE, ExchangeDefaults.FANOUT_EXCHANGE_CLASS);
        }
        return Subject.doAs(getSubjectWithAddedSystemRights(), (PrivilegedAction<MessageDestination>) () -> getAddressSpace().createMessageDestination(clazz, attributes));
    } catch (AccessControlException e) {
        throw new AmqpErrorException(AmqpError.UNAUTHORIZED_ACCESS, e.getMessage());
    } catch (AbstractConfiguredObject.DuplicateNameException e) {
        LOGGER.error("A temporary destination was created with a name which collided with an existing destination name '{}'", destName);
        throw new ConnectionScopedRuntimeException(e);
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) AccessControlException(java.security.AccessControlException) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Example 20 with AmqpErrorException

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

the class Session_1_0 method createExchangeDestination.

private ExchangeSendingDestination createExchangeDestination(final String exchangeName, final String bindingKey, final String linkName, final Source source) throws AmqpErrorException {
    ExchangeSendingDestination exchangeDestination = null;
    Exchange<?> exchange = getExchange(exchangeName);
    if (exchange != null) {
        if (!Boolean.TRUE.equals(source.getDynamic())) {
            String remoteContainerId = getConnection().getRemoteContainerId();
            exchangeDestination = new ExchangeSendingDestination(exchange, linkName, bindingKey, remoteContainerId, source);
            source.setFilter(exchangeDestination.getFilters());
            source.setDistributionMode(StdDistMode.COPY);
        } else {
            // TODO
            throw new AmqpErrorException(new Error(AmqpError.NOT_IMPLEMENTED, "Temporary subscription is not implemented"));
        }
    }
    return exchangeDestination;
}
Also used : AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) 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)

Aggregations

AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)20 AmqpError (org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError)10 Error (org.apache.qpid.server.protocol.v1_0.type.transport.Error)10 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)8 Source (org.apache.qpid.server.protocol.v1_0.type.messaging.Source)8 MessageSource (org.apache.qpid.server.message.MessageSource)7 BaseSource (org.apache.qpid.server.protocol.v1_0.type.BaseSource)6 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)6 ArrayList (java.util.ArrayList)5 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)5 EncodingRetainingSection (org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)4 AmqpValueSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpValueSection)4 TransactionError (org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError)4 DeliveryState (org.apache.qpid.server.protocol.v1_0.type.DeliveryState)3 AmqpSequenceSection (org.apache.qpid.server.protocol.v1_0.type.messaging.AmqpSequenceSection)3 DataSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2