Search in sources :

Example 1 with NotFoundException

use of org.apache.qpid.server.model.NotFoundException in project qpid-broker-j by apache.

the class ExchangeSendingDestination method getQueue.

private static Queue<?> getQueue(Exchange<?> exchange, Source source, String subscriptionName, BindingInfo bindingInfo) throws AmqpErrorException {
    boolean isDurable = source.getExpiryPolicy() == TerminusExpiryPolicy.NEVER;
    boolean isShared = hasCapability(source.getCapabilities(), SHARED_CAPABILITY);
    QueueManagingVirtualHost virtualHost;
    if (exchange.getAddressSpace() instanceof QueueManagingVirtualHost) {
        virtualHost = (QueueManagingVirtualHost) exchange.getAddressSpace();
    } else {
        throw new AmqpErrorException(new Error(AmqpError.INTERNAL_ERROR, "Address space of unexpected type"));
    }
    Queue<?> queue;
    final Map<String, Object> attributes = new HashMap<>();
    ExclusivityPolicy exclusivityPolicy;
    if (isShared) {
        exclusivityPolicy = ExclusivityPolicy.SHARED_SUBSCRIPTION;
    } else {
        exclusivityPolicy = ExclusivityPolicy.LINK;
    }
    org.apache.qpid.server.model.LifetimePolicy lifetimePolicy = getLifetimePolicy(source.getExpiryPolicy());
    attributes.put(Queue.ID, UUID.randomUUID());
    attributes.put(Queue.NAME, subscriptionName);
    attributes.put(Queue.LIFETIME_POLICY, lifetimePolicy);
    attributes.put(Queue.EXCLUSIVE, exclusivityPolicy);
    attributes.put(Queue.DURABLE, isDurable);
    Map<String, Map<String, Object>> bindings = bindingInfo.getBindings();
    try {
        queue = virtualHost.getSubscriptionQueue(exchange.getName(), attributes, bindings);
    } catch (NotFoundException e) {
        throw new AmqpErrorException(new Error(AmqpError.NOT_FOUND, e.getMessage()));
    } catch (IllegalStateException e) {
        throw new AmqpErrorException(new Error(AmqpError.RESOURCE_LOCKED, "Subscription is already in use"));
    }
    return queue;
}
Also used : QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) HashMap(java.util.HashMap) 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) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) NotFoundException(org.apache.qpid.server.model.NotFoundException) ExclusivityPolicy(org.apache.qpid.server.model.ExclusivityPolicy) LifetimePolicy(org.apache.qpid.server.model.LifetimePolicy) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with NotFoundException

use of org.apache.qpid.server.model.NotFoundException in project qpid-broker-j by apache.

the class AbstractVirtualHost method getSubscriptionQueue.

@Override
@DoOnConfigThread
public Queue<?> getSubscriptionQueue(@Param(name = "exchangeName", mandatory = true) final String exchangeName, @Param(name = "attributes", mandatory = true) final Map<String, Object> attributes, @Param(name = "bindings", mandatory = true) final Map<String, Map<String, Object>> bindings) {
    Queue queue;
    Object exclusivityPolicy = attributes.get(Queue.EXCLUSIVE);
    if (exclusivityPolicy == null) {
        exclusivityPolicy = getContextValue(ExclusivityPolicy.class, Queue.QUEUE_DEFAULT_EXCLUSIVITY_POLICY);
    }
    if (!(exclusivityPolicy instanceof ExclusivityPolicy)) {
        throw new IllegalArgumentException("Exclusivity policy is required");
    }
    Exchange<?> exchange = findConfiguredObject(Exchange.class, exchangeName);
    if (exchange == null) {
        throw new NotFoundException(String.format("Exchange '%s' was not found", exchangeName));
    }
    try {
        queue = createMessageDestination(Queue.class, attributes);
        for (String binding : bindings.keySet()) {
            exchange.addBinding(binding, queue, bindings.get(binding));
        }
    } catch (AbstractConfiguredObject.DuplicateNameException e) {
        Queue<?> existingQueue = (Queue) e.getExisting();
        if (existingQueue.getExclusive() == exclusivityPolicy) {
            if (hasDifferentBindings(exchange, existingQueue, bindings)) {
                if (existingQueue.getConsumers().isEmpty()) {
                    existingQueue.delete();
                    queue = createMessageDestination(Queue.class, attributes);
                    for (String binding : bindings.keySet()) {
                        try {
                            exchange.addBinding(binding, queue, bindings.get(binding));
                        } catch (AMQInvalidArgumentException ia) {
                            throw new IllegalArgumentException("Unexpected bind argument : " + ia.getMessage(), ia);
                        }
                    }
                } else {
                    throw new IllegalStateException("subscription already in use");
                }
            } else {
                queue = existingQueue;
            }
        } else {
            throw new IllegalStateException("subscription already in use");
        }
    } catch (AMQInvalidArgumentException e) {
        throw new IllegalArgumentException("Unexpected bind argument : " + e.getMessage(), e);
    }
    return queue;
}
Also used : ExclusivityPolicy(org.apache.qpid.server.model.ExclusivityPolicy) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) AMQInvalidArgumentException(org.apache.qpid.server.filter.AMQInvalidArgumentException) NotFoundException(org.apache.qpid.server.model.NotFoundException) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Queue(org.apache.qpid.server.model.Queue) DoOnConfigThread(org.apache.qpid.server.model.DoOnConfigThread)

