Package org.apache.qpid.server.queue

Examples of org.apache.qpid.server.queue.AMQQueue


    public void exchangeBound(Session session, ExchangeBound method)
    {

        ExchangeBoundResult result = new ExchangeBoundResult();
        Exchange exchange;
        AMQQueue queue;
        if(method.hasExchange())
        {
            exchange = getExchange(session, method.getExchange());

            if(exchange == null)
View Full Code Here


        VirtualHost virtualHost = getVirtualHost(session);
        DurableConfigurationStore store = virtualHost.getMessageStore();

        String queueName = method.getQueue();
        AMQQueue queue;
        QueueRegistry queueRegistry = getQueueRegistry(session);
        //TODO: do we need to check that the queue already exists with exactly the same "configuration"?

        synchronized (queueRegistry)
        {

            if (((queue = queueRegistry.getQueue(queueName)) == null))
            {

                if (method.getPassive())
                {
                    String description = "Queue: " + queueName + " not found on VirtualHost(" + virtualHost + ").";
                    ExecutionErrorCode errorCode = ExecutionErrorCode.NOT_FOUND;

                    exception(session, method, errorCode, description);

                    return;
                }
                else
                {
                    try
                    {
                        queue = createQueue(queueName, method, virtualHost, (ServerSession)session);
                        if(!method.getExclusive() && method.getAutoDelete())
                        {
                            queue.setDeleteOnNoConsumers(true);
                        }

                        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);

                        }

                        if (method.hasAutoDelete()
                            && method.getAutoDelete()
                            && method.hasExclusive()
                            && method.getExclusive())
                        {
                            final AMQQueue q = queue;
                            final ServerSession.Task deleteQueueTask = new ServerSession.Task()
                                {
                                    public void doTask(ServerSession session)
                                    {
                                        try
                                        {
                                            q.delete();
                                        }
                                        catch (AMQException e)
                                        {
                                            exception(session, method, e, "Cannot delete '" + method.getQueue());
                                        }
                                    }
                                };
                            final ServerSession s = (ServerSession) session;
                            s.addSessionCloseTask(deleteQueueTask);
                            queue.addQueueDeleteTask(new AMQQueue.Task()
                                {
                                    public void doTask(AMQQueue queue) throws AMQException
                                    {
                                        s.removeSessionCloseTask(deleteQueueTask);
                                    }
                                });
                        }
                        if (method.hasExclusive()
                            && method.getExclusive())
                        {
                            final AMQQueue q = queue;
                            final ServerSession.Task removeExclusive = new ServerSession.Task()
                            {
                                public void doTask(ServerSession session)
                                {
                                    q.setAuthorizationHolder(null);
                                    q.setExclusiveOwningSession(null);
                                }
                            };
                            final ServerSession s = (ServerSession) session;
                            q.setExclusiveOwningSession(s);
                            s.addSessionCloseTask(removeExclusive);
                            queue.addQueueDeleteTask(new AMQQueue.Task()
                            {
                                public void doTask(AMQQueue queue) throws AMQException
                                {
View Full Code Here

                                   final ServerSession session)
            throws AMQException
    {
        String owner = body.getExclusive() ? session.getClientID() : null;

        final AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateQueueUUID(queueName, virtualHost.getName()), queueName, body.getDurable(), owner,
                                                                  body.getAutoDelete(), body.getExclusive(), virtualHost, body.getArguments());

        return queue;
    }
View Full Code Here

            exception(session, method, ExecutionErrorCode.INVALID_ARGUMENT, "No queue name supplied");

        }
        else
        {
            AMQQueue queue = getQueue(session, queueName);


            if (queue == null)
            {
                exception(session, method, ExecutionErrorCode.NOT_FOUND, "No queue " + queueName + " found");
            }
            else
            {
                if(queue.getAuthorizationHolder() != null && queue.getAuthorizationHolder() != session)
                {
                    exception(session,method,ExecutionErrorCode.RESOURCE_LOCKED, "Exclusive Queue: " + queueName + " owned exclusively by another session");
                }
                else if(queue.isExclusive() && queue.getExclusiveOwningSession()  != null && queue.getExclusiveOwningSession() != session)
                {
                    exception(session,method,ExecutionErrorCode.RESOURCE_LOCKED, "Exclusive Queue: " + queueName + " owned exclusively by another session");
                }
                else if (method.getIfEmpty() && !queue.isEmpty())
                {
                    exception(session, method, ExecutionErrorCode.PRECONDITION_FAILED, "Queue " + queueName + " not empty");
                }
                else if (method.getIfUnused() && !queue.isUnused())
                {
                    // TODO - Error code
                    exception(session, method, ExecutionErrorCode.PRECONDITION_FAILED, "Queue " + queueName + " in use");

                }
                else
                {
                    VirtualHost virtualHost = getVirtualHost(session);

                    try
                    {
                        queue.delete();
                        if (queue.isDurable() && !queue.isAutoDelete())
                        {
                            DurableConfigurationStore store = virtualHost.getMessageStore();
                            store.removeQueue(queue);
                        }
                    }
View Full Code Here

        {
            exception(session, method, ExecutionErrorCode.ILLEGAL_ARGUMENT, "No queue name supplied");
        }
        else
        {
            AMQQueue queue = getQueue(session, queueName);

            if (queue == null)
            {
                exception(session, method, ExecutionErrorCode.NOT_FOUND, "No queue " + queueName + " found");
            }
            else
            {
                try
                {
                    queue.clearQueue();
                }
                catch (AMQException e)
                {
                    exception(session, method, e, "Cannot purge queue '" + queueName);
                }
View Full Code Here

    @Override
    public void queueQuery(Session session, QueueQuery method)
    {
        QueueQueryResult result = new QueueQueryResult();

        AMQQueue queue = getQueue(session, method.getQueue());

        if(queue != null)
        {
            result.setQueue(queue.getNameShortString().toString());
            result.setDurable(queue.isDurable());
            result.setExclusive(queue.isExclusive());
            result.setAutoDelete(queue.isAutoDelete());
            result.setArguments(queue.getArguments());
            result.setMessageCount(queue.getMessageCount());
            result.setSubscriberCount(queue.getConsumerCount());

        }


        session.executionResult((int) method.getId(), result);
View Full Code Here

        else
        {
            queueName = body.getQueue().intern();
        }

        AMQQueue queue;
       
        //TODO: do we need to check that the queue already exists with exactly the same "configuration"?

        AMQChannel channel = protocolConnection.getChannel(channelId);

        if (channel == null)
        {
            throw body.getChannelNotFoundException(channelId);
        }

        synchronized (queueRegistry)
        {
            queue = queueRegistry.getQueue(queueName);

            AMQSessionModel owningSession = null;

            if (queue != null)
            {
                owningSession = queue.getExclusiveOwningSession();
            }

            if (queue == null)
            {
                if (body.getPassive())
                {
                    String msg = "Queue: " + queueName + " not found on VirtualHost(" + virtualHost + ").";
                    throw body.getChannelException(AMQConstant.NOT_FOUND, msg);
                }
                else
                {
                    queue = createQueue(queueName, body, virtualHost, protocolConnection);
                    queue.setAuthorizationHolder(protocolConnection);
                    if (queue.isDurable() && !queue.isAutoDelete())
                    {
                        store.createQueue(queue, body.getArguments());
                    }
                    if(body.getAutoDelete())
                    {
                        queue.setDeleteOnNoConsumers(true);
                    }
                    queueRegistry.registerQueue(queue);
                    if (body.getExclusive())
                    {
                        queue.setExclusiveOwningSession(protocolConnection.getChannel(channelId));
                        queue.setAuthorizationHolder(protocolConnection);

                        if(!body.getDurable())
                        {
                            final AMQQueue q = queue;
                            final AMQProtocolSession.Task sessionCloseTask = new AMQProtocolSession.Task()
                            {
                                public void doTask(AMQProtocolSession session) throws AMQException
                                {
                                    q.setExclusiveOwningSession(null);
                                }
                            };
                            protocolConnection.addSessionCloseTask(sessionCloseTask);
                            queue.addQueueDeleteTask(new AMQQueue.Task() {
                                public void doTask(AMQQueue queue) throws AMQException
View Full Code Here

        String owner = body.getExclusive() ? AMQShortString.toString(session.getContextKey()) : null;

        Map<String, Object> arguments = FieldTable.convertToMap(body.getArguments());
        String queueNameString = AMQShortString.toString(queueName);

        final AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(UUIDGenerator.generateQueueUUID(queueNameString, virtualHost.getName()),
                                                                  queueNameString, body.getDurable(), owner, body.getAutoDelete(),
                                                                  body.getExclusive(),virtualHost, arguments);

        if (body.getExclusive() && !body.getDurable())
        {
            final AMQProtocolSession.Task deleteQueueTask =
                    new AMQProtocolSession.Task()
                    {
                        public void doTask(AMQProtocolSession session) throws AMQException
                        {
                            if (registry.getQueue(queueName) == queue)
                            {
                                queue.delete();
                            }
                        }
                    };

            session.addSessionCloseTask(deleteQueueTask);

            queue.addQueueDeleteTask(new AMQQueue.Task()
            {
                public void doTask(AMQQueue queue)
                {
                    session.removeSessionCloseTask(deleteQueueTask);
                }
View Full Code Here

        }
    }

    private void configureQueue(QueueConfiguration queueConfiguration) throws AMQException, ConfigurationException
    {
        AMQQueue queue = AMQQueueFactory.createAMQQueueImpl(queueConfiguration, this);
        String queueName = queue.getName();

        if (queue.isDurable())
        {
            getMessageStore().createQueue(queue);
        }

        //get the exchange name (returns default exchange name if none was specified)
View Full Code Here

    public void queue(UUID id, String queueName, String owner, boolean exclusive, FieldTable arguments, UUID alternateExchangeId)
    {
        try
        {
            AMQQueue q = _virtualHost.getQueueRegistry().getQueue(queueName);
   
            if (q == null)
            {
                q = AMQQueueFactory.createAMQQueueImpl(id, queueName, true, owner, false, exclusive, _virtualHost,
                                                       FieldTable.convertToMap(arguments));
                _virtualHost.getQueueRegistry().registerQueue(q);

                if (alternateExchangeId != null)
                {
                    Exchange altExchange = _virtualHost.getExchangeRegistry().getExchange(alternateExchangeId);
                    if (altExchange == null)
                    {
                        _logger.error("Unknown exchange id " + alternateExchangeId + ", cannot set alternate exchange on queue with id " + id);
                        return;
                    }
                    q.setAlternateExchange(altExchange);
                }
            }
   
            CurrentActor.get().message(_logSubject, TransactionLogMessages.RECOVERY_START(queueName, true));
   
View Full Code Here

TOP

Related Classes of org.apache.qpid.server.queue.AMQQueue

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.