Search in sources :

Example 1 with AMQFrame

use of org.apache.qpid.server.protocol.v1_0.framing.AMQFrame in project qpid-broker-j by apache.

the class FrameEncoder method encode.

@Override
public ByteBuffer encode(final Object msg) {
    if (msg instanceof AMQFrame) {
        List<ByteBuffer> buffers = new ArrayList<>();
        FrameWriter _frameWriter = new FrameWriter(TYPE_REGISTRY, new ByteBufferSender() {

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

            @Override
            public void send(final QpidByteBuffer msg) {
                byte[] data = new byte[msg.remaining()];
                msg.get(data);
                buffers.add(ByteBuffer.wrap(data));
            }

            @Override
            public void flush() {
            }

            @Override
            public void close() {
            }
        });
        AMQFrame frame = (AMQFrame) msg;
        FRAME_LOGGER.debug("SEND: " + frame.getFrameBody());
        _frameWriter.send(frame);
        int remaining = 0;
        for (ByteBuffer byteBuffer : buffers) {
            remaining += byteBuffer.remaining();
        }
        ByteBuffer result = ByteBuffer.allocate(remaining);
        for (ByteBuffer byteBuffer : buffers) {
            result.put(byteBuffer);
        }
        result.flip();
        return result;
    }
    return null;
}
Also used : ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) ArrayList(java.util.ArrayList) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AMQFrame(org.apache.qpid.server.protocol.v1_0.framing.AMQFrame) ByteBuffer(java.nio.ByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) FrameWriter(org.apache.qpid.server.protocol.v1_0.codec.FrameWriter)

Example 2 with AMQFrame

use of org.apache.qpid.server.protocol.v1_0.framing.AMQFrame in project qpid-broker-j by apache.

the class AMQPConnection_1_0Impl method send.

public void send(short channel, FrameBody body) {
    AMQFrame frame = AMQFrame.createAMQFrame(channel, body);
    send(frame);
}
Also used : AMQFrame(org.apache.qpid.server.protocol.v1_0.framing.AMQFrame)

Aggregations

AMQFrame (org.apache.qpid.server.protocol.v1_0.framing.AMQFrame)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 FrameWriter (org.apache.qpid.server.protocol.v1_0.codec.FrameWriter)1 ByteBufferSender (org.apache.qpid.server.transport.ByteBufferSender)1