Search in sources :

Example 1 with UnknownAlternateBindingException

use of org.apache.qpid.server.virtualhost.UnknownAlternateBindingException in project qpid-broker-j by apache.

the class ServerSessionDelegate method exchangeDeclare.

@Override
public void exchangeDeclare(ServerSession session, ExchangeDeclare method) {
    String exchangeName = method.getExchange();
    NamedAddressSpace addressSpace = getAddressSpace(session);
    // we must check for any unsupported arguments present and throw not-implemented
    if (method.hasArguments()) {
        Map<String, Object> args = method.getArguments();
        // QPID-3392: currently we don't support any!
        if (!args.isEmpty()) {
            exception(session, method, ExecutionErrorCode.NOT_IMPLEMENTED, "Unsupported exchange argument(s) found " + args.keySet().toString());
            return;
        }
    }
    String alternateExchangeName = method.getAlternateExchange();
    if (nameNullOrEmpty(method.getExchange())) {
        // special case handling to fake the existence of the default exchange for 0-10
        if (!ExchangeDefaults.DIRECT_EXCHANGE_CLASS.equals(method.getType())) {
            exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to redeclare default exchange " + " of type " + ExchangeDefaults.DIRECT_EXCHANGE_CLASS + " to " + method.getType() + ".");
        }
        if (!nameNullOrEmpty(alternateExchangeName)) {
            exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to set alternate exchange of the default exchange " + " to " + alternateExchangeName + ".");
        }
    } else {
        if (method.getPassive()) {
            Exchange<?> exchange = getExchange(session, exchangeName);
            if (exchange == null) {
                exception(session, method, ExecutionErrorCode.NOT_FOUND, "not-found: exchange-name '" + exchangeName + "'");
            } else {
                if (!exchange.getType().equals(method.getType()) && (method.getType() != null && method.getType().length() > 0)) {
                    exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to redeclare exchange: " + exchangeName + " of type " + exchange.getType() + " to " + method.getType() + ".");
                }
            }
        } else {
            try {
                Map<String, Object> attributes = new HashMap<String, Object>();
                attributes.put(org.apache.qpid.server.model.Exchange.NAME, method.getExchange());
                attributes.put(org.apache.qpid.server.model.Exchange.TYPE, method.getType());
                attributes.put(org.apache.qpid.server.model.Exchange.DURABLE, method.getDurable());
                attributes.put(org.apache.qpid.server.model.Exchange.LIFETIME_POLICY, method.getAutoDelete() ? LifetimePolicy.DELETE_ON_NO_LINKS : LifetimePolicy.PERMANENT);
                if (method.hasAlternateExchange() && !nameNullOrEmpty(alternateExchangeName)) {
                    validateAlternateExchangeIsNotQueue(addressSpace, alternateExchangeName);
                    attributes.put(org.apache.qpid.server.model.Exchange.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, alternateExchangeName));
                }
                addressSpace.createMessageDestination(Exchange.class, attributes);
                ;
            } catch (ReservedExchangeNameException e) {
                Exchange<?> existingExchange = getExchange(session, exchangeName);
                if (existingExchange == null || !existingExchange.getType().equals(method.getType()) || (method.hasAlternateExchange() && (existingExchange.getAlternateBinding() == null || !alternateExchangeName.equals(existingExchange.getAlternateBinding().getDestination())))) {
                    exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to declare exchange: " + exchangeName + " which begins with reserved name or prefix.");
                }
            } catch (UnknownAlternateBindingException e) {
                exception(session, method, ExecutionErrorCode.NOT_FOUND, String.format("Unknown alternate exchange '%s'", e.getAlternateBindingName()));
            } catch (NoFactoryForTypeException e) {
                exception(session, method, ExecutionErrorCode.NOT_FOUND, "Unknown Exchange Type: " + method.getType());
            } catch (AbstractConfiguredObject.DuplicateNameException e) {
                Exchange<?> exchange = (Exchange<?>) e.getExisting();
                if (!exchange.getType().equals(method.getType())) {
                    exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to redeclare exchange: " + exchangeName + " of type " + exchange.getType() + " to " + method.getType() + ".");
                } else if (method.hasAlternateExchange() && (exchange.getAlternateBinding() == null || !alternateExchangeName.equals(exchange.getAlternateBinding().getDestination()))) {
                    exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to change alternate exchange of: " + exchangeName + " from " + exchange.getAlternateBinding() + " to " + alternateExchangeName + ".");
                }
            } catch (AccessControlException e) {
                exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage());
            } catch (IllegalArgumentException | IllegalConfigurationException e) {
                exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, e.getMessage());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AccessControlException(java.security.AccessControlException) Exchange(org.apache.qpid.server.model.Exchange) NoFactoryForTypeException(org.apache.qpid.server.model.NoFactoryForTypeException) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ReservedExchangeNameException(org.apache.qpid.server.virtualhost.ReservedExchangeNameException) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)

