org.glassfish.grizzly.nio
Class AbstractNIOAsyncQueueReader

java.lang.Object
  extended by org.glassfish.grizzly.AbstractReader<java.net.SocketAddress>
      extended by org.glassfish.grizzly.nio.AbstractNIOAsyncQueueReader
All Implemented Interfaces:
AsyncQueue, AsyncQueueReader<java.net.SocketAddress>, Reader<java.net.SocketAddress>
Direct Known Subclasses:
TCPNIOAsyncQueueReader, UDPNIOAsyncQueueReader

public abstract class AbstractNIOAsyncQueueReader
extends AbstractReader<java.net.SocketAddress>
implements AsyncQueueReader<java.net.SocketAddress>

The AsyncQueueReader implementation, based on the Java NIO

Author:
Alexey Stashok, Ryan Lubke, Gustav Trede

Field Summary
static int DEFAULT_BUFFER_SIZE
           
protected  int defaultBufferSize
           
protected  NIOTransport transport
           
 
Fields inherited from interface org.glassfish.grizzly.Reader
COMPLETE_EVENT, INCOMPLETE_EVENT, READ_EVENT
 
Constructor Summary
AbstractNIOAsyncQueueReader(NIOTransport transport)
           
 
Method Summary
 void close()
          Close AsyncQueueProcessor and release associated resources
protected  int doRead(Connection connection, AsyncReadQueueRecord queueRecord)
          Performs real read on the NIO channel
protected  void failReadRecord(AsyncReadQueueRecord record, java.lang.Throwable e)
           
 boolean isReady(Connection connection)
          Checks whether there is ready data in AsyncQueue, associated with the Connection.
 void onClose(Connection connection)
          Callback method, which is called, when Connection has been closed, to let processor release a connection associated resources.
protected  void onReadComplete(AsyncReadQueueRecord record)
           
protected  void onReadFailure(Connection connection, AsyncReadQueueRecord failedRecord, java.io.IOException e)
           
protected  void onReadIncomplete(AsyncReadQueueRecord record)
           
protected abstract  void onReadyToRead(Connection connection)
           
 boolean processAsync(Context context)
          Callback method, which is called async.
 GrizzlyFuture<ReadResult<Buffer,java.net.SocketAddress>> read(Connection connection, Buffer buffer, CompletionHandler<ReadResult<Buffer,java.net.SocketAddress>> completionHandler, Interceptor<ReadResult> interceptor)
          Method reads data to the buffer.
protected abstract  int read0(Connection connection, Buffer buffer, ReadResult<Buffer,java.net.SocketAddress> currentResult)
           
 
Methods inherited from class org.glassfish.grizzly.AbstractReader
read, read, read
 
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.Reader
read, read, read
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values

defaultBufferSize

protected int defaultBufferSize

transport

protected final NIOTransport transport
Constructor Detail

AbstractNIOAsyncQueueReader

public AbstractNIOAsyncQueueReader(NIOTransport transport)
Method Detail

read

public GrizzlyFuture<ReadResult<Buffer,java.net.SocketAddress>> read(Connection connection,
                                                                     Buffer buffer,
                                                                     CompletionHandler<ReadResult<Buffer,java.net.SocketAddress>> completionHandler,
                                                                     Interceptor<ReadResult> interceptor)
                                                              throws java.io.IOException
Method reads data to the buffer.

Specified by:
read in interface Reader<java.net.SocketAddress>
Parameters:
connection - the Connection to read from
buffer - the Buffer to which data will be read
completionHandler - CompletionHandler, which will get notified, when read will be completed
interceptor - 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.
Returns:
Future, using which it's possible to check the result
Throws:
java.io.IOException

isReady

public final boolean isReady(Connection connection)
Checks whether there is ready data in AsyncQueue, associated with the Connection.

Specified by:
isReady in interface AsyncQueue
Parameters:
connection - Connection
Returns:
true, if there is ready data, or false otherwise.

processAsync

public boolean processAsync(Context context)
                     throws java.io.IOException
Callback method, which is called async. to process ready AsyncQueue, which are associated with the given Connection

Specified by:
processAsync in interface AsyncQueue
Parameters:
context - Context
Returns:
true, if there are pending elements to be processed, or false otherwise.
Throws:
java.io.IOException

onClose

public void onClose(Connection connection)
Callback method, which is called, when Connection has been closed, to let processor release a connection associated resources.

Specified by:
onClose in interface AsyncQueue
Parameters:
connection - Connection

close

public final void close()
Close AsyncQueueProcessor and release associated resources

Specified by:
close in interface AsyncQueue

doRead

protected final int doRead(Connection connection,
                           AsyncReadQueueRecord queueRecord)
                    throws java.io.IOException
Performs real read on the NIO channel

Parameters:
connection - the Connection to read from
queueRecord - the record to be read to
Throws:
java.io.IOException

onReadComplete

protected final void onReadComplete(AsyncReadQueueRecord record)
                             throws java.io.IOException
Throws:
java.io.IOException

onReadIncomplete

protected final void onReadIncomplete(AsyncReadQueueRecord record)
                               throws java.io.IOException
Throws:
java.io.IOException

onReadFailure

protected final void onReadFailure(Connection connection,
                                   AsyncReadQueueRecord failedRecord,
                                   java.io.IOException e)

failReadRecord

protected final void failReadRecord(AsyncReadQueueRecord record,
                                    java.lang.Throwable e)

read0

protected abstract int read0(Connection connection,
                             Buffer buffer,
                             ReadResult<Buffer,java.net.SocketAddress> currentResult)
                      throws java.io.IOException
Throws:
java.io.IOException

onReadyToRead

protected abstract void onReadyToRead(Connection connection)
                               throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2011 Oracle Corpration. All Rights Reserved.