public class SerializingBufferWriter
extends java.lang.Object
implements java.nio.channels.CompletionHandler<java.lang.Long,java.lang.Void>
AsynchronousSocketChannel
that serializes all incoming write requests. This means we queue any incoming buffer and don't begin writing
it until the previous buffer has been written fully. All buffers are transmitted atomically with respect to the caller/callback.Modifier and Type | Field and Description |
---|---|
protected java.nio.channels.AsynchronousSocketChannel |
channel |
Constructor and Description |
---|
SerializingBufferWriter(java.nio.channels.AsynchronousSocketChannel channel) |
Modifier and Type | Method and Description |
---|---|
void |
completed(java.lang.Long bytesWritten,
java.lang.Void v)
Completion handler for channel writes.
|
void |
failed(java.lang.Throwable t,
java.lang.Void v) |
void |
queueBuffer(java.nio.ByteBuffer buf,
java.nio.channels.CompletionHandler<java.lang.Long,java.lang.Void> callback)
Queue a buffer to be written to the channel.
|
void |
setChannel(java.nio.channels.AsynchronousSocketChannel channel)
Allow overwriting the channel once the writer has been established.
|
public SerializingBufferWriter(java.nio.channels.AsynchronousSocketChannel channel)
public void queueBuffer(java.nio.ByteBuffer buf, java.nio.channels.CompletionHandler<java.lang.Long,java.lang.Void> callback)
buf
- ByteBuffer
callback
- CompletionHandler
public void completed(java.lang.Long bytesWritten, java.lang.Void v)
completed
in interface java.nio.channels.CompletionHandler<java.lang.Long,java.lang.Void>
bytesWritten
- number of processed bytesv
- Voidpublic void failed(java.lang.Throwable t, java.lang.Void v)
failed
in interface java.nio.channels.CompletionHandler<java.lang.Long,java.lang.Void>
public void setChannel(java.nio.channels.AsynchronousSocketChannel channel)
channel
- AsynchronousSocketChannel