Example 2 with UnknownAlternateBindingException

use of org.apache.qpid.server.virtualhost.UnknownAlternateBindingException in project qpid-broker-j by apache.

the class AMQChannel method receiveExchangeDeclare.

@Override
public void receiveExchangeDeclare(final AMQShortString exchangeName, final AMQShortString type, final boolean passive, final boolean durable, final boolean autoDelete, final boolean internal, final boolean nowait, final FieldTable arguments) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + _channelId + "] ExchangeDeclare[" + " exchange: " + exchangeName + " type: " + type + " passive: " + passive + " durable: " + durable + " autoDelete: " + autoDelete + " internal: " + internal + " nowait: " + nowait + " arguments: " + arguments + " ]");
    }
    final MethodRegistry methodRegistry = _connection.getMethodRegistry();
    final AMQMethodBody declareOkBody = methodRegistry.createExchangeDeclareOkBody();
    Exchange<?> exchange;
    NamedAddressSpace virtualHost = _connection.getAddressSpace();
    if (isDefaultExchange(exchangeName)) {
        if (!new AMQShortString(ExchangeDefaults.DIRECT_EXCHANGE_CLASS).equals(type)) {
            _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to redeclare default exchange: " + " of type " + ExchangeDefaults.DIRECT_EXCHANGE_CLASS + " to " + type + ".", getChannelId());
        } else if (!nowait) {
            sync();
            _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
        }
    } else {
        if (passive) {
            exchange = getExchange(exchangeName.toString());
            if (exchange == null) {
                closeChannel(ErrorCodes.NOT_FOUND, "Unknown exchange: '" + exchangeName + "'");
            } else if (!(type == null || type.length() == 0) && !exchange.getType().equals(type.toString())) {
                _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to redeclare exchange: '" + exchangeName + "' of type " + exchange.getType() + " to " + type + ".", getChannelId());
            } else if (!nowait) {
                sync();
                _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
            }
        } else {
            String name = exchangeName.toString();
            String typeString = type == null ? null : type.toString();
            try {
                Map<String, Object> attributes = new HashMap<String, Object>();
                if (arguments != null) {
                    attributes.putAll(FieldTable.convertToMap(arguments));
                }
                attributes.put(Exchange.NAME, name);
                attributes.put(Exchange.TYPE, typeString);
                attributes.put(Exchange.DURABLE, durable);
                attributes.put(Exchange.LIFETIME_POLICY, autoDelete ? LifetimePolicy.DELETE_ON_NO_LINKS : LifetimePolicy.PERMANENT);
                Object alternateExchange = attributes.remove(ALTERNATE_EXCHANGE);
                if (alternateExchange != null) {
                    String alternateExchangeName = String.valueOf(alternateExchange);
                    validateAlternateExchangeIsNotQueue(virtualHost, alternateExchangeName);
                    attributes.put(Exchange.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, alternateExchangeName));
                }
                exchange = virtualHost.createMessageDestination(Exchange.class, attributes);
                if (!nowait) {
                    sync();
                    _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
                }
            } catch (ReservedExchangeNameException e) {
                Exchange existing = getExchange(name);
                if (existing == null || !existing.getType().equals(typeString)) {
                    _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to declare exchange: '" + exchangeName + "' which begins with reserved prefix.", getChannelId());
                } else if (!nowait) {
                    sync();
                    _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
                }
            } catch (AbstractConfiguredObject.DuplicateNameException e) {
                exchange = (Exchange<?>) e.getExisting();
                if (!exchange.getType().equals(typeString)) {
                    _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Attempt to redeclare exchange: '" + exchangeName + "' of type " + exchange.getType() + " to " + type + ".", getChannelId());
                } else {
                    if (!nowait) {
                        sync();
                        _connection.writeFrame(declareOkBody.generateFrame(getChannelId()));
                    }
                }
            } catch (NoFactoryForTypeException e) {
                _connection.sendConnectionClose(ErrorCodes.COMMAND_INVALID, "Unknown exchange type '" + e.getType() + "' for exchange '" + exchangeName + "'", getChannelId());
            } catch (AccessControlException e) {
                _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
            } catch (UnknownAlternateBindingException e) {
                final String message = String.format("Unknown alternate exchange '%s'", e.getAlternateBindingName());
                _connection.sendConnectionClose(ErrorCodes.NOT_FOUND, message, getChannelId());
            } catch (IllegalArgumentException | IllegalConfigurationException e) {
                _connection.sendConnectionClose(ErrorCodes.COMMAND_INVALID, "Error creating exchange '" + exchangeName + "': " + e.getMessage(), getChannelId());
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AccessControlException(java.security.AccessControlException) Exchange(org.apache.qpid.server.model.Exchange) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) NoFactoryForTypeException(org.apache.qpid.server.model.NoFactoryForTypeException) ReservedExchangeNameException(org.apache.qpid.server.virtualhost.ReservedExchangeNameException) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)

