Search in sources :

Example 11 with ConnectionTuneBody

use of org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody 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)

Example 12 with ConnectionTuneBody

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

the class ConnectionTest method heartbeatingNoIncomingTraffic.

@Test
@SpecificationTest(section = "4.2.7", description = " If a peer detects no incoming traffic (i.e. received octets) for two heartbeat intervals " + "or longer, it should close the connection without following the Connection.Close/Close-Ok handshaking")
public void heartbeatingNoIncomingTraffic() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTuneBody response = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
        final Long heartbeatPeriod = 1L;
        interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(response.getFrameMax()).tuneOkHeartbeat(heartbeatPeriod.intValue()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).consumeResponse(HeartbeatBody.class);
        // Do not reflect a heartbeat so incoming line will be silent thus
        // requiring the broker to close the connection.
        Class[] classes = new Class[] { ChannelClosedResponse.class, HeartbeatBody.class };
        do {
            Response<?> latestResponse = interaction.consumeResponse(classes).getLatestResponse();
            if (latestResponse instanceof ChannelClosedResponse) {
                break;
            }
            classes = new Class[] { ChannelClosedResponse.class };
        } while (true);
    }
}
Also used : HeartbeatBody(org.apache.qpid.server.protocol.v0_8.transport.HeartbeatBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) ChannelClosedResponse(org.apache.qpid.tests.protocol.ChannelClosedResponse) ConnectionOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Example 13 with ConnectionTuneBody

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

the class ConnectionTest method heartbeatingIncomingTrafficIsNonHeartbeat.

@Test
@SpecificationTest(section = "4.2.7", description = "Any sent octet is a valid substitute for a heartbeat")
public void heartbeatingIncomingTrafficIsNonHeartbeat() throws Exception {
    try (FrameTransport transport = new FrameTransport(getBrokerAdmin()).connect()) {
        final Interaction interaction = transport.newInteraction();
        ConnectionTuneBody response = interaction.authenticateConnection().getLatestResponse(ConnectionTuneBody.class);
        final Long heartbeatPeriod = 1L;
        interaction.connection().tuneOkChannelMax(response.getChannelMax()).tuneOkFrameMax(response.getFrameMax()).tuneOkHeartbeat(heartbeatPeriod.intValue()).tuneOk().connection().open().consumeResponse(ConnectionOpenOkBody.class).channel().open().consumeResponse(ChannelOpenOkBody.class).consumeResponse(HeartbeatBody.class).exchange().declarePassive(true).declareNoWait(true).declare().consumeResponse(HeartbeatBody.class).sendPerformative(new HeartbeatBody()).exchange().declarePassive(true).declareNoWait(true).declare();
        interaction.connection().close().consumeResponse().getLatestResponse(ConnectionCloseOkBody.class);
    }
}
Also used : HeartbeatBody(org.apache.qpid.server.protocol.v0_8.transport.HeartbeatBody) ConnectionTuneBody(org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody) ChannelOpenOkBody(org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody) Test(org.junit.Test) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest) SpecificationTest(org.apache.qpid.tests.protocol.SpecificationTest)

Aggregations

ConnectionTuneBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionTuneBody)13 Test (org.junit.Test)12 SpecificationTest (org.apache.qpid.tests.protocol.SpecificationTest)10 ChannelOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ChannelOpenOkBody)3 HeartbeatBody (org.apache.qpid.server.protocol.v0_8.transport.HeartbeatBody)3 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)2 BasicConsumeOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicConsumeOkBody)2 BasicDeliverBody (org.apache.qpid.server.protocol.v0_8.transport.BasicDeliverBody)2 BasicQosOkBody (org.apache.qpid.server.protocol.v0_8.transport.BasicQosOkBody)2 ConnectionOpenOkBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionOpenOkBody)2 ConnectionSecureBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionSecureBody)2 ConnectionStartBody (org.apache.qpid.server.protocol.v0_8.transport.ConnectionStartBody)2 ContentHeaderBody (org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 AMQDataBlock (org.apache.qpid.server.protocol.v0_8.transport.AMQDataBlock)1