voldemort.common.nio
Class SelectorManagerWorker

java.lang.Object
  extended by voldemort.common.nio.SelectorManagerWorker
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
AsyncRequestHandler, ClientRequestExecutor

public abstract class SelectorManagerWorker
extends java.lang.Object
implements java.lang.Runnable

SelectorManagerWorker manages a Selector, SocketChannel, and IO streams 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.


Field Summary
protected  long createTimestamp
           
protected  ByteBufferBackedInputStream inputStream
           
protected  java.util.concurrent.atomic.AtomicBoolean isClosed
           
protected  org.apache.log4j.Logger logger
           
protected  ByteBufferBackedOutputStream outputStream
           
protected  int resizeThreshold
           
protected  java.nio.channels.Selector selector
           
protected  int socketBufferSize
           
protected  java.nio.channels.SocketChannel socketChannel
           
 
Constructor Summary
SelectorManagerWorker(java.nio.channels.Selector selector, java.nio.channels.SocketChannel socketChannel, int socketBufferSize, CommBufferSizeStats commBufferStats)
           
 
Method Summary
 void close()
           
protected  void closeInternal()
           
 long getCreateTimestamp()
          Returns the nanosecond-based timestamp of when this was created.
protected  void handleIncompleteRequest(int newPosition)
           
protected abstract  void initializeStreams(int socketBufferSize, CommBufferSizeStats commBufferStats)
           
 boolean isClosed()
           
protected abstract  void read(java.nio.channels.SelectionKey selectionKey)
           
 void run()
           
protected  void traceInputBufferState(java.lang.String preamble)
           
protected abstract  void write(java.nio.channels.SelectionKey selectionKey)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

selector

protected final java.nio.channels.Selector selector

socketChannel

protected final java.nio.channels.SocketChannel socketChannel

socketBufferSize

protected final int socketBufferSize

resizeThreshold

protected final int resizeThreshold

inputStream

protected ByteBufferBackedInputStream inputStream

outputStream

protected ByteBufferBackedOutputStream outputStream

createTimestamp

protected final long createTimestamp

isClosed

protected final java.util.concurrent.atomic.AtomicBoolean isClosed

logger

protected final org.apache.log4j.Logger logger
Constructor Detail

SelectorManagerWorker

public SelectorManagerWorker(java.nio.channels.Selector selector,
                             java.nio.channels.SocketChannel socketChannel,
                             int socketBufferSize,
                             CommBufferSizeStats commBufferStats)
Method Detail

read

protected abstract void read(java.nio.channels.SelectionKey selectionKey)
                      throws java.io.IOException
Throws:
java.io.IOException

write

protected abstract void write(java.nio.channels.SelectionKey selectionKey)
                       throws java.io.IOException
Throws:
java.io.IOException

initializeStreams

protected abstract void initializeStreams(int socketBufferSize,
                                          CommBufferSizeStats commBufferStats)

getCreateTimestamp

public long getCreateTimestamp()
Returns the nanosecond-based timestamp of when this was created.

Returns:
Nanosecond-based timestamp of creation

run

public void run()
Specified by:
run in interface java.lang.Runnable

close

public void close()

closeInternal

protected void closeInternal()

isClosed

public boolean isClosed()

handleIncompleteRequest

protected void handleIncompleteRequest(int newPosition)

traceInputBufferState

protected void traceInputBufferState(java.lang.String preamble)


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