Examples of AMQProtocolSession


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

        return new AMQShortString(Long.toString(System.currentTimeMillis()));
    }

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

        //ignore leading '/'
        String virtualHostName;
        if ((body.getVirtualHost() != null) && body.getVirtualHost().charAt(0) == '/')
        {
            virtualHostName = new StringBuilder(body.getVirtualHost().subSequence(1, body.getVirtualHost().length())).toString();
        }
        else
        {
            virtualHostName = body.getVirtualHost() == null ? null : String.valueOf(body.getVirtualHost());
        }

        VirtualHost virtualHost = stateManager.getVirtualHostRegistry().getVirtualHost(virtualHostName);

        if (virtualHost == null)
        {
            throw body.getConnectionException(AMQConstant.NOT_FOUND, "Unknown virtual host: '" + virtualHostName + "'");
        }
        else
        {
            // Check virtualhost access
            if (!virtualHost.getSecurityManager().accessVirtualhost(virtualHostName, session.getRemoteAddress()))
            {
                throw body.getConnectionException(AMQConstant.ACCESS_REFUSED, "Permission denied: '" + virtualHost.getName() + "'");
            }
            else if (virtualHost.getState() != State.ACTIVE)
            {
                throw body.getConnectionException(AMQConstant.CONNECTION_FORCED, "Virtual host '" + virtualHost.getName() + "' is not active");
            }

            session.setVirtualHost(virtualHost);

            // See Spec (0.8.2). Section  3.1.2 Virtual Hosts
            if (session.getContextKey() == null)
            {
                session.setContextKey(generateClientID());
            }

            MethodRegistry methodRegistry = session.getMethodRegistry();
            AMQMethodBody responseBody =  methodRegistry.createConnectionOpenOkBody(body.getVirtualHost());

            stateManager.changeState(AMQState.CONNECTION_OPEN);

            session.writeFrame(responseBody.generateFrame(channelId));
        }
    }
View Full Code Here

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

    {
    }

    public void methodReceived(AMQStateManager stateManager, ConnectionCloseBody body, int channelId) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        if (_logger.isInfoEnabled())
        {
            _logger.info("ConnectionClose received with reply code/reply text " + body.getReplyCode() + "/" +
                         body.getReplyText() + " for " + session);
        }
        try
        {
            session.closeSession();
        }
        catch (Exception e)
        {
            _logger.error("Error closing protocol session: " + e, e);
        }

        MethodRegistry methodRegistry = session.getMethodRegistry();
        ConnectionCloseOkBody responseBody = methodRegistry.createConnectionCloseOkBody();
        session.writeFrame(responseBody.generateFrame(channelId));

        session.closeProtocolSession();

    }
View Full Code Here

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

    {
    }

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


        AMQChannel channel = session.getChannel(channelId);

        if (channel == null)
        {
            throw body.getChannelNotFoundException(channelId);
        }
        channel.sync();
        channel.setSuspended(!body.getActive());
        _logger.debug("Channel.Flow for channel " + channelId + ", active=" + body.getActive());

        MethodRegistry methodRegistry = session.getMethodRegistry();
        AMQMethodBody responseBody = methodRegistry.createChannelFlowOkBody(body.getActive());
        session.writeFrame(responseBody.generateFrame(channelId));
    }
View Full Code Here

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

    {
    }

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

        AMQChannel channel = session.getChannel(channelId);

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

        channel.setLocalTransactional();

        MethodRegistry methodRegistry = session.getMethodRegistry();
        TxSelectOkBody responseBody = methodRegistry.createTxSelectOkBody();
        session.writeFrame(responseBody.generateFrame(channelId));
    }
View Full Code Here

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

    {
    }

    public void methodReceived(AMQStateManager stateManager, ChannelOpenBody body, int channelId) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        VirtualHost virtualHost = session.getVirtualHost();

        // Protect the broker against out of order frame request.
        if (virtualHost == null)
        {
            throw new AMQException(AMQConstant.COMMAND_INVALID, "Virtualhost has not yet been set. ConnectionOpen has not been called.", null);
        }
        _logger.info("Connecting to: " + virtualHost.getName());

        final AMQChannel channel = new AMQChannel(session,channelId, virtualHost.getMessageStore());

        session.addChannel(channel);

        ChannelOpenOkBody response;

        ProtocolVersion pv = session.getProtocolVersion();

        if(pv.equals(ProtocolVersion.v8_0))
        {
            MethodRegistry_8_0 methodRegistry = (MethodRegistry_8_0) MethodRegistry.getMethodRegistry(ProtocolVersion.v8_0);
            response = methodRegistry.createChannelOpenOkBody();

        }
        else if(pv.equals(ProtocolVersion.v0_9))
        {
            MethodRegistry_0_9 methodRegistry = (MethodRegistry_0_9) MethodRegistry.getMethodRegistry(ProtocolVersion.v0_9);
            UUID uuid = UUID.randomUUID();
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            DataOutputStream dataOut = new DataOutputStream(output);
            try
            {
                dataOut.writeLong(uuid.getMostSignificantBits());
                dataOut.writeLong(uuid.getLeastSignificantBits());
                dataOut.flush();
                dataOut.close();
            }
            catch (IOException e)
            {
                // This *really* shouldn't happen as we're not doing any I/O
                throw new RuntimeException("I/O exception when writing to byte array", e);
            }

            // should really associate this channelId to the session
            byte[] channelName = output.toByteArray();

            response = methodRegistry.createChannelOpenOkBody(channelName);
        }
        else if(pv.equals(ProtocolVersion.v0_91))
        {
            MethodRegistry_0_91 methodRegistry = (MethodRegistry_0_91) MethodRegistry.getMethodRegistry(ProtocolVersion.v0_91);
            UUID uuid = UUID.randomUUID();
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            DataOutputStream dataOut = new DataOutputStream(output);
            try
            {
                dataOut.writeLong(uuid.getMostSignificantBits());
                dataOut.writeLong(uuid.getLeastSignificantBits());
                dataOut.flush();
                dataOut.close();
            }
            catch (IOException e)
            {
                // This *really* shouldn't happen as we're not doing any I/O
                throw new RuntimeException("I/O exception when writing to byte array", e);
            }

            // should really associate this channelId to the session
            byte[] channelName = output.toByteArray();

            response = methodRegistry.createChannelOpenOkBody(channelName);
        }
        else
        {
            throw new AMQException(AMQConstant.INTERNAL_ERROR, "Got channel open for protocol version not catered for: " + pv, null);
        }


        session.writeFrame(response.generateFrame(channelId));
    }
