com.sun.grizzly.async
Class TCPAsyncQueueWriter

java.lang.Object
  extended by com.sun.grizzly.async.AbstractAsyncQueueWriter
      extended by com.sun.grizzly.async.TCPAsyncQueueWriter
All Implemented Interfaces:
AsyncQueueWriter

public class TCPAsyncQueueWriter
extends AbstractAsyncQueueWriter

TCP implementation of AsyncQueueWriter

Author:
Alexey Stashok

Field Summary
 
Fields inherited from class com.sun.grizzly.async.AbstractAsyncQueueWriter
selectorHandler
 
Constructor Summary
TCPAsyncQueueWriter(SelectorHandler selectorHandler)
           
 
Method Summary
protected  OperationResult doWrite(WritableByteChannel channel, SocketAddress dstAddress, ByteBuffer byteBuffer, OperationResult dstResult)
           
 Future<AsyncQueueWriteUnit> write(SelectionKey key, SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor, ByteBufferCloner cloner)
          Method sends ByteBuffer to the SocketAddress First, if SelectableChannel associated write queue is empty - it tries to write ByteBuffer to the given SocketAddress directly (without putting to the queue).
 
Methods inherited from class com.sun.grizzly.async.AbstractAsyncQueueWriter
close, doWrite, getAsyncQueue, isReady, onClose, onWrite, registerForWriting, write, write, write, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TCPAsyncQueueWriter

public TCPAsyncQueueWriter(SelectorHandler selectorHandler)
Method Detail

write

public Future<AsyncQueueWriteUnit> write(SelectionKey key,
                                         SocketAddress dstAddress,
                                         ByteBuffer buffer,
                                         AsyncWriteCallbackHandler callbackHandler,
                                         AsyncQueueDataProcessor writePreProcessor,
                                         ByteBufferCloner cloner)
                                  throws IOException
Method sends ByteBuffer to the SocketAddress First, if SelectableChannel associated write queue is empty - it tries to write ByteBuffer to the given SocketAddress directly (without putting to the queue). If associated write queue is not empty or after direct writing ByteBuffer still has ready data to be written - ByteBuffer will be added to AsyncQueue and SelectableChannel will be registered on SelectorHandler, waiting for OP_WRITE event. If an exception occurs, during direct writing - it will be propagated to the caller directly and come via AsyncWriteCallbackHandler.onIOException() Before data will be written on SelectableChannel, first it will be passed for preprocessing to AsyncQueueDataProcessor, and then preprocessor result data (AsyncQueueDataProcessor.getResultByteBuffer()) will be written on the SelectableChannel.

Specified by:
write in interface AsyncQueueWriter
Overrides:
write in class AbstractAsyncQueueWriter
Parameters:
key - SelectionKey associated with SelectableChannel ByteBuffer should be written to
dstAddress - destination address ByteBuffer will be sent to
buffer - ByteBuffer
callbackHandler - AsyncWriteCallbackHandler, which will get notified, when ByteBuffer will be completely written
writePreProcessor - AsyncQueueDataProcessor, which will perform data processing, before it will be written on SelectableChannel
Throws:
IOException

doWrite

protected OperationResult doWrite(WritableByteChannel channel,
                                  SocketAddress dstAddress,
                                  ByteBuffer byteBuffer,
                                  OperationResult dstResult)
                           throws IOException
Specified by:
doWrite in class AbstractAsyncQueueWriter
Throws:
IOException


Copyright © 2012 Oracle Corporation. All Rights Reserved.