Package org.apache.qpid.server.exchange

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


                false,
                false,
                null);

        assertEquals("Unexpected maximum delivery count", 5, queue.getMaximumDeliveryCount());
        Exchange altExchange = queue.getAlternateExchange();
        assertNotNull("Queue should have an alternate exchange as DLQ is enabled", altExchange);
        assertEquals("Alternate exchange name was not as expected", dlExchangeName, altExchange.getName());
        assertEquals("Alternate exchange type was not as expected", ExchangeDefaults.FANOUT_EXCHANGE_CLASS, altExchange.getTypeName());

        assertNotNull("The alternate exchange was not registered as expected", _virtualHost.getExchange(dlExchangeName));
        assertEquals("The registered exchange was not the expected exchange instance", altExchange, _virtualHost.getExchange(dlExchangeName));

        AMQQueue dlQueue = _virtualHost.getQueue(dlQueueName);
        assertNotNull("The DLQ was not registered as expected", dlQueue);
        assertTrue("DLQ should have been bound to the alternate exchange", altExchange.isBound(dlQueue));
        assertNull("DLQ should have no alternate exchange", dlQueue.getAlternateExchange());
        assertEquals("DLQ should have a zero maximum delivery count", 0, dlQueue.getMaximumDeliveryCount());

        //2 queues should have been registered
        verifyRegisteredQueueCount(2);
