public abstract class AbstractNIOAsyncQueueWriter extends AbstractWriter<SocketAddress> implements AsyncQueueWriter<SocketAddress>
AsyncQueueWriter
implementation, based on the Java NIOWriter.Reentrant
AsyncQueue.AsyncResult
Modifier and Type | Field and Description |
---|---|
protected static int |
EMPTY_RECORD_SPACE_VALUE |
protected int |
maxPendingBytes |
protected int |
maxWriteReentrants |
protected NIOTransport |
transport |
AUTO_SIZE, UNLIMITED_SIZE
EXPECTING_MORE_OPTION
Constructor and Description |
---|
AbstractNIOAsyncQueueWriter(NIOTransport transport) |
Modifier and Type | Method and Description |
---|---|
protected AsyncWriteQueueRecord |
aggregate(TaskQueue<AsyncWriteQueueRecord> connectionQueue)
Aggregates records in a queue to be written as one chunk.
|
boolean |
canWrite(Connection connection)
Return
true if the connection has not exceeded it's maximum
size in bytes of pending writes, otherwise false . |
boolean |
canWrite(Connection connection,
int size)
Deprecated.
|
void |
close()
Close AsyncQueueProcessor and release associated resources
|
protected AsyncWriteQueueRecord |
createRecord(Connection connection,
WritableMessage message,
WriteResult<WritableMessage,SocketAddress> currentResult,
CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler,
SocketAddress dstAddress,
PushBackHandler pushBackHandler,
boolean isEmptyRecord) |
int |
getMaxPendingBytesPerConnection() |
boolean |
isAllowDirectWrite()
Returns true, if async write queue is allowed to write buffer
directly during write(...) method call, w/o adding buffer to the
queue, or false otherwise.
|
boolean |
isReady(Connection connection)
Checks whether there is ready data in
AsyncQueue ,
associated with the Connection . |
void |
notifyWritePossible(Connection connection,
WriteHandler writeHandler)
Registers
WriteHandler , which will be notified ones the
Connection is able to accept more bytes to be written. |
void |
notifyWritePossible(Connection connection,
WriteHandler writeHandler,
int size)
Deprecated.
|
protected static void |
offerToTaskQueue(NIOConnection nioConnection,
AsyncWriteQueueRecord queueRecord,
TaskQueue<AsyncWriteQueueRecord> taskQueue) |
void |
onClose(Connection connection)
Callback method, which is called, when
Connection has been closed,
to let processor release a connection associated resources. |
protected abstract void |
onReadyToWrite(NIOConnection connection) |
protected static void |
onWriteFailure(Connection connection,
AsyncWriteQueueRecord failedRecord,
Throwable e) |
AsyncQueue.AsyncResult |
processAsync(Context context)
Callback method, which is called async.
|
void |
setAllowDirectWrite(boolean isAllowDirectWrite)
Set true, if async write queue is allowed to write buffer
directly during write(...) method call, w/o adding buffer to the
queue, or false otherwise.
|
void |
setMaxPendingBytesPerConnection(int maxPendingBytes)
Configures the maximum number of bytes pending to be written
for a particular
Connection . |
void |
write(Connection connection,
SocketAddress dstAddress,
WritableMessage message,
CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler,
MessageCloner<WritableMessage> cloner)
Method writes the
WritableMessage to the specific address. |
void |
write(Connection connection,
SocketAddress dstAddress,
WritableMessage message,
CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler,
PushBackHandler pushBackHandler)
Deprecated.
|
void |
write(Connection connection,
SocketAddress dstAddress,
WritableMessage message,
CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler,
PushBackHandler pushBackHandler,
MessageCloner<WritableMessage> cloner)
Deprecated.
|
protected abstract long |
write0(NIOConnection connection,
AsyncWriteQueueRecord queueRecord) |
write, write, write, write
protected static final int EMPTY_RECORD_SPACE_VALUE
protected final NIOTransport transport
protected volatile int maxPendingBytes
protected volatile int maxWriteReentrants
public AbstractNIOAsyncQueueWriter(NIOTransport transport)
@Deprecated public boolean canWrite(Connection connection, int size)
canWrite
in interface AsyncQueueWriter<SocketAddress>
connection
- the Connection
to test whether or not the
specified number of bytes can be written to.size
- number of bytes to write.true
if the queue has not exceeded it's maximum
size in bytes of pending writes, otherwise false
public boolean canWrite(Connection connection)
Writer
true
if the connection has not exceeded it's maximum
size in bytes of pending writes, otherwise false
.canWrite
in interface AsyncQueueWriter<SocketAddress>
canWrite
in interface Writer<SocketAddress>
connection
- the Connection
to test whether or not it's ready
to accept more bytes to write.true
if the queue has not exceeded it's maximum
size in bytes of pending writes, otherwise false
@Deprecated public void notifyWritePossible(Connection connection, WriteHandler writeHandler, int size)
WriteHandler
, which will be notified ones the
Connection
is able to accept more bytes to be written.
Note: using this method from different threads simultaneously may lead
to quick situation changes, so at time WriteHandler
is called -
the queue may become busy again.notifyWritePossible
in interface AsyncQueueWriter<SocketAddress>
connection
- Connection
writeHandler
- WriteHandler
to be notified.size
- number of bytes queue has to be able to accept before notifying
WriteHandler
.public void notifyWritePossible(Connection connection, WriteHandler writeHandler)
AsyncQueueWriter
WriteHandler
, which will be notified ones the
Connection
is able to accept more bytes to be written.notifyWritePossible
in interface AsyncQueueWriter<SocketAddress>
notifyWritePossible
in interface Writer<SocketAddress>
connection
- Connection
writeHandler
- WriteHandler
to be notified.public void setMaxPendingBytesPerConnection(int maxPendingBytes)
Connection
.setMaxPendingBytesPerConnection
in interface AsyncQueueWriter<SocketAddress>
maxPendingBytes
- maximum number of bytes that may be pending to be
written to a particular Connection
.public int getMaxPendingBytesPerConnection()
getMaxPendingBytesPerConnection
in interface AsyncQueueWriter<SocketAddress>
Connection
. By default, this will be four
times the size of the Socket
send buffer size.public boolean isAllowDirectWrite()
isAllowDirectWrite
in interface AsyncQueueWriter<SocketAddress>
public void setAllowDirectWrite(boolean isAllowDirectWrite)
setAllowDirectWrite
in interface AsyncQueueWriter<SocketAddress>
isAllowDirectWrite
- true, if async write queue is allowed
to write buffer directly during write(...) method call, w/o adding buffer
to the queue, or false otherwise.public void write(Connection connection, SocketAddress dstAddress, WritableMessage message, CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler, MessageCloner<WritableMessage> cloner)
Writer
WritableMessage
to the specific address.write
in interface Writer<SocketAddress>
connection
- the Connection
to write todstAddress
- the destination address the WritableMessage
will be
sent tomessage
- the WritableMessage
, from which the data will be writtencompletionHandler
- CompletionHandler
,
which will get notified, when write will be completedcloner
- the MessageCloner
, which will be able to
clone the message in case it can't be completely written in the
current thread.@Deprecated public void write(Connection connection, SocketAddress dstAddress, WritableMessage message, CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler, PushBackHandler pushBackHandler)
Writer
WritableMessage
to the specific address.write
in interface Writer<SocketAddress>
connection
- the Connection
to write todstAddress
- the destination address the WritableMessage
will be
sent tomessage
- the WritableMessage
, from which the data will be writtencompletionHandler
- CompletionHandler
,
which will get notified, when write will be completedpushBackHandler
- PushBackHandler
, which will be notified
if message was accepted by transport write queue or refused@Deprecated public void write(Connection connection, SocketAddress dstAddress, WritableMessage message, CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler, PushBackHandler pushBackHandler, MessageCloner<WritableMessage> cloner)
Buffer
to the specific address.write
in interface AsyncQueueWriter<SocketAddress>
connection
- the Connection
to write todstAddress
- the destination address the WritableMessage
will be
sent tomessage
- the WritableMessage
, from which the data will be writtencompletionHandler
- CompletionHandler
,
which will get notified, when write will be completedpushBackHandler
- PushBackHandler
, which will be notified
if message was accepted by transport write queue or refusedcloner
- MessageCloner
, which will be invoked by
AsyncQueueWriter, if message could not be written to a
channel directly and has to be put on a asynchronous queuepublic AsyncQueue.AsyncResult processAsync(Context context)
AsyncQueue
, which are associated with the given
Connection
processAsync
in interface AsyncQueue
context
- Context
AsyncQueue.AsyncResult
, depending on async queue status.protected static void offerToTaskQueue(NIOConnection nioConnection, AsyncWriteQueueRecord queueRecord, TaskQueue<AsyncWriteQueueRecord> taskQueue)
protected AsyncWriteQueueRecord createRecord(Connection connection, WritableMessage message, WriteResult<WritableMessage,SocketAddress> currentResult, CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler, SocketAddress dstAddress, PushBackHandler pushBackHandler, boolean isEmptyRecord)
public final boolean isReady(Connection connection)
AsyncQueue
,
associated with the Connection
.isReady
in interface AsyncQueue
connection
- Connection
public void onClose(Connection connection)
Connection
has been closed,
to let processor release a connection associated resources.onClose
in interface AsyncQueue
connection
- Connection
public final void close()
close
in interface AsyncQueue
protected static void onWriteFailure(Connection connection, AsyncWriteQueueRecord failedRecord, Throwable e)
protected abstract long write0(NIOConnection connection, AsyncWriteQueueRecord queueRecord) throws IOException
IOException
protected abstract void onReadyToWrite(NIOConnection connection) throws IOException
IOException
protected AsyncWriteQueueRecord aggregate(TaskQueue<AsyncWriteQueueRecord> connectionQueue)
Copyright © 2014 Oracle Corporation. All rights reserved.