voldemort.utils
Class SelectorManagerWorker
java.lang.Object
voldemort.utils.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.
|
Constructor Summary |
SelectorManagerWorker(java.nio.channels.Selector selector,
java.nio.channels.SocketChannel socketChannel,
int socketBufferSize)
|
|
Method Summary |
void |
close()
|
protected void |
closeInternal()
|
long |
getCreateTimestamp()
Returns the nanosecond-based timestamp of when this was created. |
protected void |
handleIncompleteRequest(int newPosition)
|
boolean |
isClosed()
|
protected void |
prepForWrite(java.nio.channels.SelectionKey selectionKey)
Flips the output buffer, and lets the Selector know we're ready to write. |
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 |
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 final ByteBufferBackedInputStream inputStream
outputStream
protected final ByteBufferBackedOutputStream outputStream
createTimestamp
protected final long createTimestamp
isClosed
protected final java.util.concurrent.atomic.AtomicBoolean isClosed
logger
protected final org.apache.log4j.Logger logger
SelectorManagerWorker
public SelectorManagerWorker(java.nio.channels.Selector selector,
java.nio.channels.SocketChannel socketChannel,
int socketBufferSize)
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
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()
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 -
handleIncompleteRequest
protected void handleIncompleteRequest(int newPosition)
traceInputBufferState
protected void traceInputBufferState(java.lang.String preamble)
Jay Kreps, Roshan Sumbaly, Alex Feinberg, Bhupesh Bansal, Lei Gao