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);
}
}
Aggregations