use of org.apache.qpid.tests.protocol.HeaderResponse 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.tests.protocol.HeaderResponse in project qpid-broker-j by apache.
the class FrameDecoder method decode.
@Override
public Collection<Response<?>> decode(final ByteBuffer inputBuffer) {
QpidByteBuffer qpidByteBuffer = QpidByteBuffer.wrap(inputBuffer);
int remaining;
do {
remaining = qpidByteBuffer.remaining();
switch(_state) {
case HEADER:
if (inputBuffer.remaining() >= 8) {
byte[] header = new byte[8];
inputBuffer.get(header);
_connectionHandler._responseQueue.add(new HeaderResponse(header));
_state = ParsingState.PERFORMATIVES;
}
break;
case PERFORMATIVES:
_frameHandler.parse(qpidByteBuffer);
break;
default:
throw new IllegalStateException("Unexpected state : " + _state);
}
} while (qpidByteBuffer.remaining() != remaining);
List<Response<?>> responses = new ArrayList<>();
Response<?> r;
while ((r = _connectionHandler._responseQueue.poll()) != null) {
responses.add(r);
}
return responses;
}
Aggregations