java.lang.Object
org.glassfish.grizzly.AbstractReader<SocketAddress>
org.glassfish.grizzly.nio.AbstractNIOAsyncQueueReader
- All Implemented Interfaces:
AsyncQueue,AsyncQueueReader<SocketAddress>,Reader<SocketAddress>
- Direct Known Subclasses:
TCPNIOAsyncQueueReader,UDPNIOAsyncQueueReader
public abstract class AbstractNIOAsyncQueueReader
extends AbstractReader<SocketAddress>
implements AsyncQueueReader<SocketAddress>
The
AsyncQueueReader implementation, based on the Java NIO- Author:
- Alexey Stashok, Ryan Lubke, Gustav Trede
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueue
AsyncQueue.AsyncResult -
Field Summary
FieldsFields inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueue
EXPECTING_MORE_OPTIONFields inherited from interface org.glassfish.grizzly.Reader
COMPLETE_EVENT, INCOMPLETE_EVENT, READ_EVENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidclose()Close AsyncQueueProcessor and release associated resourcesprotected final intdoRead(Connection connection, AsyncReadQueueRecord queueRecord) Performs real read on the NIO channelfinal booleanisReady(Connection connection) Checks whether there is ready data inAsyncQueue, associated with theConnection.voidonClose(Connection connection) Callback method, which is called, whenConnectionhas been closed, to let processor release a connection associated resources.protected final voidonReadFailure(Connection connection, AsyncReadQueueRecord failedRecord, IOException e) protected abstract voidonReadyToRead(Connection connection) processAsync(Context context) Callback method, which is called async.voidread(Connection<SocketAddress> connection, Buffer buffer, CompletionHandler<ReadResult<Buffer, SocketAddress>> completionHandler, Interceptor<ReadResult> interceptor) Method reads data to the buffer.protected abstract intread0(Connection connection, Buffer buffer, ReadResult<Buffer, SocketAddress> currentResult) Methods inherited from class org.glassfish.grizzly.AbstractReader
read, read, read
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE- See Also:
-
defaultBufferSize
protected int defaultBufferSize -
transport
-
-
Constructor Details
-
AbstractNIOAsyncQueueReader
-
-
Method Details
-
read
public void read(Connection<SocketAddress> connection, Buffer buffer, CompletionHandler<ReadResult<Buffer, SocketAddress>> completionHandler, Interceptor<ReadResult> interceptor) Method reads data to the buffer.- Specified by:
readin interfaceReader<SocketAddress>- Parameters:
connection- theConnectionto read frombuffer- theBufferto which data will be readcompletionHandler-CompletionHandler, which will get notified, when read will be completedinterceptor-Interceptor, which will be able to intercept control each time new portion of a data was read to a buffer. The interceptor can decide, whether asynchronous read is completed or not, or provide other processing instructions.
-
isReady
Checks whether there is ready data inAsyncQueue, associated with theConnection.- Specified by:
isReadyin interfaceAsyncQueue- Parameters:
connection-Connection- Returns:
- true, if there is ready data, or false otherwise.
-
processAsync
Callback method, which is called async. to process readyAsyncQueue, which are associated with the givenConnection- Specified by:
processAsyncin interfaceAsyncQueue- Parameters:
context-Context- Returns:
AsyncQueue.AsyncResult, depending on async queue status.
-
onClose
Callback method, which is called, whenConnectionhas been closed, to let processor release a connection associated resources.- Specified by:
onClosein interfaceAsyncQueue- Parameters:
connection-Connection
-
close
public final void close()Close AsyncQueueProcessor and release associated resources- Specified by:
closein interfaceAsyncQueue
-
doRead
protected final int doRead(Connection connection, AsyncReadQueueRecord queueRecord) throws IOException Performs real read on the NIO channel- Parameters:
connection- theConnectionto read fromqueueRecord- the record to be read to- Throws:
IOException
-
onReadFailure
protected final void onReadFailure(Connection connection, AsyncReadQueueRecord failedRecord, IOException e) -
read0
protected abstract int read0(Connection connection, Buffer buffer, ReadResult<Buffer, SocketAddress> currentResult) throws IOException- Throws:
IOException
-
onReadyToRead
- Throws:
IOException
-