voldemort.server.niosocket
Class AsyncRequestHandler

java.lang.Object
  extended by voldemort.common.nio.SelectorManagerWorker
      extended by voldemort.server.niosocket.AsyncRequestHandler
All Implemented Interfaces:
java.lang.Runnable

public class AsyncRequestHandler
extends SelectorManagerWorker

AsyncRequestHandler manages a Selector, SocketChannel, and RequestHandler implementation. At the point that the run method is invoked, the Selector with which the (socket) Channel has been registered has notified us that the socket has data to read or write.

The bulk of the complexity in this class surrounds partial reads and writes, as well as determining when all the data needed for the request has been read.

See Also:
RequestHandler

Field Summary
 
Fields inherited from class voldemort.common.nio.SelectorManagerWorker
createTimestamp, inputStream, isClosed, logger, outputStream, resizeThreshold, selector, socketBufferSize, socketChannel
 
Constructor Summary
AsyncRequestHandler(java.nio.channels.Selector selector, java.nio.channels.SocketChannel socketChannel, RequestHandlerFactory requestHandlerFactory, int socketBufferSize, NioSelectorManagerStats nioStats)
           
 
Method Summary
 void close()
           
protected  void initializeStreams(int socketBufferSize, CommBufferSizeStats commBufferStats)
           
protected  void prepForWrite(java.nio.channels.SelectionKey selectionKey)
          Flips the output buffer, and lets the Selector know we're ready to write.
protected  void read(java.nio.channels.SelectionKey selectionKey)
           
protected  void write(java.nio.channels.SelectionKey selectionKey)
           
 
Methods inherited from class voldemort.common.nio.SelectorManagerWorker
closeInternal, getCreateTimestamp, handleIncompleteRequest, isClosed, run, traceInputBufferState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncRequestHandler

public AsyncRequestHandler(java.nio.channels.Selector selector,
                           java.nio.channels.SocketChannel socketChannel,
                           RequestHandlerFactory requestHandlerFactory,
                           int socketBufferSize,
                           NioSelectorManagerStats nioStats)
Method Detail

prepForWrite

protected void prepForWrite(java.nio.channels.SelectionKey selectionKey)
Flips the output buffer, and lets the Selector know we're ready to write.

Parameters:
selectionKey -

initializeStreams

protected void initializeStreams(int socketBufferSize,
                                 CommBufferSizeStats commBufferStats)
Specified by:
initializeStreams in class SelectorManagerWorker

read

protected void read(java.nio.channels.SelectionKey selectionKey)
             throws java.io.IOException
Specified by:
read in class SelectorManagerWorker
Throws:
java.io.IOException

write

protected void write(java.nio.channels.SelectionKey selectionKey)
              throws java.io.IOException
Specified by:
write in class SelectorManagerWorker
Throws:
java.io.IOException

close

public void close()
Overrides:
close in class SelectorManagerWorker


Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao, Chinmay Soman, Vinoth Chandar, Zhongjie Wu