Example 3 with UnknownAlternateBindingException

use of org.apache.qpid.server.virtualhost.UnknownAlternateBindingException in project qpid-broker-j by apache.

the class AMQChannel method receiveQueueDeclare.

@Override
public void receiveQueueDeclare(final AMQShortString queueStr, final boolean passive, final boolean durable, final boolean exclusive, final boolean autoDelete, final boolean nowait, final FieldTable arguments) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("RECV[" + _channelId + "] QueueDeclare[" + " queue: " + queueStr + " passive: " + passive + " durable: " + durable + " exclusive: " + exclusive + " autoDelete: " + autoDelete + " nowait: " + nowait + " arguments: " + arguments + " ]");
    }
    NamedAddressSpace virtualHost = _connection.getAddressSpace();
    final AMQShortString queueName;
    // if we aren't given a queue name, we create one which we return to the client
    if ((queueStr == null) || (queueStr.length() == 0)) {
        queueName = new AMQShortString("tmp_" + UUID.randomUUID());
    } else {
        queueName = queueStr;
    }
    Queue<?> queue;
    if (passive) {
        queue = getQueue(queueName.toString());
        if (queue == null) {
            closeChannel(ErrorCodes.NOT_FOUND, "Queue: '" + queueName + "' not found on VirtualHost '" + virtualHost.getName() + "'.");
        } else {
            if (!queue.verifySessionAccess(this)) {
                _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Queue '" + queue.getName() + "' is exclusive, but not created on this Connection.", getChannelId());
            } else {
                // set this as the default queue on the channel:
                setDefaultQueue(queue);
                if (!nowait) {
                    sync();
                    MethodRegistry methodRegistry = _connection.getMethodRegistry();
                    QueueDeclareOkBody responseBody = methodRegistry.createQueueDeclareOkBody(queueName, queue.getQueueDepthMessages(), queue.getConsumerCount());
                    _connection.writeFrame(responseBody.generateFrame(getChannelId()));
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Queue " + queueName + " declared successfully");
                    }
                }
            }
        }
    } else {
        try {
            final String queueNameString = AMQShortString.toString(queueName);
            Map<String, Object> wireArguments = FieldTable.convertToMap(arguments);
            Object alternateExchange = wireArguments.get(ALTERNATE_EXCHANGE);
            if (alternateExchange != null) {
                String alternateExchangeName = String.valueOf(alternateExchange);
                validateAlternateExchangeIsNotQueue(virtualHost, alternateExchangeName);
            }
            Map<String, Object> attributes = QueueArgumentsConverter.convertWireArgsToModel(queueNameString, wireArguments);
            attributes.put(Queue.NAME, queueNameString);
            attributes.put(Queue.DURABLE, durable);
            LifetimePolicy lifetimePolicy;
            ExclusivityPolicy exclusivityPolicy;
            if (exclusive) {
                lifetimePolicy = autoDelete ? LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS : durable ? LifetimePolicy.PERMANENT : LifetimePolicy.DELETE_ON_CONNECTION_CLOSE;
                exclusivityPolicy = durable ? ExclusivityPolicy.CONTAINER : ExclusivityPolicy.CONNECTION;
            } else {
                lifetimePolicy = autoDelete ? LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS : LifetimePolicy.PERMANENT;
                exclusivityPolicy = ExclusivityPolicy.NONE;
            }
            if (!attributes.containsKey(Queue.EXCLUSIVE)) {
                attributes.put(Queue.EXCLUSIVE, exclusivityPolicy);
            }
            if (!attributes.containsKey(Queue.LIFETIME_POLICY)) {
                attributes.put(Queue.LIFETIME_POLICY, lifetimePolicy);
            }
            queue = virtualHost.createMessageSource(Queue.class, attributes);
            setDefaultQueue(queue);
            if (!nowait) {
                sync();
                MethodRegistry methodRegistry = _connection.getMethodRegistry();
                QueueDeclareOkBody responseBody = methodRegistry.createQueueDeclareOkBody(queueName, queue.getQueueDepthMessages(), queue.getConsumerCount());
                _connection.writeFrame(responseBody.generateFrame(getChannelId()));
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Queue " + queueName + " declared successfully");
                }
            }
        } catch (AbstractConfiguredObject.DuplicateNameException qe) {
            queue = (Queue<?>) qe.getExisting();
            if (!queue.verifySessionAccess(this)) {
                _connection.sendConnectionClose(ErrorCodes.NOT_ALLOWED, "Queue '" + queue.getName() + "' is exclusive, but not created on this Connection.", getChannelId());
            } else if (queue.isExclusive() != exclusive) {
                closeChannel(ErrorCodes.ALREADY_EXISTS, "Cannot re-declare queue '" + queue.getName() + "' with different exclusivity (was: " + queue.isExclusive() + " requested " + exclusive + ")");
            } else if ((autoDelete && queue.getLifetimePolicy() == LifetimePolicy.PERMANENT) || (!autoDelete && queue.getLifetimePolicy() != ((exclusive && !durable) ? LifetimePolicy.DELETE_ON_CONNECTION_CLOSE : LifetimePolicy.PERMANENT))) {
                closeChannel(ErrorCodes.ALREADY_EXISTS, "Cannot re-declare queue '" + queue.getName() + "' with different lifetime policy (was: " + queue.getLifetimePolicy() + " requested autodelete: " + autoDelete + ")");
            } else {
                setDefaultQueue(queue);
                if (!nowait) {
                    sync();
                    MethodRegistry methodRegistry = _connection.getMethodRegistry();
                    QueueDeclareOkBody responseBody = methodRegistry.createQueueDeclareOkBody(queueName, queue.getQueueDepthMessages(), queue.getConsumerCount());
                    _connection.writeFrame(responseBody.generateFrame(getChannelId()));
                    if (LOGGER.isDebugEnabled()) {
                        LOGGER.debug("Queue " + queueName + " declared successfully");
                    }
                }
            }
        } catch (AccessControlException e) {
            _connection.sendConnectionClose(ErrorCodes.ACCESS_REFUSED, e.getMessage(), getChannelId());
        } catch (UnknownAlternateBindingException e) {
            final String message = String.format("Unknown alternate exchange: '%s'", e.getAlternateBindingName());
            _connection.sendConnectionClose(ErrorCodes.NOT_FOUND, message, getChannelId());
        } catch (IllegalArgumentException | IllegalConfigurationException e) {
            String message = String.format("Error creating queue '%s': %s", queueName, e.getMessage());
            _connection.sendConnectionClose(ErrorCodes.COMMAND_INVALID, message, getChannelId());
        }
    }
}
Also used : LifetimePolicy(org.apache.qpid.server.model.LifetimePolicy) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AccessControlException(java.security.AccessControlException) ExclusivityPolicy(org.apache.qpid.server.model.ExclusivityPolicy) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Queue(org.apache.qpid.server.model.Queue)

