org.glassfish.grizzly.asyncqueue
Interface AsyncQueueWriter<L>

All Superinterfaces:
AsyncQueue, Writer<L>
All Known Implementing Classes:
AbstractNIOAsyncQueueWriter, TCPNIOAsyncQueueWriter, UDPNIOAsyncQueueWriter

public interface AsyncQueueWriter<L>
extends Writer<L>, AsyncQueue

The AsyncQueue, which implements asynchronous write queue.

Author:
Alexey Stashok, Ryan Lubke

Nested Class Summary
static class AsyncQueueWriter.Reentrant
          Write reentrants counter
 
Nested classes/interfaces inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueue
AsyncQueue.AsyncResult
 
Field Summary
static int AUTO_SIZE
          Constant set via setMaxPendingBytesPerConnection(int) means the async write queue size will be configured automatically per NIOConnection depending on connections write buffer size.
static int UNLIMITED_SIZE
          Constant set via setMaxPendingBytesPerConnection(int) means the async write queue size is unlimited.
 
Fields inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueue
EXPECTING_MORE_OPTION
 
Method Summary
 boolean canWrite(Connection connection, int size)
           
 int getMaxPendingBytesPerConnection()
           
 int getMaxWriteReentrants()
          Returns the maximum number of write() method reentrants a thread is allowed to made.
 AsyncQueueWriter.Reentrant getWriteReentrant()
          Returns the current write reentrants counter.
 boolean isMaxReentrantsReached(AsyncQueueWriter.Reentrant reentrant)
          Returns true, if max number of write->completion-handler reentrants has been reached for the passed AsyncQueueWriter.Reentrant object, and next write will happen in the separate thread.
 void notifyWritePossible(Connection connection, WriteHandler writeHandler, int size)
          Registers WriteHandler, which will be notified ones Buffer of "size"-bytes can be written.
 void setMaxPendingBytesPerConnection(int maxQueuedWrites)
          Configures the maximum number of bytes pending to be written for a particular Connection.
 void setMaxWriteReentrants(int maxWriteReentrants)
          Sets the maximum number of write() method reentrants a thread is allowed to made.
 void write(Connection connection, SocketAddress dstAddress, WritableMessage message, CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler, PushBackHandler pushBackHandler, MessageCloner<WritableMessage> cloner)
          Method writes the Buffer to the specific address.
 
Methods inherited from interface org.glassfish.grizzly.Writer
write, write, write, write, write
 
Methods inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueue
close, isReady, onClose, processAsync
 

Field Detail

UNLIMITED_SIZE

static final int UNLIMITED_SIZE
Constant set via setMaxPendingBytesPerConnection(int) means the async write queue size is unlimited.

See Also:
Constant Field Values

AUTO_SIZE

static final int AUTO_SIZE
Constant set via setMaxPendingBytesPerConnection(int) means the async write queue size will be configured automatically per NIOConnection depending on connections write buffer size.

See Also:
Constant Field Values
Method Detail

write

void write(Connection connection,
           SocketAddress dstAddress,
           WritableMessage message,
           CompletionHandler<WriteResult<WritableMessage,SocketAddress>> completionHandler,
           PushBackHandler pushBackHandler,
           MessageCloner<WritableMessage> cloner)
Method writes the Buffer to the specific address.

Parameters:
connection - the Connection to write to
dstAddress - the destination address the WritableMessage will be sent to
message - the WritableMessage, from which the data will be written
completionHandler - CompletionHandler, which will get notified, when write will be completed
pushBackHandler - PushBackHandler, which will be notified if message was accepted by transport write queue or refused
cloner - 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 queue

canWrite

boolean canWrite(Connection connection,
                 int size)
Parameters:
connection - the Connection to test whether or not the specified number of bytes can be written to.
size - number of bytes to write.
Returns:
true if the queue has not exceeded it's maximum size in bytes of pending writes, otherwise false

notifyWritePossible

void notifyWritePossible(Connection connection,
                         WriteHandler writeHandler,
                         int size)
Registers WriteHandler, which will be notified ones Buffer of "size"-bytes can 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. It's recommended to use this method together with PushBackHandler to have a chance to handle such a situations properly.

Parameters:
connection - Connection
writeHandler - WriteHandler to be notified.
size - number of bytes queue has to be able to accept before notifying WriteHandler.
Since:
2.2

setMaxPendingBytesPerConnection

void setMaxPendingBytesPerConnection(int maxQueuedWrites)
Configures the maximum number of bytes pending to be written for a particular Connection.

Parameters:
maxQueuedWrites - maximum number of bytes that may be pending to be written to a particular Connection.

getMaxPendingBytesPerConnection

int getMaxPendingBytesPerConnection()
Returns:
the maximum number of bytes that may be pending to be written to a particular Connection. By default, this will be four times the size of the Socket send buffer size.

getMaxWriteReentrants

int getMaxWriteReentrants()
Returns the maximum number of write() method reentrants a thread is allowed to made. This is related to possible write()->onComplete()->write()->... chain, which may grow infinitely and cause StackOverflow. Using maxWriteReentrants value it's possible to limit such a chain.

Returns:
the maximum number of write() method reentrants a thread is allowed to make.

setMaxWriteReentrants

void setMaxWriteReentrants(int maxWriteReentrants)
Sets the maximum number of write() method reentrants a thread is allowed to made. This is related to possible write()->onComplete()->write()->... chain, which may grow infinitely and cause StackOverflow. Using maxWriteReentrants value it's possible to limit such a chain.

Parameters:
maxWriteReentrants - the maximum number of write() method calls a thread is allowed to make.

getWriteReentrant

AsyncQueueWriter.Reentrant getWriteReentrant()
Returns the current write reentrants counter. Might be useful, if developer wants to use custom notification mechanism, based on on canWrite(org.glassfish.grizzly.Connection, int) and various write methods.


isMaxReentrantsReached

boolean isMaxReentrantsReached(AsyncQueueWriter.Reentrant reentrant)
Returns true, if max number of write->completion-handler reentrants has been reached for the passed AsyncQueueWriter.Reentrant object, and next write will happen in the separate thread.

Parameters:
reentrant - AsyncQueueWriter.Reentrant object.
Returns:
true, if max number of write->completion-handler reentrants has been reached for the passed AsyncQueueWriter.Reentrant object, and next write will happen in the separate thread.


Copyright © 2013 Oracle Corporation. All Rights Reserved.