Search in sources :

Example 1 with Response

use of org.apache.qpid.tests.protocol.Response 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 2 with Response

use of org.apache.qpid.tests.protocol.Response 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;
}
Also used : Response(org.apache.qpid.tests.protocol.Response) SaslResponse(org.apache.qpid.server.protocol.v1_0.type.security.SaslResponse) HeaderResponse(org.apache.qpid.tests.protocol.HeaderResponse) HeaderResponse(org.apache.qpid.tests.protocol.HeaderResponse) ArrayList(java.util.ArrayList) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Aggregations

ArrayList (java.util.ArrayList)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 HeaderResponse (org.apache.qpid.tests.protocol.HeaderResponse)2 Response (org.apache.qpid.tests.protocol.Response)2 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 ProtocolInitiation (org.apache.qpid.server.protocol.v0_8.transport.ProtocolInitiation)1 SaslResponse (org.apache.qpid.server.protocol.v1_0.type.security.SaslResponse)1 ByteBufferSender (org.apache.qpid.server.transport.ByteBufferSender)1