Example 4 with UnknownAlternateBindingException

use of org.apache.qpid.server.virtualhost.UnknownAlternateBindingException in project qpid-broker-j by apache.

the class ServerSessionDelegate method queueDeclare.

@Override
public void queueDeclare(ServerSession session, final QueueDeclare method) {
    final NamedAddressSpace addressSpace = getAddressSpace(session);
    String queueName = method.getQueue();
    Queue<?> queue;
    // TODO: do we need to check that the queue already exists with exactly the same "configuration"?
    final boolean exclusive = method.getExclusive();
    final boolean autoDelete = method.getAutoDelete();
    if (method.getPassive()) {
        queue = getQueue(addressSpace, queueName);
        if (queue == null) {
            String description = "Queue: " + queueName + " not found on VirtualHost(" + addressSpace + ").";
            ExecutionErrorCode errorCode = ExecutionErrorCode.NOT_FOUND;
            exception(session, method, errorCode, description);
        } else if (exclusive) {
            if (queue.getExclusive() == ExclusivityPolicy.NONE) {
                String description = "Cannot passively declare queue ('" + queueName + "')" + " as exclusive as queue with same name is" + " already declared as non-exclusive";
                ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
                exception(session, method, errorCode, description);
            } else if (!verifySessionAccess(session, queue)) {
                String description = "Cannot passively declare queue('" + queueName + "')," + " as exclusive queue with same name " + "declared on another session";
                ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
                exception(session, method, errorCode, description);
            }
        }
    } else {
        try {
            final Map<String, Object> arguments = QueueArgumentsConverter.convertWireArgsToModel(queueName, method.getArguments());
            final String alternateExchangeName = method.getAlternateExchange();
            if (method.hasAlternateExchange() && !nameNullOrEmpty(alternateExchangeName)) {
                validateAlternateExchangeIsNotQueue(addressSpace, alternateExchangeName);
                arguments.put(Queue.ALTERNATE_BINDING, Collections.singletonMap(AlternateBinding.DESTINATION, alternateExchangeName));
            }
            arguments.put(Queue.NAME, queueName);
            if (!arguments.containsKey(Queue.LIFETIME_POLICY)) {
                LifetimePolicy lifetime;
                if (autoDelete) {
                    lifetime = exclusive ? LifetimePolicy.DELETE_ON_SESSION_END : LifetimePolicy.DELETE_ON_NO_OUTBOUND_LINKS;
                } else {
                    lifetime = LifetimePolicy.PERMANENT;
                }
                arguments.put(Queue.LIFETIME_POLICY, lifetime);
            }
            if (!arguments.containsKey(Queue.EXCLUSIVE)) {
                ExclusivityPolicy exclusivityPolicy = exclusive ? ExclusivityPolicy.SESSION : ExclusivityPolicy.NONE;
                arguments.put(Queue.EXCLUSIVE, exclusivityPolicy);
            }
            arguments.put(Queue.DURABLE, method.getDurable());
            queue = addressSpace.createMessageSource(Queue.class, arguments);
        } catch (AbstractConfiguredObject.DuplicateNameException qe) {
            queue = (Queue<?>) qe.getExisting();
            if (!verifySessionAccess(session, queue)) {
                String description = "Cannot declare queue('" + queueName + "')," + " as exclusive queue with same name " + "declared on another session";
                ExecutionErrorCode errorCode = ExecutionErrorCode.RESOURCE_LOCKED;
                exception(session, method, errorCode, description);
            }
        } catch (AccessControlException e) {
            exception(session, method, ExecutionErrorCode.UNAUTHORIZED_ACCESS, e.getMessage());
        } catch (UnknownAlternateBindingException e) {
            exception(session, method, ExecutionErrorCode.NOT_FOUND, String.format("Unknown alternate exchange '%s'", e.getAlternateBindingName()));
        } catch (IllegalArgumentException | IllegalConfigurationException e) {
            exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, e.getMessage());
        }
    }
}
Also used : LifetimePolicy(org.apache.qpid.server.model.LifetimePolicy) NamedAddressSpace(org.apache.qpid.server.model.NamedAddressSpace) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) AccessControlException(java.security.AccessControlException) ExclusivityPolicy(org.apache.qpid.server.model.ExclusivityPolicy) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException) Queue(org.apache.qpid.server.model.Queue)