View Full Code Here


    }

    @Override
    public void messageTransfer(Session ssn, final MessageTransfer xfr)
    {
        final Exchange exchange = getExchangeForMessage(ssn, xfr);

        DeliveryProperties delvProps = null;
        if(xfr.getHeader() != null && (delvProps = xfr.getHeader().getDeliveryProperties()) != null && delvProps.hasTtl() && !delvProps
                .hasExpiration())
        {
            delvProps.setExpiration(System.currentTimeMillis() + delvProps.getTtl());
        }

        final MessageMetaData_0_10 messageMetaData = new MessageMetaData_0_10(xfr);
        messageMetaData.setConnectionReference(((ServerSession)ssn).getReference());

        if (!getVirtualHost(ssn).getSecurityManager().authorisePublish(messageMetaData.isImmediate(), messageMetaData.getRoutingKey(), exchange.getName()))
        {
            ExecutionErrorCode errorCode = ExecutionErrorCode.UNAUTHORIZED_ACCESS;
            String description = "Permission denied: exchange-name '" + exchange.getName() + "'";
            exception(ssn, xfr, errorCode, description);

            return;
        }

        final Exchange exchangeInUse;
        List<? extends BaseQueue> queues = exchange.route(messageMetaData);
        if(queues.isEmpty() && exchange.getAlternateExchange() != null)
        {
            final Exchange alternateExchange = exchange.getAlternateExchange();
            queues = alternateExchange.route(messageMetaData);
            if (!queues.isEmpty())
            {
                exchangeInUse = alternateExchange;
            }
            else
View Full Code Here

            }
        }

        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.getTypeName().equals(method.getType())
                        && (method.getType() != null && method.getType().length() > 0))
                {
                    exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to redeclare exchange: "
                            + exchangeName + " of type " + exchange.getTypeName() + " to " + method.getType() + ".");
                }
            }
        }
        else
        {

            try
            {
                virtualHost.createExchange(null,
                        method.getExchange(),
                        method.getType(),
                        method.getDurable(),
                        method.getAutoDelete(),
                        method.getAlternateExchange());
            }
            catch(ReservedExchangeNameException e)
            {
                exception(session, method, ExecutionErrorCode.NOT_ALLOWED, "Attempt to declare exchange: "
                                            + exchangeName + " which begins with reserved name or prefix.");
            }
            catch(UnknownExchangeException e)
            {
                exception(session, method, ExecutionErrorCode.NOT_FOUND,
                                                            "Unknown alternate exchange " + e.getExchangeName());
            }
            catch(AMQUnknownExchangeType e)
            {
                exception(session, method, ExecutionErrorCode.NOT_FOUND, "Unknown Exchange Type: " + method.getType());
            }
            catch(ExchangeExistsException e)
            {
                Exchange exchange = e.getExistingExchange();
                if(!exchange.getTypeName().equals(method.getType()))
                {
                    exception(session, method, ExecutionErrorCode.NOT_ALLOWED,
                            "Attempt to redeclare exchange: " + exchangeName
                                    + " of type " + exchange.getTypeName()
                                    + " to " + method.getType() +".");
                }
                else if(method.hasAlternateExchange()
                          && (exchange.getAlternateExchange() == null ||
                              !method.getAlternateExchange().equals(exchange.getAlternateExchange().getName())))
                {
                    exception(session, method, ExecutionErrorCode.NOT_ALLOWED,
                            "Attempt to change alternate exchange of: " + exchangeName
                                    + " from " + exchange.getAlternateExchange()
                                    + " to " + method.getAlternateExchange() +".");
                }
            }
            catch (AMQException e)
            {
View Full Code Here

    private Exchange getExchangeForMessage(Session ssn, MessageTransfer xfr)
    {
        VirtualHost virtualHost = getVirtualHost(ssn);

        Exchange exchange;
        if(xfr.hasDestination())
        {
            exchange = virtualHost.getExchange(xfr.getDestination());
            if(exchange == null)
            {
View Full Code Here

            {
                exception(session, method, ExecutionErrorCode.INVALID_ARGUMENT, "Delete not allowed for default exchange");
                return;
            }

            Exchange exchange = getExchange(session, method.getExchange());

            if(exchange == null)
            {
                exception(session, method, ExecutionErrorCode.NOT_FOUND, "No such exchange '" + method.getExchange() + "'");
            }
View Full Code Here

                {
                    name = UUID.randomUUID().toString();
                }

                queue = _vhost.getQueueRegistry().getQueue(name);
                Exchange exchange = exchangeDestination.getExchange();

                if(queue == null)
                {
                    queue = AMQQueueFactory.createAMQQueueImpl(
                                UUIDGenerator.generateQueueUUID(name, _vhost.getName()),
                                name,
                                isDurable,
                                null,
                                true,
                                true,
                                _vhost,
                                Collections.EMPTY_MAP);
                }
                else
                {
                    List<Binding> bindings = queue.getBindings();
                    List<Binding> bindingsToRemove = new ArrayList<Binding>();
                    for(Binding existingBinding : bindings)
                    {
                        if(existingBinding.getExchange() != _vhost.getExchangeRegistry().getDefaultExchange()
                            && existingBinding.getExchange() != exchange)
                        {
                            bindingsToRemove.add(existingBinding);
                        }
                    }
                    for(Binding existingBinding : bindingsToRemove)
                    {
                        existingBinding.getExchange().removeBinding(existingBinding);
                    }
                }


                String binding = "";

                Map<Symbol,Filter> filters = source.getFilter();
                Map<Symbol,Filter> actualFilters = new HashMap<Symbol,Filter>();
                boolean hasBindingFilter = false;
                if(filters != null && !filters.isEmpty())
                {

                    for(Map.Entry<Symbol,Filter> entry : filters.entrySet())
                    {
                        if(!hasBindingFilter
                           && entry.getValue() instanceof ExactSubjectFilter
                           && exchange.getType() == DirectExchange.TYPE)
                        {
                            ExactSubjectFilter filter = (ExactSubjectFilter) filters.values().iterator().next();
                            source.setFilter(filters);
                            binding = filter.getValue();
                            actualFilters.put(entry.getKey(), entry.getValue());
                            hasBindingFilter = true;
                        }
                        else if(!hasBindingFilter
                                && entry.getValue() instanceof MatchingSubjectFilter
                                && exchange.getType() == TopicExchange.TYPE)
                        {
                            MatchingSubjectFilter filter = (MatchingSubjectFilter) filters.values().iterator().next();
                            source.setFilter(filters);
                            binding = filter.getValue();
                            actualFilters.put(entry.getKey(), entry.getValue());
View Full Code Here


                    }
                    else
                    {
                        Exchange exchg = _vhost.getExchangeRegistry().getExchange(addr);
                        if(exchg != null)
                        {
                            destination = new ExchangeDestination(exchg, source.getDurable(), source.getExpiryPolicy());
                        }
                        else
                        {

                            endpoint.setSource(null);
                            destination = null;
                        }
                    }

                }
                else
                {
                    destination = null;
                }

                if(destination != null)
                {
                    final SendingLinkEndpoint sendingLinkEndpoint = (SendingLinkEndpoint) endpoint;
                    try
                    {
                        final SendingLink_1_0 sendingLink = new SendingLink_1_0(new SendingLinkAttachment(this, sendingLinkEndpoint),
                                                                                _vhost,
                                                                                (SendingDestination) destination
                        );
                        sendingLinkEndpoint.setLinkEventListener(sendingLink);
                        link = sendingLink;
                        if(TerminusDurability.UNSETTLED_STATE.equals(source.getDurable()))
                        {
                            linkRegistry.registerSendingLink(endpoint.getName(), sendingLink);
                        }
                    }
                    catch(AmqpErrorException e)
                    {
                        e.printStackTrace();
                        destination = null;
                        sendingLinkEndpoint.setSource(null);
                        error = e.getError();
                    }
                }
            }
            else
            {
                Source newSource = (Source) endpoint.getSource();

                Source oldSource = (Source) previousLink.getEndpoint().getSource();
                final TerminusDurability newSourceDurable = newSource == null ? null : newSource.getDurable();
                if(newSourceDurable != null)
                {
                    oldSource.setDurable(newSourceDurable);
                    if(newSourceDurable.equals(TerminusDurability.NONE))
                    {
                        linkRegistry.unregisterSendingLink(endpoint.getName());
                    }
                }
                endpoint.setSource(oldSource);
                SendingLinkEndpoint sendingLinkEndpoint = (SendingLinkEndpoint) endpoint;
                previousLink.setLinkAttachment(new SendingLinkAttachment(this, sendingLinkEndpoint));
                sendingLinkEndpoint.setLinkEventListener(previousLink);
                link = previousLink;
                endpoint.setLocalUnsettled(previousLink.getUnsettledOutcomeMap());
            }
        }
        else
        {
            if(endpoint.getTarget() instanceof Coordinator)
            {
                Coordinator coordinator = (Coordinator) endpoint.getTarget();
                TxnCapability[] capabilities = coordinator.getCapabilities();
                boolean localTxn = false;
                boolean multiplePerSession = false;
                if(capabilities != null)
                {
                    for(TxnCapability capability : capabilities)
                    {
                        if(capability.equals(TxnCapability.LOCAL_TXN))
                        {
                            localTxn = true;
                        }
                        else if(capability.equals(TxnCapability.MULTI_TXNS_PER_SSN))
                        {
                            multiplePerSession = true;
                        }
                        else
                        {
                            error = new Error();
                            error.setCondition(AmqpError.NOT_IMPLEMENTED);
                            error.setDescription("Unsupported capability: " + capability);
                            break;
                        }
                    }
                }

       /*         if(!localTxn)
                {
                    capabilities.add(TxnCapabilities.LOCAL_TXN);
                }*/

                final ReceivingLinkEndpoint receivingLinkEndpoint = (ReceivingLinkEndpoint) endpoint;
                final TxnCoordinatorLink_1_0 coordinatorLink =
                        new TxnCoordinatorLink_1_0(_vhost, this, receivingLinkEndpoint, _openTransactions);
                receivingLinkEndpoint.setLinkEventListener(coordinatorLink);
                link = coordinatorLink;


            }
            else
            {

                ReceivingLink_1_0 previousLink = linkRegistry.getDurableReceivingLink(endpoint.getName());

                if(previousLink == null)
                {

                    Target target = (Target) endpoint.getTarget();

                    if(target != null)
                    {
                        if(Boolean.TRUE.equals(target.getDynamic()))
                        {

                            AMQQueue tempQueue = createTemporaryQueue(target.getDynamicNodeProperties());
                            target.setAddress(tempQueue.getName());
                        }

                        String addr = target.getAddress();
                        Exchange exchg = _vhost.getExchangeRegistry().getExchange(addr);
                        if(exchg != null)
                        {
                            destination = new ExchangeDestination(exchg, target.getDurable(),
                                                                  target.getExpiryPolicy());
                        }
View Full Code Here

        {
            final ServerMessage msg = rejectedQueueEntry.getMessage();

            final AMQQueue queue = rejectedQueueEntry.getQueue();

            final Exchange altExchange = queue.getAlternateExchange();
            unackedMap.remove(deliveryTag);

            if (altExchange == null)
            {
                _logger.debug("No alternate exchange configured for queue, must discard the message as unable to DLQ: delivery tag: " + deliveryTag);
                _actor.message(_logSubject, ChannelMessages.DISCARDMSG_NOALTEXCH(msg.getMessageNumber(), queue.getName(), msg.getRoutingKey()));
                rejectedQueueEntry.discard();
                return;
            }

            final InboundMessage m = new InboundMessageAdapter(rejectedQueueEntry);

            final List<? extends BaseQueue> destinationQueues = altExchange.route(m);

            if (destinationQueues == null || destinationQueues.isEmpty())
            {
                _logger.debug("Routing process provided no queues to enqueue the message on, must discard message as unable to DLQ: delivery tag: " + deliveryTag);
                _actor.message(_logSubject, ChannelMessages.DISCARDMSG_NOROUTE(msg.getMessageNumber(), altExchange.getName()));
                rejectedQueueEntry.discard();
                return;
            }

            rejectedQueueEntry.routeToAlternate();
View Full Code Here

        }
    }

    protected void sendToDLQOrDiscard(QueueEntry entry)
    {
        final Exchange alternateExchange = entry.getQueue().getAlternateExchange();
        final LogActor logActor = CurrentActor.get();
        final ServerMessage msg = entry.getMessage();
        if (alternateExchange != null)
        {
            final InboundMessage m = new InboundMessageAdapter(entry);

            final List<? extends BaseQueue> destinationQueues = alternateExchange.route(m);

            if (destinationQueues == null || destinationQueues.isEmpty())
            {
                entry.discard();

                logActor.message( ChannelMessages.DISCARDMSG_NOROUTE(msg.getMessageNumber(), alternateExchange.getName()));
            }
            else
            {
                entry.routeToAlternate();
View Full Code Here

                        }

                        final String alternateExchangeName = method.getAlternateExchange();
                        if(alternateExchangeName != null && alternateExchangeName.length() != 0)
                        {
                            Exchange alternate = getExchange(session, alternateExchangeName);
                            queue.setAlternateExchange(alternate);
                        }

                        if(method.hasArguments()  && method.getArguments() != null)
                        {
                            if(method.getArguments().containsKey(QUEUE_ARGUMENT_NO_LOCAL))
                            {
                                Object noLocal = method.getArguments().get(QUEUE_ARGUMENT_NO_LOCAL);
                                queue.setNoLocal(convertBooleanValue(noLocal));
                            }
                        }


                        if (queue.isDurable() && !queue.isAutoDelete())
                        {
                            if(method.hasArguments() && method.getArguments() != null)
                            {
                                Map<String,Object> args = method.getArguments();
                                FieldTable ftArgs = new FieldTable();
                                for(Map.Entry<String, Object> entry : args.entrySet())
                                {
                                    ftArgs.put(new AMQShortString(entry.getKey()), entry.getValue());
                                }
                                store.createQueue(queue, ftArgs);
                            }
                            else
                            {
                                store.createQueue(queue);
                            }
                        }
                        queueRegistry.registerQueue(queue);
                        boolean autoRegister = ApplicationRegistry.getInstance().getConfiguration().getQueueAutoRegister();

                        if (autoRegister)
                        {

                            ExchangeRegistry exchangeRegistry = getExchangeRegistry(session);

                            Exchange defaultExchange = exchangeRegistry.getDefaultExchange();

                            virtualHost.getBindingFactory().addBinding(queueName, queue, defaultExchange, null);

                        }
View Full Code Here

TOP

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

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.