Examples of AMQChannel


Examples of org.apache.qpid.server.AMQChannel

        return channel;
    }

    public AMQChannel getChannel(int channelId)
    {
        final AMQChannel channel =
                ((channelId & CHANNEL_CACHE_SIZE) == channelId) ? _cachedChannels[channelId] : _channelMap.get(channelId);
        if ((channel == null) || channel.isClosing())
        {
            return null;
        }
        else
        {
View Full Code Here

Examples of org.apache.qpid.server.AMQChannel

     * @throws AMQException             if an error occurs closing the channel
     * @throws IllegalArgumentException if the channel id is not valid
     */
    public void closeChannel(int channelId) throws AMQException
    {
        final AMQChannel channel = getChannel(channelId);
        if (channel == null)
        {
            throw new IllegalArgumentException("Unknown channel id");
        }
        else
        {
            try
            {
                channel.close();
                markChannelAwaitingCloseOk(channelId);
            }
            finally
            {
                removeChannel(channelId);
View Full Code Here

Examples of org.apache.qpid.server.AMQChannel

    public void methodReceived(AMQStateManager stateManager, BasicConsumeBody body, int channelId) throws AMQException
    {
        AMQProtocolSession protocolConnection = stateManager.getProtocolSession();

        AMQChannel channel = protocolConnection.getChannel(channelId);

        VirtualHost vHost = protocolConnection.getVirtualHost();

        if (channel == null)
        {
            throw body.getChannelNotFoundException(channelId);
        }
        else
        {
            if (_logger.isDebugEnabled())
            {
                _logger.debug("BasicConsume: from '" + body.getQueue() +
                              "' for:" + body.getConsumerTag() +
                              " nowait:" + body.getNowait() +
                              " args:" + body.getArguments());
            }

            AMQQueue queue = body.getQueue() == null ? channel.getDefaultQueue() : vHost.getQueueRegistry().getQueue(body.getQueue().intern());

            if (queue == null)
            {
                if (_logger.isDebugEnabled())
                {
                    _logger.debug("No queue for '" + body.getQueue() + "'");
                }
                if (body.getQueue() != null)
                {
                    String msg = "No such queue, '" + body.getQueue() + "'";
                    throw body.getChannelException(AMQConstant.NOT_FOUND, msg);
                }
                else
                {
                    String msg = "No queue name provided, no default queue defined.";
                    throw body.getConnectionException(AMQConstant.NOT_ALLOWED, msg);
                }
            }
            else
            {
                final AMQShortString consumerTagName;

                if (queue.isExclusive() && !queue.isDurable())
                {
                    AMQSessionModel session = queue.getExclusiveOwningSession();
                    if (session == null || session.getConnectionModel() != protocolConnection)
                    {
                        throw body.getConnectionException(AMQConstant.NOT_ALLOWED,
                                                          "Queue " + queue.getNameShortString() + " is exclusive, but not created on this Connection.");
                    }
                }

                if (body.getConsumerTag() != null)
                {
                    consumerTagName = body.getConsumerTag().intern();
                }
                else
                {
                    consumerTagName = null;
                }

                try
                {
                    if(consumerTagName == null || channel.getSubscription(consumerTagName) == null)
                    {

                        AMQShortString consumerTag = channel.subscribeToQueue(consumerTagName, queue, !body.getNoAck(),
                                                                              body.getArguments(), body.getNoLocal(), body.getExclusive());
                        if (!body.getNowait())
                        {
                            MethodRegistry methodRegistry = protocolConnection.getMethodRegistry();
                            AMQMethodBody responseBody = methodRegistry.createBasicConsumeOkBody(consumerTag);
View Full Code Here

Examples of org.apache.qpid.server.AMQChannel

{
    public Subscription createSubscription(int channelId, AMQProtocolSession protocolSession,
                                           AMQShortString consumerTag, boolean acks, FieldTable filters,
                                           boolean noLocal, FlowCreditManager creditManager) throws AMQException
    {
        AMQChannel channel = protocolSession.getChannel(channelId);
        if (channel == null)
        {
            throw new AMQException(AMQConstant.NOT_FOUND, "channel :" + channelId + " not found in protocol session");
        }
        ClientDeliveryMethod clientMethod = channel.getClientDeliveryMethod();
        RecordDeliveryMethod recordMethod = channel.getRecordDeliveryMethod();


        return createSubscription(channel, protocolSession, consumerTag, acks, filters,
                                  noLocal,
                                  creditManager,
View Full Code Here

Examples of org.apache.qpid.server.AMQChannel

        _defaultVhost.getQueueRegistry().registerQueue(queue);

        try
        {
            AMQChannel channel = new AMQChannel(_connection, 0, null);
            _connection.addChannel(channel);

            queue.setExclusiveOwningSession(channel);
        }
        catch (AMQException e)
View Full Code Here

Examples of org.apache.qpid.server.AMQChannel

        assertFalse(mgr.hasActiveSubscribers());
        assertTrue(_queueMBean.getActiveConsumerCount() == 0);


        TestMinaProtocolSession protocolSession = new TestMinaProtocolSession();
        AMQChannel channel = new AMQChannel(protocolSession, 1, _messageStore, null);
        protocolSession.addChannel(channel);

        _queue.registerProtocolSession(protocolSession, 1, new AMQShortString("test"), false, null, false, false);
        assertTrue(_queueMBean.getActiveConsumerCount() == 1);

        SubscriptionSet _subscribers = (SubscriptionSet) mgr;
        SubscriptionFactory subscriptionFactory = new SubscriptionImpl.Factory();
        Subscription s1 = subscriptionFactory.createSubscription(channel.getChannelId(),
                                                                 protocolSession,
                                                                 new AMQShortString("S1"),
                                                                 false,
                                                                 null,
                                                                 true,
                                                                 _queue);

        Subscription s2 = subscriptionFactory.createSubscription(channel.getChannelId(),
                                                                 protocolSession,
                                                                 new AMQShortString("S2"),
                                                                 false,
                                                                 null,
                                                                 true,
View Full Code Here

Examples of org.apache.qpid.server.AMQChannel

     The QueueDepth should decrease when messages are delivered from the queue (QPID-408)
    */
    public void testQueueDepthAlertWithSubscribers() throws Exception
    {
        protocolSession = new TestMinaProtocolSession();
        AMQChannel channel = new AMQChannel(protocolSession, 2, _messageStore, null);
        protocolSession.addChannel(channel);

        // Create queue
        _queue = getNewQueue();
        _queue.registerProtocolSession(protocolSession, channel.getChannelId(),
                                       new AMQShortString("consumer_tag"), true, null, false, false);

        _queueMBean = (AMQQueueMBean) _queue.getManagedObject();
        _queueMBean.setMaximumMessageCount(9999l);   // Set a high value, because this is not being tested
        _queueMBean.setMaximumQueueDepth(MAX_QUEUE_DEPTH);

        // Send messages(no of message to be little more than what can cause a Queue_Depth alert)
        int messageCount = Math.round(MAX_QUEUE_DEPTH / MAX_MESSAGE_SIZE) + 10;
        long totalSize = (messageCount * MAX_MESSAGE_SIZE) >> 10;
        sendMessages(messageCount, MAX_MESSAGE_SIZE);

        // Check queueDepth. There should be no messages on the queue and as the subscriber is listening
        // so there should be no Queue_Deoth alert raised
        assertEquals(new Long(0), new Long(_queueMBean.getQueueDepth()));
        Notification lastNotification = _queueMBean.getLastNotification();
        assertNull(lastNotification);

        // Kill the subscriber and check for the queue depth values.
        // Messages are unacknowledged, so those should get requeued. All messages should be on the Queue
        _queue.unregisterProtocolSession(protocolSession, channel.getChannelId(), new AMQShortString("consumer_tag"));
        channel.requeue();

        assertEquals(new Long(totalSize), new Long(_queueMBean.getQueueDepth()));

        lastNotification = _queueMBean.getLastNotification();
        assertNotNull(lastNotification);
        String notificationMsg = lastNotification.getMessage();
        assertTrue(notificationMsg.startsWith(NotificationCheck.QUEUE_DEPTH_ALERT.name()));

        // Connect a consumer again and check QueueDepth values. The queue should get emptied.
        // Messages will get delivered but still are unacknowledged.
        _queue.registerProtocolSession(protocolSession, channel.getChannelId(),
                                       new AMQShortString("consumer_tag"), true, null, false, false);
        _queue.deliverAsync();
        while (_queue.getMessageCount() != 0)
        {
            Thread.sleep(100);
        }
        assertEquals(new Long(0), new Long(_queueMBean.getQueueDepth()));

        // Kill the subscriber again. Now those messages should get requeued again. Check if the queue depth
        // value is correct.
        _queue.unregisterProtocolSession(protocolSession, channel.getChannelId(), new AMQShortString("consumer_tag"));
        channel.requeue();

        assertEquals(new Long(totalSize), new Long(_queueMBean.getQueueDepth()));
        protocolSession.closeSession();

        // Check the clear queue
View Full Code Here

Examples of org.apache.qpid.server.protocol.v0_8.AMQChannel

        {
            if (_log.isDebugEnabled())
            {
                _log.debug("Commit received on channel " + channelId);
            }
            AMQChannel channel = session.getChannel(channelId);

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

                @Override
                public void run()
                {
View Full Code Here

Examples of org.apache.qpid.server.protocol.v0_8.AMQChannel

        AMQProtocolSession protocolConnection = stateManager.getProtocolSession();


        VirtualHost vHost = protocolConnection.getVirtualHost();

        AMQChannel channel = protocolConnection.getChannel(channelId);
        if (channel == null)
        {
            throw body.getChannelNotFoundException(channelId);
        }
        else
        {
            channel.sync();
            AMQQueue queue = body.getQueue() == null ? channel.getDefaultQueue() : vHost.getQueue(body.getQueue().toString());
            if (queue == null)
            {
                _log.info("No queue for '" + body.getQueue() + "'");
                if(body.getQueue()!=null)
                {
View Full Code Here

Examples of org.apache.qpid.server.protocol.v0_8.AMQChannel

    public void methodReceived(AMQStateManager stateManager, QueueBindBody body, int channelId) throws AMQException
    {
        AMQProtocolSession protocolConnection = stateManager.getProtocolSession();
        VirtualHost virtualHost = protocolConnection.getVirtualHost();
        AMQChannel channel = protocolConnection.getChannel(channelId);

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

        final AMQQueue queue;
        final AMQShortString routingKey;

        final AMQShortString queueName = body.getQueue();

        if (queueName == null)
        {

            queue = channel.getDefaultQueue();

            if (queue == null)
            {
                throw body.getChannelException(AMQConstant.NOT_FOUND, "No default queue defined on channel and queue was null");
            }

            if (body.getRoutingKey() == null)
            {
                routingKey = AMQShortString.valueOf(queue.getName());
            }
            else
            {
                routingKey = body.getRoutingKey().intern();
            }
        }
        else
        {
            queue = virtualHost.getQueue(queueName.toString());
            routingKey = body.getRoutingKey() == null ? AMQShortString.EMPTY_STRING : body.getRoutingKey().intern();
        }

        if (queue == null)
        {
            throw body.getChannelException(AMQConstant.NOT_FOUND, "Queue " + queueName + " does not exist.");
        }
        final String exchangeName = body.getExchange() == null ? null : body.getExchange().toString();
        final Exchange exch = virtualHost.getExchange(exchangeName);
        if (exch == null)
        {
            throw body.getChannelException(AMQConstant.NOT_FOUND, "Exchange " + exchangeName + " does not exist.");
        }


        try
        {
            if (queue.isExclusive() && !queue.isDurable())
            {
                AMQSessionModel session = queue.getExclusiveOwningSession();
                if (session == null || session.getConnectionModel() != protocolConnection)
                {
                    throw body.getConnectionException(AMQConstant.NOT_ALLOWED,
                                                      "Queue " + queue.getName() + " is exclusive, but not created on this Connection.");
                }
            }

            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.getType()))
                {
                    Binding oldBinding = exch.getBinding(bindingKey, queue, arguments);

                    Map<String, Object> oldArgs = oldBinding.getArguments();
                    if((oldArgs == null && !arguments.isEmpty()) || (oldArgs != null && !oldArgs.equals(arguments)))
                    {
                        exch.replaceBinding(oldBinding.getId(), bindingKey, queue, arguments);
                    }
                }
            }
        }
        catch (AMQException e)
        {
            throw body.getChannelException(AMQConstant.CHANNEL_ERROR, e.toString());
        }

        if (_log.isInfoEnabled())
        {
            _log.info("Binding queue " + queue + " to exchange " + exch + " with routing key " + routingKey);
        }
        if (!body.getNowait())
        {
            channel.sync();
            MethodRegistry methodRegistry = protocolConnection.getMethodRegistry();
            AMQMethodBody responseBody = methodRegistry.createQueueBindOkBody();
            protocolConnection.writeFrame(responseBody.generateFrame(channelId));

        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.