public abstract class AbstractNIOAsyncQueueWriter extends AbstractWriter<SocketAddress> implements AsyncQueueWriter<SocketAddress>
AsyncQueueWriter implementation, based on the Java NIOWriter.ReentrantAsyncQueue.AsyncResult| Modifier and Type | Field and Description |
|---|---|
protected int |
maxPendingBytes |
protected int |
maxWriteReentrants |
protected NIOTransport |
transport |
AUTO_SIZE, UNLIMITED_SIZEEXPECTING_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<SocketAddress> connection)
Return
true if the connection has not exceeded it's maximum
size in bytes of pending writes, otherwise false. |
boolean |
canWrite(Connection<SocketAddress> connection,
int size)
Deprecated.
|
void |
close()
Close AsyncQueueProcessor and release associated resources
|
protected AsyncWriteQueueRecord |
createRecord(Connection connection,
WritableMessage message,
CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler,
SocketAddress dstAddress,
PushBackHandler pushBackHandler,
boolean isUncountable) |
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<SocketAddress> connection,
WriteHandler writeHandler)
Registers
WriteHandler, which will be notified ones at least one
byte can be written. |
void |
notifyWritePossible(Connection<SocketAddress> connection,
WriteHandler writeHandler,
int size)
Deprecated.
|
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<SocketAddress> connection,
SocketAddress dstAddress,
WritableMessage message,
CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler,
MessageCloner<WritableMessage> cloner)
Method writes the
WritableMessage to the specific address. |
void |
write(Connection<SocketAddress> connection,
SocketAddress dstAddress,
WritableMessage message,
CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler,
PushBackHandler pushBackHandler)
Deprecated.
|
void |
write(Connection<SocketAddress> connection,
SocketAddress dstAddress,
WritableMessage message,
CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler,
PushBackHandler pushBackHandler,
MessageCloner<WritableMessage> cloner)
Deprecated.
|
protected abstract RecordWriteResult |
write0(NIOConnection connection,
AsyncWriteQueueRecord queueRecord) |
write, write, write, writeprotected final NIOTransport transport
protected volatile int maxPendingBytes
protected volatile int maxWriteReentrants
public AbstractNIOAsyncQueueWriter(NIOTransport transport)
@Deprecated public boolean canWrite(Connection<SocketAddress> 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 falsepublic boolean canWrite(Connection<SocketAddress> connection)
Writertrue if the connection has not exceeded it's maximum
size in bytes of pending writes, otherwise false.canWrite in interface Writer<SocketAddress>connection - the Connection to test whether or not the
specified number of bytes can be written to.true if the connection has not exceeded it's maximum
size in bytes of pending writes, otherwise false@Deprecated public void notifyWritePossible(Connection<SocketAddress> 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 - ConnectionwriteHandler - WriteHandler to be notified.size - number of bytes queue has to be able to accept before notifying
WriteHandler.public void notifyWritePossible(Connection<SocketAddress> connection, WriteHandler writeHandler)
WriterWriteHandler, which will be notified ones at least one
byte can be written.
This method call is equivalent to call notifyWritePossible(connection, writeHandler, 1);
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 Writer<SocketAddress>connection - ConnectionwriteHandler - 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<SocketAddress> connection, SocketAddress dstAddress, WritableMessage message, CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler, MessageCloner<WritableMessage> cloner)
WriterWritableMessage 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<SocketAddress> connection, SocketAddress dstAddress, WritableMessage message, CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler, PushBackHandler pushBackHandler)
WriterWritableMessage 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<SocketAddress> 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
ConnectionprocessAsync in interface AsyncQueuecontext - ContextAsyncQueue.AsyncResult, depending on async queue status.protected AsyncWriteQueueRecord createRecord(Connection connection, WritableMessage message, CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler, SocketAddress dstAddress, PushBackHandler pushBackHandler, boolean isUncountable)
public final boolean isReady(Connection connection)
AsyncQueue,
associated with the Connection.isReady in interface AsyncQueueconnection - Connectionpublic void onClose(Connection connection)
Connection has been closed,
to let processor release a connection associated resources.onClose in interface AsyncQueueconnection - Connectionpublic final void close()
close in interface AsyncQueueprotected static void onWriteFailure(Connection connection, AsyncWriteQueueRecord failedRecord, Throwable e)
protected abstract RecordWriteResult write0(NIOConnection connection, AsyncWriteQueueRecord queueRecord) throws IOException
IOExceptionprotected abstract void onReadyToWrite(NIOConnection connection) throws IOException
IOExceptionprotected AsyncWriteQueueRecord aggregate(TaskQueue<AsyncWriteQueueRecord> connectionQueue)
Copyright © 2017–2019 Oracle Corporation. All rights reserved.