org.glassfish.grizzly.nio
Class AbstractNIOAsyncQueueReader

java.lang.Object
  extended by org.glassfish.grizzly.AbstractReader<SocketAddress>
      extended by org.glassfish.grizzly.nio.AbstractNIOAsyncQueueReader
All Implemented Interfaces:
AsyncQueueProcessor, AsyncQueueReader<SocketAddress>, Processor, 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

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
 
Fields inherited from interface org.glassfish.grizzly.asyncqueue.AsyncQueueProcessor
NOT_REGISTER_KEY
 
Constructor Summary
AbstractNIOAsyncQueueReader(NIOTransport transport)
           
 
Method Summary
 void close()
          Close AsyncQueueProcessor and release associated resources
protected  int doRead(Connection connection, ReadResult currentResult, Buffer message)
          Performs real read on the NIO channel
protected  void failReadRecord(Connection connection, AsyncReadQueueRecord record, IOException e)
           
 ObjectPool getContextPool()
          
 boolean isInterested(IOEvent ioEvent)
          Is this Processor interested in processing the i/o event
 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 onReadCompleted(Connection connection, AsyncReadQueueRecord record)
           
protected  void onReadFailure(Connection connection, AsyncReadQueueRecord failedRecord, IOException e)
           
protected  void onReadIncompleted(Connection connection, AsyncReadQueueRecord record)
           
protected abstract  void onReadyToRead(Connection connection)
           
 ProcessorResult process(Context context)
          Method will be called by framework to process some event, which occured on a connection
 void processAsync(Connection connection)
          Callback method, which is called async.
 Future<ReadResult<Buffer,SocketAddress>> read(Connection connection, Buffer buffer, CompletionHandler<ReadResult<Buffer,SocketAddress>> completionHandler, Interceptor<ReadResult> interceptor)
          Method reads data to the buffer.
protected abstract  int read0(Connection connection, Buffer buffer, ReadResult<Buffer,SocketAddress> currentResult)
           
 void setInterested(IOEvent ioEvent, boolean isInterested)
          Set the the i/o event, this Processor is interested in
 
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
 
Methods inherited from interface org.glassfish.grizzly.Processor
afterProcess, beforeProcess, context
 

Field Detail

DEFAULT_BUFFER_SIZE

public static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values

defaultBufferSize

protected int defaultBufferSize

transport

protected NIOTransport transport
Constructor Detail

AbstractNIOAsyncQueueReader

public AbstractNIOAsyncQueueReader(NIOTransport transport)
Method Detail

read

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

Specified by:
read in interface Reader<SocketAddress>
Parameters:
connection - the Connection to read from
buffer - the buffer, where 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:
IOException

isReady

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

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

processAsync

public void processAsync(Connection connection)
                  throws IOException
Callback method, which is called async. to process ready AsyncQueue, which are associated with the given Connection

Specified by:
processAsync in interface AsyncQueueProcessor
Parameters:
connection - Connection
Throws:
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 AsyncQueueProcessor
Parameters:
connection - Connection

getContextPool

public ObjectPool getContextPool()


isInterested

public boolean isInterested(IOEvent ioEvent)
Is this Processor interested in processing the i/o event

Specified by:
isInterested in interface Processor
Returns:
true, if this Processor is interested and execution process will start, false otherwise.

process

public ProcessorResult process(Context context)
                        throws IOException
Method will be called by framework to process some event, which occured on a connection

Specified by:
process in interface Processor
Parameters:
context - processing context
Returns:
the result of I/O event processing
Throws:
IOException

setInterested

public void setInterested(IOEvent ioEvent,
                          boolean isInterested)
Set the the i/o event, this Processor is interested in

Specified by:
setInterested in interface Processor
Parameters:
ioEvent - IOEvent
isInterested - true, if Processor is interested in processing of the I/O event, or false otherwise.

close

public void close()
Close AsyncQueueProcessor and release associated resources

Specified by:
close in interface AsyncQueueProcessor

doRead

protected int doRead(Connection connection,
                     ReadResult currentResult,
                     Buffer message)
              throws IOException
Performs real read on the NIO channel

Parameters:
connection - the Connection to read from
readFuture - the asynchronous operation result holder
message - the message to read to
Throws:
IOException

onReadCompleted

protected void onReadCompleted(Connection connection,
                               AsyncReadQueueRecord record)
                        throws IOException
Throws:
IOException

onReadIncompleted

protected void onReadIncompleted(Connection connection,
                                 AsyncReadQueueRecord record)
                          throws IOException
Throws:
IOException

onReadFailure

protected void onReadFailure(Connection connection,
                             AsyncReadQueueRecord failedRecord,
                             IOException e)

failReadRecord

protected void failReadRecord(Connection connection,
                              AsyncReadQueueRecord record,
                              IOException e)

read0

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

onReadyToRead

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


Copyright © 2009 SUN Microsystems. All Rights Reserved.