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

Constructor Summary
TCPAsyncQueueWriter(SelectorHandler selectorHandler)
           
 
Method Summary
protected  void doWrite(WritableByteChannel channel, SocketAddress dstAddress, ByteBuffer byteBuffer)
           
 void write(SelectionKey key, SocketAddress dstAddress, ByteBuffer buffer, AsyncWriteCallbackHandler callbackHandler, AsyncQueueDataProcessor writePreProcessor, boolean isCloneByteBuffer)
          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, hasReadyAsyncWriteData, 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 void write(SelectionKey key,
                  SocketAddress dstAddress,
                  ByteBuffer buffer,
                  AsyncWriteCallbackHandler callbackHandler,
                  AsyncQueueDataProcessor writePreProcessor,
                  boolean isCloneByteBuffer)
           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, otherwise, if the ByteBuffer is added to a writing queue - exception notification will 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
isCloneByteBuffer - if true - AsyncQueueWriter will clone given ByteBuffer before puting it to the AsyncQueue
Throws:
IOException

doWrite

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


Copyright © 2011 SUN Microsystems. All Rights Reserved.