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