Example 5 with UnknownAlternateBindingException

use of org.apache.qpid.server.virtualhost.UnknownAlternateBindingException in project qpid-broker-j by apache.

the class AbstractQueue method validateOrCreateAlternateBinding.

private void validateOrCreateAlternateBinding(final Queue<?> queue, final boolean mayCreate) {
    Object value = queue.getAttribute(ALTERNATE_BINDING);
    if (value instanceof AlternateBinding) {
        AlternateBinding alternateBinding = (AlternateBinding) value;
        String destinationName = alternateBinding.getDestination();
        MessageDestination messageDestination = _virtualHost.getAttainedMessageDestination(destinationName, mayCreate);
        if (messageDestination == null) {
            throw new UnknownAlternateBindingException(destinationName);
        } else if (messageDestination == this) {
            throw new IllegalConfigurationException(String.format("Cannot create alternate binding for '%s' : Alternate binding destination cannot refer to self.", getName()));
        } else if (isDurable() && !messageDestination.isDurable()) {
            throw new IllegalConfigurationException(String.format("Cannot create alternate binding for '%s' : Alternate binding destination '%s' is not durable.", getName(), destinationName));
        }
    }
}
Also used : MessageDestination(org.apache.qpid.server.message.MessageDestination) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) UnknownAlternateBindingException(org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)

Aggregations

IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)6 UnknownAlternateBindingException (org.apache.qpid.server.virtualhost.UnknownAlternateBindingException)6 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)5 AccessControlException (java.security.AccessControlException)4 NamedAddressSpace (org.apache.qpid.server.model.NamedAddressSpace)4 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 MessageDestination (org.apache.qpid.server.message.MessageDestination)2 Exchange (org.apache.qpid.server.model.Exchange)2 ExclusivityPolicy (org.apache.qpid.server.model.ExclusivityPolicy)2 LifetimePolicy (org.apache.qpid.server.model.LifetimePolicy)2 NoFactoryForTypeException (org.apache.qpid.server.model.NoFactoryForTypeException)2 Queue (org.apache.qpid.server.model.Queue)2 ReservedExchangeNameException (org.apache.qpid.server.virtualhost.ReservedExchangeNameException)2 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 AlternateBinding (org.apache.qpid.server.model.AlternateBinding)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1