Package org.apache.qpid.server.exchange

Examples of org.apache.qpid.server.exchange.ExchangeImpl


        if (_logger.isDebugEnabled())
        {
            _logger.debug("Request to declare exchange of type " + body.getType() + " with name " + exchangeName);
        }

        ExchangeImpl exchange;

        if(isDefaultExchange(exchangeName))
        {
            if(!new AMQShortString(DirectExchange.TYPE.getType()).equals(body.getType()))
            {
                throw new AMQConnectionException(AMQConstant.NOT_ALLOWED, "Attempt to redeclare default exchange: "
                                                                          + " of type "
                                                                          + DirectExchange.TYPE.getType()
                                                                          + " to " + body.getType() +".",
                                                 body.getClazz(), body.getMethod(),
                                                 body.getMajor(), body.getMinor(),null);
            }
        }
        else
        {
            if (body.getPassive())
            {
                exchange = virtualHost.getExchange(exchangeName.toString());
                if(exchange == null)
                {
                    throw body.getChannelException(AMQConstant.NOT_FOUND, "Unknown exchange: " + exchangeName);
                }
                else if (!(body.getType() == null || body.getType().length() ==0) && !exchange.getTypeName().equals(body.getType().asString()))
                {

                    throw new AMQConnectionException(AMQConstant.NOT_ALLOWED, "Attempt to redeclare exchange: " +
                                      exchangeName + " of type " + exchange.getTypeName()
                                      + " to " + body.getType() +".",body.getClazz(), body.getMethod(),body.getMajor(),body.getMinor(),null);
                }

            }
            else
            {
                try
                {
                    String name = exchangeName == null ? null : exchangeName.intern().toString();
                    String type = body.getType() == null ? null : body.getType().intern().toString();
                    Map<String,Object> attributes = new HashMap<String, Object>();

                    attributes.put(org.apache.qpid.server.model.Exchange.ID, null);
                    attributes.put(org.apache.qpid.server.model.Exchange.NAME,name);
                    attributes.put(org.apache.qpid.server.model.Exchange.TYPE,type);
                    attributes.put(org.apache.qpid.server.model.Exchange.DURABLE, body.getDurable());
                    attributes.put(org.apache.qpid.server.model.Exchange.LIFETIME_POLICY,
                                   body.getAutoDelete() ? LifetimePolicy.DELETE_ON_NO_LINKS : LifetimePolicy.PERMANENT);
                    attributes.put(org.apache.qpid.server.model.Exchange.ALTERNATE_EXCHANGE, null);
                    exchange = virtualHost.createExchange(attributes);

                }
                catch(ReservedExchangeNameException e)
                {
                    throw body.getConnectionException(AMQConstant.NOT_ALLOWED,
                                              "Attempt to declare exchange: " + exchangeName +
                                              " which begins with reserved prefix.");

                }
                catch(ExchangeExistsException e)
                {
                    exchange = e.getExistingExchange();
                    if(!new AMQShortString(exchange.getTypeName()).equals(body.getType()))
                    {
                        throw new AMQConnectionException(AMQConstant.NOT_ALLOWED, "Attempt to redeclare exchange: "
                                                                                  + exchangeName + " of type "
                                                                                  + exchange.getTypeName()
                                                                                  + " to " + body.getType() +".",
                                                         body.getClazz(), body.getMethod(),
                                                         body.getMajor(), body.getMinor(),null);
                    }
                }
View Full Code Here


                }
            }
        }
        else
        {
            ExchangeImpl exchange = virtualHost.getExchange(exchangeName.toString());
            if (exchange == null)
            {


                response = methodRegistry.createExchangeBoundOkBody(EXCHANGE_NOT_FOUND,
                                                                    AMQShortString.validValueOf("Exchange '" + exchangeName + "' not found"));
            }
            else if (routingKey == null)
            {
                if (queueName == null)
                {
                    if (exchange.hasBindings())
                    {
                        response = methodRegistry.createExchangeBoundOkBody(OK, null);
                    }
                    else
                    {

                        response = methodRegistry.createExchangeBoundOkBody(NO_BINDINGS,  // replyCode
                            null)// replyText
                    }
                }
                else
                {

                    AMQQueue queue = virtualHost.getQueue(queueName.toString());
                    if (queue == null)
                    {

                        response = methodRegistry.createExchangeBoundOkBody(QUEUE_NOT_FOUND,  // replyCode
                            AMQShortString.validValueOf("Queue '" + queueName + "' not found"))// replyText
                    }
                    else
                    {
                        if (exchange.isBound(queue))
                        {

                            response = methodRegistry.createExchangeBoundOkBody(OK,  // replyCode
                                null)// replyText
                        }
                        else
                        {

                            response = methodRegistry.createExchangeBoundOkBody(QUEUE_NOT_BOUND,  // replyCode
                                AMQShortString.validValueOf("Queue '" + queueName + "' not bound to exchange '" + exchangeName + "'"))// replyText
                        }
                    }
                }
            }
            else if (queueName != null)
            {
                AMQQueue queue = virtualHost.getQueue(queueName.toString());
                if (queue == null)
                {

                    response = methodRegistry.createExchangeBoundOkBody(QUEUE_NOT_FOUND,  // replyCode
                        AMQShortString.validValueOf("Queue '" + queueName + "' not found"))// replyText
                }
                else
                {
                    String bindingKey = body.getRoutingKey() == null ? null : body.getRoutingKey().asString();
                    if (exchange.isBound(bindingKey, queue))
                    {

                        response = methodRegistry.createExchangeBoundOkBody(OK,  // replyCode
                            null)// replyText
                    }
                    else
                    {

                        String message = "Queue '" + queueName + "' not bound with routing key '" +
                                            body.getRoutingKey() + "' to exchange '" + exchangeName + "'";

                        response = methodRegistry.createExchangeBoundOkBody(SPECIFIC_QUEUE_NOT_BOUND_WITH_RK,  // replyCode
                            AMQShortString.validValueOf(message))// replyText
                    }
                }
            }
            else
            {
                if (exchange.isBound(body.getRoutingKey() == null ? "" : body.getRoutingKey().asString()))
                {

                    response = methodRegistry.createExchangeBoundOkBody(OK,  // replyCode
                        null)// replyText
                }
View Full Code Here

            throw body.getConnectionException(AMQConstant.NOT_ALLOWED, "Cannot bind the queue " + queueName + " to the default exchange");
        }

        final String exchangeName = body.getExchange().toString();

        final ExchangeImpl exch = virtualHost.getExchange(exchangeName);
        if (exch == null)
        {
            throw body.getChannelException(AMQConstant.NOT_FOUND, "Exchange " + exchangeName + " does not exist.");
        }


        try
        {

            Map<String,Object> arguments = FieldTable.convertToMap(body.getArguments());
            String bindingKey = String.valueOf(routingKey);

            if (!exch.isBound(bindingKey, arguments, queue))
            {

                if(!exch.addBinding(bindingKey, queue, arguments) && TopicExchange.TYPE.equals(exch.getExchangeType()))
                {
                    exch.replaceBinding(bindingKey, queue, arguments);
                }
            }
        }
        catch (AccessControlException e)
        {
View Full Code Here

                throw body.getConnectionException(AMQConstant.NOT_ALLOWED, "Default Exchange cannot be deleted");
            }

            final String exchangeName = body.getExchange().toString();

            final ExchangeImpl exchange = virtualHost.getExchange(exchangeName);
            if(exchange == null)
            {
                throw body.getChannelException(AMQConstant.NOT_FOUND, "No such exchange: " + body.getExchange());
            }
View Full Code Here

*/
public class ExchangeMessagesTest extends AbstractTestMessages
{
    public void testExchangeCreated_Transient() throws Exception
    {
        ExchangeImpl exchange = BrokerTestHelper.createExchange("test", false, getEventLogger());

        String type = exchange.getType();
        String name = exchange.getName();

        _logMessage = ExchangeMessages.CREATED(type, name, false);
        List<Object> log = getLog();

        String[] expected = {"Create :", "Type:", type, "Name:", name};
View Full Code Here

        validateLogMessageNoSubject(log, "EXH-1001", expected);
    }

    public void testExchangeCreated_Persistent() throws Exception
    {
        ExchangeImpl exchange = BrokerTestHelper.createExchange("test", true, getEventLogger());

        String type = exchange.getType();
        String name = exchange.getName();

        _logMessage = ExchangeMessages.CREATED(type, name, true);
        List<Object> log = getLog();

        String[] expected = {"Create :", "Durable", "Type:", type, "Name:", name};
View Full Code Here

        validateLogMessage(log, "EXH-1002", expected);
    }

    public void testExchangeDiscardedMessage() throws Exception
    {
        ExchangeImpl exchange = BrokerTestHelper.createExchange("test", false, getEventLogger());

        final String name = exchange.getName();
        final String routingKey = "routingKey";
        clearLog();
        _logMessage = ExchangeMessages.DISCARDMSG(name, routingKey);
        List<Object> log = performLog();
View Full Code Here

        setTestSystemProperty(BrokerProperties.PROPERTY_MSG_AUTH, "true");
        AMQChannel channel = new AMQChannel(_protocolSession, 1, _virtualHost.getMessageStore());
        channel.setLocalTransactional();

        MessagePublishInfo info = mock(MessagePublishInfo.class);
        ExchangeImpl e = mock(ExchangeImpl.class);
        ContentHeaderBody contentHeaderBody= mock(ContentHeaderBody.class);
        BasicContentHeaderProperties properties = mock(BasicContentHeaderProperties.class);

        when(contentHeaderBody.getProperties()).thenReturn(properties);
        when(info.getExchange()).thenReturn(new AMQShortString("test"));
View Full Code Here

        setTestSystemProperty(BrokerProperties.PROPERTY_MSG_AUTH, "true");
        AMQChannel channel = new AMQChannel(_protocolSession, 1, _virtualHost.getMessageStore());
        channel.setLocalTransactional();

        MessagePublishInfo info = mock(MessagePublishInfo.class);
        ExchangeImpl e = mock(ExchangeImpl.class);
        ContentHeaderBody contentHeaderBody= mock(ContentHeaderBody.class);
        BasicContentHeaderProperties properties = mock(BasicContentHeaderProperties.class);

        when(contentHeaderBody.getProperties()).thenReturn(properties);
        when(info.getExchange()).thenReturn(new AMQShortString("test"));
View Full Code Here

                if(exchangeName == null)
                {
                    exchangeName = "";
                }

                ExchangeImpl exchange = vhost.getExchange(exchangeName);
                String exchangeClass = exchange == null
                                            ? ExchangeDefaults.DIRECT_EXCHANGE_CLASS
                                            : exchange.getType();
                props.setReplyTo(exchangeClass + "://" + exchangeName + "//?routingkey='" + (routingKey == null
                                                                                             ? ""
                                                                                             : routingKey + "'"));

            }
View Full Code Here

TOP

Related Classes of org.apache.qpid.server.exchange.ExchangeImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.