com.sun.grizzly.nio
Class AbstractNIOAsyncQueueWriter

java.lang.Object
  extended by com.sun.grizzly.AbstractWriter<SocketAddress>
      extended by com.sun.grizzly.nio.AbstractNIOAsyncQueueWriter
All Implemented Interfaces:
AsyncQueueProcessor, AsyncQueueWriter<SocketAddress>, Processor, Writer<SocketAddress>
Direct Known Subclasses:
TCPNIOAsyncQueueWriter, UDPNIOAsyncQueueWriter

public abstract class AbstractNIOAsyncQueueWriter
extends AbstractWriter<SocketAddress>
implements AsyncQueueWriter<SocketAddress>

The AsyncQueueWriter implementation, based on the Java NIO

Author:
Alexey Stashok

Field Summary
protected  NIOTransport transport
           
 
Fields inherited from interface com.sun.grizzly.asyncqueue.AsyncQueueProcessor
NOT_REGISTER_KEY
 
Constructor Summary
AbstractNIOAsyncQueueWriter(NIOTransport transport)
           
 
Method Summary
 void close()
          Close AsyncQueueProcessor and release associated resources
protected
<E> void
doWrite(Connection connection, WriteResult currentResult, CompletionHandler completionHandler, SocketAddress dstAddress, Buffer buffer)
          Performs real write on the NIO channel
protected  void failWriteRecord(Connection connection, AsyncWriteQueueRecord record, Throwable 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 abstract  void onReadyToWrite(Connection connection)
           
protected  void onWriteCompleted(Connection connection, AsyncWriteQueueRecord<?> record)
           
protected  void onWriteFailure(Connection connection, AsyncWriteQueueRecord failedRecord, IOException e)
           
protected  void onWriteIncompleted(Connection connection, AsyncWriteQueueRecord<?> record)
           
 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.
 void setInterested(IOEvent ioEvent, boolean isInterested)
          Set the the i/o event, this Processor is interested in
 Future<WriteResult<Buffer,SocketAddress>> write(Connection connection, SocketAddress dstAddress, Buffer buffer, CompletionHandler<WriteResult<Buffer,SocketAddress>> completionHandler, Interceptor<WriteResult> interceptor)
          Method writes the buffer to the specific address.
 Future<WriteResult<Buffer,SocketAddress>> write(Connection connection, SocketAddress dstAddress, Buffer buffer, CompletionHandler<WriteResult<Buffer,SocketAddress>> completionHandler, Interceptor<WriteResult> interceptor, MessageCloner<Buffer> cloner)
          Method writes the Buffer to the specific address.
protected abstract  int write0(Connection connection, SocketAddress dstAddress, Buffer buffer, WriteResult<Buffer,SocketAddress> currentResult)
           
 
Methods inherited from class com.sun.grizzly.AbstractWriter
write, 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 com.sun.grizzly.Writer
write, write, write, write, write
 
Methods inherited from interface com.sun.grizzly.Processor
afterProcess, beforeProcess, context
 

Field Detail

transport

protected NIOTransport transport
Constructor Detail

AbstractNIOAsyncQueueWriter

public AbstractNIOAsyncQueueWriter(NIOTransport transport)
Method Detail

write

public Future<WriteResult<Buffer,SocketAddress>> write(Connection connection,
                                                       SocketAddress dstAddress,
                                                       Buffer buffer,
                                                       CompletionHandler<WriteResult<Buffer,SocketAddress>> completionHandler,
                                                       Interceptor<WriteResult> interceptor)
                                                throws IOException
Method writes the buffer to the specific address.

Specified by:
write in interface Writer<SocketAddress>
Parameters:
connection - the Connection to write to
dstAddress - the destination address the buffer will be sent to
buffer - the buffer, from which the data will be written
completionHandler - CompletionHandler, which will get notified, when write will be completed
interceptor - Interceptor, which will be able to intercept control each time new portion of a data was written from a buffer. The interceptor can decide, whether asynchronous write is completed or not, or provide other processing instructions.
Returns:
Future, using which it's possible to check the result
Throws:
IOException

write

public Future<WriteResult<Buffer,SocketAddress>> write(Connection connection,
                                                       SocketAddress dstAddress,
                                                       Buffer buffer,
                                                       CompletionHandler<WriteResult<Buffer,SocketAddress>> completionHandler,
                                                       Interceptor<WriteResult> interceptor,
                                                       MessageCloner<Buffer> cloner)
                                                throws IOException
Method writes the Buffer to the specific address.

Specified by:
write in interface AsyncQueueWriter<SocketAddress>
Parameters:
connection - the Connection to write to
dstAddress - the destination address the message will be sent to
buffer - the message, from which the data will be written
completionHandler - CompletionHandler, which will get notified, when write will be completed
interceptor - Interceptor, which will be able to intercept control each time new portion of a data was written from a buffer. The interceptor can decide, whether asynchronous write is completed or not, or provide other processing instructions.
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
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

doWrite

protected <E> void doWrite(Connection connection,
                           WriteResult currentResult,
                           CompletionHandler completionHandler,
                           SocketAddress dstAddress,
                           Buffer buffer)
                throws IOException
Performs real write on the NIO channel

Parameters:
connection - the Connection to write to
currentResult - current result of the write operation
dstAddress - destination address
message - the message to write
writePreProcessor - write post-processor
Throws:
IOException

onWriteCompleted

protected void onWriteCompleted(Connection connection,
                                AsyncWriteQueueRecord<?> record)
                         throws IOException
Throws:
IOException

onWriteIncompleted

protected void onWriteIncompleted(Connection connection,
                                  AsyncWriteQueueRecord<?> record)
                           throws IOException
Throws:
IOException

onWriteFailure

protected void onWriteFailure(Connection connection,
                              AsyncWriteQueueRecord failedRecord,
                              IOException e)

failWriteRecord

protected void failWriteRecord(Connection connection,
                               AsyncWriteQueueRecord record,
                               Throwable e)

write0

protected abstract int write0(Connection connection,
                              SocketAddress dstAddress,
                              Buffer buffer,
                              WriteResult<Buffer,SocketAddress> currentResult)
                       throws IOException
Throws:
IOException

onReadyToWrite

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


Copyright © 2009 SUN Microsystems. All Rights Reserved.