Search in sources :

Example 1 with ProtocolEvent

use of org.apache.qpid.server.protocol.v0_10.transport.ProtocolEvent in project qpid-broker-j by apache.

the class FrameEncoder method encode.

@Override
public ByteBuffer encode(final Object msg) {
    if (msg instanceof ProtocolEvent) {
        final List<ByteBuffer> buffers = new ArrayList<>();
        final AtomicInteger totalSize = new AtomicInteger();
        Disassembler disassembler = new Disassembler(new ByteBufferSender() {

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

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

            @Override
            public void flush() {
            }

            @Override
            public void close() {
            }
        }, 512);
        disassembler.send((ProtocolEvent) msg);
        ByteBuffer data = ByteBuffer.allocate(totalSize.get());
        for (ByteBuffer buffer : buffers) {
            data.put(buffer);
        }
        data.flip();
        return data;
    }
    return null;
}
Also used : ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) ProtocolEvent(org.apache.qpid.server.protocol.v0_10.transport.ProtocolEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)1 ProtocolEvent (org.apache.qpid.server.protocol.v0_10.transport.ProtocolEvent)1 ByteBufferSender (org.apache.qpid.server.transport.ByteBufferSender)1