public final class NioProcessor extends AbstractPollingIoProcessor<NioSession>
| Modifier and Type | Class and Description |
|---|---|
protected static class |
NioProcessor.IoSessionIterator<NioSession>
An encapsulating iterator around the
Selector.selectedKeys() or
the Selector.keys() iterator; |
wakeupCalled| Constructor and Description |
|---|
NioProcessor(Executor executor)
Creates a new instance of NioProcessor.
|
| Modifier and Type | Method and Description |
|---|---|
protected Iterator<NioSession> |
allSessions()
|
protected void |
destroy(NioSession session)
Destroy the underlying client socket handle
|
protected void |
doDispose()
Dispose the resources used by this
IoProcessor for polling the
client connections. |
protected SessionState |
getState(NioSession session)
Get the state of a session (preparing, open, closed)
|
protected void |
init(NioSession session)
Initialize the polling of a session.
|
protected boolean |
isBrokenConnection()
Check that the select() has not exited immediately just because of a
broken connection.
|
protected boolean |
isInterestedInRead(NioSession session)
is this session registered for reading
|
protected boolean |
isInterestedInWrite(NioSession session)
is this session registered for writing
|
protected boolean |
isReadable(NioSession session)
Is the session ready for reading
|
protected boolean |
isSelectorEmpty()
Say if the list of
IoSession polled by this IoProcessor
is empty |
protected boolean |
isWritable(NioSession session)
Is the session ready for writing
|
protected int |
read(NioSession session,
IoBuffer buf)
|
protected void |
registerNewSelector()
In the case we are using the java select() method, this method is used to
trash the buggy selector and create a new one, registering all the
sockets on it.
|
protected int |
select()
poll those sessions forever
|
protected int |
select(long timeout)
poll those sessions for the given timeout
|
protected Iterator<NioSession> |
selectedSessions()
|
protected void |
setInterestedInRead(NioSession session,
boolean isInterested)
register a session for reading
|
protected void |
setInterestedInWrite(NioSession session,
boolean isInterested)
register a session for writing
|
protected int |
transferFile(NioSession session,
FileRegion region,
int length)
Write a part of a file to a
IoSession, if the underlying API
isn't supporting system calls like sendfile(), you can throw a
UnsupportedOperationException so the file will be send using
usual AbstractPollingIoProcessor.write(AbstractIoSession, IoBuffer, int) call. |
protected void |
wakeup()
Interrupt the {@link AbstractPollingIoProcessor#select(int) call.
|
protected int |
write(NioSession session,
IoBuffer buf,
int length)
Write a sequence of bytes to a
IoSession, means to be called when
a session was found ready for writing. |
add, dispose, flush, isDisposed, isDisposing, remove, updateTrafficControl, updateTrafficMask, writepublic NioProcessor(Executor executor)
executor - protected void doDispose()
throws Exception
AbstractPollingIoProcessorIoProcessor for polling the
client connections. The implementing class doDispose method will be called.doDispose in class AbstractPollingIoProcessor<NioSession>Exception - if some low level IO error occursprotected int select(long timeout)
throws Exception
AbstractPollingIoProcessorselect in class AbstractPollingIoProcessor<NioSession>timeout - milliseconds before the call timeout if no event appearException - if some low level IO error occursprotected int select()
throws Exception
AbstractPollingIoProcessorselect in class AbstractPollingIoProcessor<NioSession>Exception - if some low level IO error occursprotected boolean isSelectorEmpty()
AbstractPollingIoProcessorIoSession polled by this IoProcessor
is emptyisSelectorEmpty in class AbstractPollingIoProcessor<NioSession>IoProcessorprotected void wakeup()
AbstractPollingIoProcessorwakeup in class AbstractPollingIoProcessor<NioSession>protected Iterator<NioSession> allSessions()
AbstractPollingIoProcessorallSessions in class AbstractPollingIoProcessor<NioSession>Iterator of IoSessionprotected Iterator<NioSession> selectedSessions()
AbstractPollingIoProcessorIterator for the list of IoSession found selected
by the last call of {@link AbstractPollingIoProcessor#select(int)selectedSessions in class AbstractPollingIoProcessor<NioSession>Iterator of IoSession read for I/Os operationprotected void init(NioSession session) throws Exception
AbstractPollingIoProcessorinit in class AbstractPollingIoProcessor<NioSession>session - the IoSession to add to the pollingException - any exception thrown by the underlying system callsprotected void destroy(NioSession session) throws Exception
AbstractPollingIoProcessordestroy in class AbstractPollingIoProcessor<NioSession>session - the IoSessionException - any exception thrown by the underlying system callsprotected void registerNewSelector()
throws IOException
registerNewSelector in class AbstractPollingIoProcessor<NioSession>IOException - If we got an exceptionprotected boolean isBrokenConnection()
throws IOException
isBrokenConnection in class AbstractPollingIoProcessor<NioSession>IOException - If we got an exceptionprotected SessionState getState(NioSession session)
getState in class AbstractPollingIoProcessor<NioSession>session - the IoSession to inspectprotected boolean isReadable(NioSession session)
AbstractPollingIoProcessorisReadable in class AbstractPollingIoProcessor<NioSession>session - the session queriedprotected boolean isWritable(NioSession session)
AbstractPollingIoProcessorisWritable in class AbstractPollingIoProcessor<NioSession>session - the session queriedprotected boolean isInterestedInRead(NioSession session)
AbstractPollingIoProcessorisInterestedInRead in class AbstractPollingIoProcessor<NioSession>session - the session queriedprotected boolean isInterestedInWrite(NioSession session)
AbstractPollingIoProcessorisInterestedInWrite in class AbstractPollingIoProcessor<NioSession>session - the session queriedprotected void setInterestedInRead(NioSession session, boolean isInterested) throws Exception
setInterestedInRead in class AbstractPollingIoProcessor<NioSession>session - the session registeredisInterested - true for registering, false for removingExceptionprotected void setInterestedInWrite(NioSession session, boolean isInterested) throws Exception
setInterestedInWrite in class AbstractPollingIoProcessor<NioSession>session - the session registeredisInterested - true for registering, false for removingExceptionprotected int read(NioSession session, IoBuffer buf) throws Exception
AbstractPollingIoProcessorIoSession into the given
IoBuffer. Is called when the session was found ready for reading.read in class AbstractPollingIoProcessor<NioSession>session - the session to readbuf - the buffer to fillException - any exception thrown by the underlying system callsprotected int write(NioSession session, IoBuffer buf, int length) throws Exception
AbstractPollingIoProcessorIoSession, means to be called when
a session was found ready for writing.write in class AbstractPollingIoProcessor<NioSession>session - the session to writebuf - the buffer to writelength - the number of bytes to write can be superior to the number of
bytes remaining in the bufferException - any exception thrown by the underlying system callsprotected int transferFile(NioSession session, FileRegion region, int length) throws Exception
AbstractPollingIoProcessorIoSession, if the underlying API
isn't supporting system calls like sendfile(), you can throw a
UnsupportedOperationException so the file will be send using
usual AbstractPollingIoProcessor.write(AbstractIoSession, IoBuffer, int) call.transferFile in class AbstractPollingIoProcessor<NioSession>session - the session to writeregion - the file region to writelength - the length of the portion to sendException - any exception thrown by the underlying system calls