|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.glassfish.grizzly.AbstractWriter<SocketAddress>
org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter
public abstract class AbstractNIOAsyncQueueWriter
The AsyncQueueWriter
implementation, based on the Java NIO
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueueWriter |
---|
AsyncQueueWriter.Reentrant |
Nested classes/interfaces inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueue |
---|
AsyncQueue.AsyncResult |
Field Summary | |
---|---|
protected static int |
EMPTY_RECORD_SPACE_VALUE
|
protected int |
maxPendingBytes
|
protected int |
maxWriteReentrants
|
protected NIOTransport |
transport
|
Fields inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueueWriter |
---|
AUTO_SIZE, UNLIMITED_SIZE |
Fields inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueue |
---|
EXPECTING_MORE_OPTION |
Constructor Summary | |
---|---|
AbstractNIOAsyncQueueWriter(NIOTransport transport)
|
Method Summary | |
---|---|
protected AsyncWriteQueueRecord |
aggregate(TaskQueue<AsyncWriteQueueRecord> connectionQueue)
Aggregates records in a queue to be written as one chunk. |
boolean |
canWrite(Connection connection,
int size)
|
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()
|
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 |
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 |
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. |
boolean |
isReady(Connection connection)
Checks whether there is ready data in AsyncQueue ,
associated with the Connection . |
void |
notifyWritePossible(Connection connection,
WriteHandler writeHandler,
int size)
Registers WriteHandler , which will be notified ones Buffer
of "size"-bytes can be written. |
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 |
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)
Method writes the WritableMessage to the specific address. |
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. |
protected abstract long |
write0(NIOConnection connection,
AsyncWriteQueueRecord queueRecord)
|
protected void |
writeQueueRecord(AsyncWriteQueueRecord queueRecord,
MessageCloner<WritableMessage> cloner,
PushBackContext pushBackContext)
|
Methods inherited from class org.glassfish.grizzly.AbstractWriter |
---|
write, write, write, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.glassfish.grizzly.Writer |
---|
write, write, write, write |
Field Detail |
---|
protected static final int EMPTY_RECORD_SPACE_VALUE
protected final NIOTransport transport
protected volatile int maxPendingBytes
protected volatile int maxWriteReentrants
Constructor Detail |
---|
public AbstractNIOAsyncQueueWriter(NIOTransport transport)
Method Detail |
---|
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 void notifyWritePossible(Connection connection, WriteHandler writeHandler, int size)
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.
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 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 int getMaxWriteReentrants()
getMaxWriteReentrants
in interface AsyncQueueWriter<SocketAddress>
public void setMaxWriteReentrants(int maxWriteReentrants)
setMaxWriteReentrants
in interface AsyncQueueWriter<SocketAddress>
maxWriteReentrants
- the maximum number of write() method calls
a thread is allowed to make.public boolean isAllowDirectWrite()
public void setAllowDirectWrite(boolean isAllowDirectWrite)
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, 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 refusedpublic 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 queueprotected void writeQueueRecord(AsyncWriteQueueRecord queueRecord, MessageCloner<WritableMessage> cloner, PushBackContext pushBackContext)
public 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 AsyncQueueWriter.Reentrant getWriteReentrant()
AsyncQueueWriter.canWrite(org.glassfish.grizzly.Connection, int)
and
various write methods.
getWriteReentrant
in interface AsyncQueueWriter<SocketAddress>
public boolean isMaxReentrantsReached(AsyncQueueWriter.Reentrant reentrant)
AsyncQueueWriter
AsyncQueueWriter.Reentrant
object, and next write
will happen in the separate thread.
isMaxReentrantsReached
in interface AsyncQueueWriter<SocketAddress>
reentrant
- AsyncQueueWriter.Reentrant
object.
AsyncQueueWriter.Reentrant
object, and next write
will happen in the separate thread.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)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |