Search in sources :

Example 1 with ProtocolInitiation

use of org.apache.qpid.server.protocol.v0_8.transport.ProtocolInitiation in project qpid-broker-j by apache.

the class AMQPConnection_0_8Test method testConnectionEnforcesMaxSessions.

public void testConnectionEnforcesMaxSessions() throws Exception {
    AMQPConnection_0_8Impl conn = new AMQPConnection_0_8Impl(_broker, _network, _port, _transport, _protocol, 0, _ticker);
    conn.create();
    conn.receiveProtocolHeader(new ProtocolInitiation(ProtocolVersion.v0_8));
    conn.receiveConnectionStartOk(new FieldTable(), SASL_MECH, SASL_RESPONSE, LOCALE);
    int maxChannels = 10;
    conn.receiveConnectionTuneOk(maxChannels, 65535, 0);
    conn.receiveConnectionOpen(new AMQShortString(VIRTUAL_HOST_NAME), AMQShortString.EMPTY_STRING, false);
    // check the channel count is correct
    int channelCount = conn.getSessionModels().size();
    assertEquals("Initial channel count wrong", 0, channelCount);
    assertEquals("Number of channels not correctly set.", maxChannels, conn.getSessionCountLimit());
    assertFalse("Connection should not be closed after opening " + maxChannels + " channels", conn.isClosing());
    for (long currentChannel = 1L; currentChannel <= maxChannels; currentChannel++) {
        conn.receiveChannelOpen((int) currentChannel);
    }
    assertFalse("Connection should not be closed after opening " + maxChannels + " channels", conn.isClosing());
    assertEquals("Maximum number of channels not set.", maxChannels, conn.getSessionModels().size());
    conn.receiveChannelOpen(maxChannels + 1);
    assertTrue("Connection should be closed after opening " + (maxChannels + 1) + " channels", conn.isClosing());
}
Also used : ProtocolInitiation(org.apache.qpid.server.protocol.v0_8.transport.ProtocolInitiation)

Example 2 with ProtocolInitiation

use of org.apache.qpid.server.protocol.v0_8.transport.ProtocolInitiation in project qpid-broker-j by apache.

the class FrameDecoder method decode.

@Override
public Collection<Response<?>> decode(final ByteBuffer inputBuffer) throws Exception {
    _clientDecoder.decodeBuffer(inputBuffer);
    List<AMQDataBlock> receivedFrames = new ArrayList<>(_methodProcessor.getProcessedMethods());
    List<Response<?>> result = new ArrayList<>();
    for (AMQDataBlock frame : receivedFrames) {
        if (frame instanceof AMQFrame) {
            AMQFrame amqFrame = (AMQFrame) frame;
            if (amqFrame.getBodyFrame() instanceof ConnectionTuneBody) {
                ConnectionTuneBody tuneBody = (ConnectionTuneBody) amqFrame.getBodyFrame();
                _clientDecoder.setMaxFrameSize((int) tuneBody.getFrameMax());
            }
            result.add(new PerformativeResponse(amqFrame.getChannel(), amqFrame.getSize(), amqFrame.getBodyFrame()));
        } else if (frame instanceof ProtocolInitiation) {
            byte[] data = new byte[(int) frame.getSize()];
            frame.writePayload(new ByteBufferSender() {

                @Override
                public boolean isDirectBufferPreferred() {
                    return false;
                }

                @Override
                public void send(final QpidByteBuffer msg) {
                    msg.copyTo(data);
                }

                @Override
                public void flush() {
                }

                @Override
                public void close() {
                }
            });
            result.add(new HeaderResponse(data));
        } else {
            throw new IllegalArgumentException(String.format("Unexpected data block received %s", frame));
        }
    }
    _methodProcessor.getProcessedMethods().removeAll(receivedFrames);
    return result;
}
Also used : ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) ArrayList(java.util.ArrayList) AMQDataBlock(org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock) Response(org.apache.qpid.tests.protocol.Response) HeaderResponse(org.apache.qpid.tests.protocol.HeaderResponse) HeaderResponse(org.apache.qpid.tests.protocol.HeaderResponse) ProtocolInitiation(org.apache.qpid.server.protocol.v0_8.transport.ProtocolInitiation) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQFrame(org.apache.qpid.server.protocol.v0_8.transport.AMQFrame)

Aggregations

ProtocolInitiation (org.apache.qpid.server.protocol.v0_8.transport.ProtocolInitiation)2 ArrayList (java.util.ArrayList)1 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 AMQDataBlock (org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock)1 AMQFrame (org.apache.qpid.server.protocol.v0_8.transport.AMQFrame)1 ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)1 ByteBufferSender (org.apache.qpid.server.transport.ByteBufferSender)1 HeaderResponse (org.apache.qpid.tests.protocol.HeaderResponse)1 Response (org.apache.qpid.tests.protocol.Response)1