Example 3 with NotFoundException

use of org.apache.qpid.server.model.NotFoundException in project qpid-broker-j by apache.

the class SendingLinkEndpoint method detach.

@Override
protected void detach(Error error, final boolean close) {
    if (_consumerTarget != null) {
        _consumerTarget.close();
    }
    Source source = getSource();
    TerminusExpiryPolicy expiryPolicy = source.getExpiryPolicy();
    NamedAddressSpace addressSpace = getSession().getConnection().getAddressSpace();
    List<Symbol> sourceCapabilities = source.getCapabilities() == null ? Collections.emptyList() : Arrays.asList(source.getCapabilities());
    if (close || TerminusExpiryPolicy.LINK_DETACH.equals(expiryPolicy) || ((expiryPolicy == null || TerminusExpiryPolicy.SESSION_END.equals(expiryPolicy)) && getSession().isClosing()) || (TerminusExpiryPolicy.CONNECTION_CLOSE.equals(expiryPolicy) && getSession().getConnection().isClosing())) {
        cleanUpUnsettledDeliveries();
    }
    if (close) {
        Error closingError = null;
        if (getDestination() instanceof ExchangeSendingDestination && addressSpace instanceof QueueManagingVirtualHost && TerminusExpiryPolicy.NEVER.equals(expiryPolicy)) {
            try {
                ((QueueManagingVirtualHost) addressSpace).removeSubscriptionQueue(((ExchangeSendingDestination) getDestination()).getQueue().getName());
                TerminusDurability sourceDurability = source.getDurable();
                if (sourceDurability != null && !TerminusDurability.NONE.equals(sourceDurability) && sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY)) {
                    final Pattern containerIdPattern = sourceCapabilities.contains(Session_1_0.GLOBAL_CAPABILITY) ? ANY_CONTAINER_ID : Pattern.compile("^" + Pattern.quote(getSession().getConnection().getRemoteContainerId()) + "$");
                    final Pattern linkNamePattern = Pattern.compile("^" + Pattern.quote(getLinkName()) + "\\|?\\d*$");
                    addressSpace.visitSendingLinks((LinkRegistryModel.LinkVisitor<Link_1_0<Source, Target>>) link -> {
                        if (containerIdPattern.matcher(link.getRemoteContainerId()).matches() && linkNamePattern.matcher(link.getName()).matches()) {
                            link.linkClosed();
                        }
                        return false;
                    });
                }
            } catch (AccessControlException e) {
                LOGGER.error("Error unregistering subscription", e);
                closingError = new Error(AmqpError.NOT_ALLOWED, "Error unregistering subscription");
            } catch (IllegalStateException e) {
                String message;
                if (sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY)) {
                    String subscriptionName = getLinkName();
                    int separator = subscriptionName.indexOf("|");
                    if (separator > 0) {
                        subscriptionName = subscriptionName.substring(0, separator);
                    }
                    message = "There are active consumers on the shared subscription '" + subscriptionName + "'";
                } else {
                    message = e.getMessage();
                }
                closingError = new Error(AmqpError.RESOURCE_LOCKED, message);
            } catch (NotFoundException e) {
                closingError = new Error(AmqpError.NOT_FOUND, e.getMessage());
            }
        }
        if (error == null) {
            error = closingError;
        } else {
            LOGGER.warn("Unexpected error on detaching endpoint {}: {}", getLinkName(), error);
        }
    } else if (addressSpace instanceof QueueManagingVirtualHost && ((QueueManagingVirtualHost) addressSpace).isDiscardGlobalSharedSubscriptionLinksOnDetach() && sourceCapabilities.contains(Session_1_0.SHARED_CAPABILITY) && sourceCapabilities.contains(Session_1_0.GLOBAL_CAPABILITY) && sourceCapabilities.contains(ExchangeSendingDestination.TOPIC_CAPABILITY) && !getLinkName().endsWith("|global")) {
        // For JMS 2.0 global shared subscriptions we do not want to keep the links hanging around.
        // However, we keep one link (ending with "|global") to perform a null-source lookup upon un-subscription.
        getLink().linkClosed();
    }
    super.detach(error, close);
}
Also used : Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) SelectorParsingException(org.apache.qpid.server.filter.SelectorParsingException) ParseException(org.apache.qpid.server.filter.selector.ParseException) ConsumerOption(org.apache.qpid.server.consumer.ConsumerOption) Transfer(org.apache.qpid.server.protocol.v1_0.type.transport.Transfer) AsyncAutoCommitTransaction(org.apache.qpid.server.txn.AsyncAutoCommitTransaction) Map(java.util.Map) NotFoundException(org.apache.qpid.server.model.NotFoundException) Rejected(org.apache.qpid.server.protocol.v1_0.type.messaging.Rejected) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) EnumSet(java.util.EnumSet) NoLocalFilter(org.apache.qpid.server.protocol.v1_0.type.messaging.NoLocalFilter) AutoCommitTransaction(org.apache.qpid.server.txn.AutoCommitTransaction) JMSSelectorFilter(org.apache.qpid.server.filter.JMSSelectorFilter) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) Filter(org.apache.qpid.server.protocol.v1_0.type.messaging.Filter) Detach(org.apache.qpid.server.protocol.v1_0.type.transport.Detach) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TransactionError(org.apache.qpid.server.protocol.v1_0.type.transaction.TransactionError) Attach(org.apache.qpid.server.protocol.v1_0.type.transport.Attach) List(java.util.List) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) MessageSource(org.apache.qpid.server.message.MessageSource) TokenMgrError(org.apache.qpid.server.filter.selector.TokenMgrError) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) AccessControlException(java.security.AccessControlException) Role(org.apache.qpid.server.protocol.v1_0.type.transport.Role) Pattern(java.util.regex.Pattern) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) LinkRegistryModel(org.apache.qpid.server.virtualhost.LinkRegistryModel) TerminusExpiryPolicy(org.apache.qpid.server.protocol.v1_0.type.messaging.TerminusExpiryPolicy) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger) Queue(org.apache.qpid.server.model.Queue) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) StdDistMode(org.apache.qpid.server.protocol.v1_0.type.messaging.StdDistMode) Released(org.apache.qpid.server.protocol.v1_0.type.messaging.Released) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Error(org.apache.qpid.server.protocol.v1_0.type.transport.Error) Outcome(org.apache.qpid.server.protocol.v1_0.type.Outcome) AmqpError(org.apache.qpid.server.protocol.v1_0.type.transport.AmqpError) MessageInstance(org.apache.qpid.server.message.MessageInstance) Target(org.apache.qpid.server.protocol.v1_0.type.messaging.Target) Accepted(org.apache.qpid.server.protocol.v1_0.type.messaging.Accepted) ServerTransaction(org.apache.qpid.server.txn.ServerTransaction) Logger(org.slf4j.Logger) Action(org.apache.qpid.server.util.Action) DeliveryState(org.apache.qpid.server.protocol.v1_0.type.DeliveryState) Flow(org.apache.qpid.server.protocol.v1_0.type.transport.Flow) MessageInstanceConsumer(org.apache.qpid.server.message.MessageInstanceConsumer) FilterManager(org.apache.qpid.server.filter.FilterManager) TerminusDurability(org.apache.qpid.server.protocol.v1_0.type.messaging.TerminusDurability) Modified(org.apache.qpid.server.protocol.v1_0.type.messaging.Modified) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) Collections(java.util.Collections) AsyncCommand(org.apache.qpid.server.txn.AsyncCommand) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) Pattern(java.util.regex.Pattern) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) 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) AccessControlException(java.security.AccessControlException) NotFoundException(org.apache.qpid.server.model.NotFoundException) TerminusDurability(org.apache.qpid.server.protocol.v1_0.type.messaging.TerminusDurability) MessageSource(org.apache.qpid.server.message.MessageSource) Source(org.apache.qpid.server.protocol.v1_0.type.messaging.Source) TerminusExpiryPolicy(org.apache.qpid.server.protocol.v1_0.type.messaging.TerminusExpiryPolicy) LinkRegistryModel(org.apache.qpid.server.virtualhost.LinkRegistryModel)

Aggregations

NotFoundException (org.apache.qpid.server.model.NotFoundException)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 TokenMgrError (org.apache.qpid.server.filter.selector.TokenMgrError)2 ExclusivityPolicy (org.apache.qpid.server.model.ExclusivityPolicy)2 Queue (org.apache.qpid.server.model.Queue)2 AmqpErrorException (org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 AccessControlException (java.security.AccessControlException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 Pattern (java.util.regex.Pattern)1 ConsumerOption (org.apache.qpid.server.consumer.ConsumerOption)1 AMQInvalidArgumentException (org.apache.qpid.server.filter.AMQInvalidArgumentException)1 FilterManager (org.apache.qpid.server.filter.FilterManager)1