View Full Code Here

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

    {
    }

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


        if (_log.isDebugEnabled())
        {
            _log.debug("Ack(Tag:" + body.getDeliveryTag() + ":Mult:" + body.getMultiple() + ") received on channel " + channelId);
        }

        final AMQChannel channel = protocolSession.getChannel(channelId);

        if (channel == null)
        {
            throw body.getChannelNotFoundException(channelId);
        }
View Full Code Here

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

    {
    }

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

        if (_logger.isInfoEnabled())
        {
            _logger.info("Received channel close for id " + channelId + " citing class " + body.getClassId() +
                         " and method " + body.getMethodId());
        }


        AMQChannel channel = session.getChannel(channelId);

        if (channel == null)
        {
            throw body.getConnectionException(AMQConstant.CHANNEL_ERROR, "Trying to close unknown channel");
        }
        channel.sync();
        session.closeChannel(channelId);
        // Client requested closure so we don't wait for ok we send it
        stateManager.getProtocolSession().closeChannelOk(channelId);

        MethodRegistry methodRegistry = session.getMethodRegistry();
        ChannelCloseOkBody responseBody = methodRegistry.createChannelCloseOkBody();
        session.writeFrame(responseBody.generateFrame(channelId));
    }
View Full Code Here

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

    {
    }

    public void methodReceived(AMQStateManager stateManager, BasicPublishBody body, int channelId) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        if (_logger.isDebugEnabled())
        {
            _logger.debug("Publish received on channel " + channelId);
        }

        AMQShortString exchangeName = body.getExchange();
        // TODO: check the delivery tag field details - is it unique across the broker or per subscriber?
        if (exchangeName == null)
        {
            exchangeName = AMQShortString.valueOf(ExchangeDefaults.DEFAULT_EXCHANGE_NAME);
        }

        VirtualHost vHost = session.getVirtualHost();
        Exchange exch = vHost.getExchange(exchangeName.toString());
        // if the exchange does not exist we raise a channel exception
        if (exch == null)
        {
            throw body.getChannelException(AMQConstant.NOT_FOUND, "Unknown exchange name");
        }
        else
        {
            // The partially populated BasicDeliver frame plus the received route body
            // is stored in the channel. Once the final body frame has been received
            // it is routed to the exchange.
            AMQChannel channel = session.getChannel(channelId);

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

            MessagePublishInfo info = session.getMethodRegistry().getProtocolVersionMethodConverter().convertToInfo(body);
            info.setExchange(exchangeName);
            channel.setPublishFrame(info, exch);
        }
    }
View Full Code Here

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

    {
    }

    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
        {
            channel.sync();
            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.getQueue(body.getQueue().intern().toString());

            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.getName() + " is exclusive, but not created on this Connection.");
                    }
                }

                if (body.getConsumerTag() != null)
                {
                    consumerTagName = body.getConsumerTag().intern(false);
                }
                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);
                            protocolConnection.writeFrame(responseBody.generateFrame(channelId));

                        }
                    }
                    else
                    {
                        AMQShortString msg = new AMQShortString("Non-unique consumer tag, '" + body.getConsumerTag() + "'");

                        MethodRegistry methodRegistry = protocolConnection.getMethodRegistry();
                        AMQMethodBody responseBody = methodRegistry.createConnectionCloseBody(AMQConstant.NOT_ALLOWED.getCode(),    // replyCode
                                                                 msg,               // replytext
                                                                 body.getClazz(),
                                                                 body.getMethod());
                        protocolConnection.writeFrame(responseBody.generateFrame(0));
                    }

                }
                catch (org.apache.qpid.AMQInvalidArgumentException ise)
                {
                    _logger.debug("Closing connection due to invalid selector");

                    MethodRegistry methodRegistry = protocolConnection.getMethodRegistry();
                    AMQMethodBody responseBody = methodRegistry.createChannelCloseBody(AMQConstant.ARGUMENT_INVALID.getCode(),
                                                                                       new AMQShortString(ise.getMessage()),
                                                                                       body.getClazz(),
                                                                                       body.getMethod());
                    protocolConnection.writeFrame(responseBody.generateFrame(channelId));


                }
                catch (AMQQueue.ExistingExclusiveSubscription e)
                {
View Full Code Here

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

    {
    }

    public void methodReceived(AMQStateManager stateManager, ConnectionCloseOkBody body, int channelId) throws AMQException
    {
        AMQProtocolSession session = stateManager.getProtocolSession();
        //todo should this not do more than just log the method?
        _logger.info("Received Connection-close-ok");

        try
        {
            stateManager.changeState(AMQState.CONNECTION_CLOSED);
            session.closeSession();
        }
        catch (Exception e)
        {
            _logger.error("Error closing protocol session: " + e, e);
        }
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.