Search in sources :

Example 1 with StreamingDataOutputPlusFixed

use of org.apache.cassandra.streaming.StreamingDataOutputPlusFixed in project cassandra by apache.

the class NettyStreamingChannel method send.

public Future<?> send(Send send) {
    class Factory implements IntFunction<StreamingDataOutputPlus> {

        ByteBuf buf;

        ByteBuffer buffer;

        @Override
        public StreamingDataOutputPlus apply(int size) {
            buf = GlobalBufferPoolAllocator.instance.buffer(size);
            buffer = buf.nioBuffer(buf.writerIndex(), size);
            return new StreamingDataOutputPlusFixed(buffer);
        }
    }
    Factory factory = new Factory();
    try {
        send.send(factory);
        ByteBuf buf = factory.buf;
        ByteBuffer buffer = factory.buffer;
        try {
            assert buffer.position() == buffer.limit();
            buf.writerIndex(buffer.position());
            AsyncChannelPromise promise = new AsyncChannelPromise(channel);
            channel.writeAndFlush(buf, promise);
            return promise;
        } catch (Throwable t) {
            buf.release();
            throw t;
        }
    } catch (Throwable t) {
        return ImmediateFuture.failure(t);
    }
}
Also used : StreamingDataOutputPlusFixed(org.apache.cassandra.streaming.StreamingDataOutputPlusFixed) IntFunction(java.util.function.IntFunction) LoggerFactory(org.slf4j.LoggerFactory) AsyncChannelPromise(org.apache.cassandra.net.AsyncChannelPromise) ByteBuf(io.netty.buffer.ByteBuf) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 ByteBuffer (java.nio.ByteBuffer)1 IntFunction (java.util.function.IntFunction)1 AsyncChannelPromise (org.apache.cassandra.net.AsyncChannelPromise)1 StreamingDataOutputPlusFixed (org.apache.cassandra.streaming.StreamingDataOutputPlusFixed)1 LoggerFactory (org.slf4j.LoggerFactory)1