public abstract class AbstractPollingIoProcessor<T extends AbstractIoSession> extends Object implements IoProcessor<T>
IoProcessor which helps
transport developers to write an IoProcessor easily.
This class is in charge of active polling a set of IoSession
and trigger events when some I/O operation is possible.| Modifier | Constructor and Description |
|---|---|
protected |
AbstractPollingIoProcessor(Executor executor)
Create an
AbstractPollingIoProcessor with the given Executor
for handling I/Os events. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(T session)
Adds the specified
session to the I/O processor so that
the I/O processor starts to perform any I/O operations related
with the session. |
protected abstract Iterator<T> |
allSessions()
|
protected abstract void |
destroy(T session)
Destroy the underlying client socket handle
|
void |
dispose()
Releases any resources allocated by this processor.
|
protected abstract void |
dispose0()
Dispose the resources used by this
IoProcessor for polling
the client connections |
void |
flush(T session)
Flushes the internal write request queue of the specified
session. |
protected abstract SessionState |
getState(T session)
Get the state of a session (preparing, open, closed)
|
protected Object |
getWriteRequestMessage(T session,
WriteRequest writeRequest)
Determines the message (IoBuffer) that will actually get written
|
protected abstract void |
init(T session)
Initialize the polling of a session.
|
boolean |
isDisposed()
Returns true if and if only all resources of this processor
have been disposed.
|
boolean |
isDisposing()
Returns true if and if only
IoProcessor.dispose() method has
been called. |
protected abstract boolean |
isInterestedInRead(T session)
is this session registered for reading
|
protected abstract boolean |
isInterestedInWrite(T session)
is this session registered for writing
|
protected abstract boolean |
isReadable(T session)
Is the session ready for reading
|
protected abstract boolean |
isSelectorEmpty()
Say if the list of
IoSession polled by this IoProcessor
is empty |
protected abstract boolean |
isWritable(T session)
Is the session ready for writing
|
protected IoBuffer |
newReadBuffer(int readBufferSize) |
protected abstract int |
read(T session,
IoBuffer buf)
|
void |
remove(T session)
Removes and closes the specified
session from the I/O
processor so that the I/O processor closes the connection
associated with the session and releases any other related
resources. |
protected abstract int |
select()
poll those sessions forever
|
protected abstract int |
select(long timeout)
poll those sessions for the given timeout
|
protected abstract Iterator<T> |
selectedSessions()
|
protected abstract void |
setInterestedInRead(T session,
boolean isInterested)
register a session for reading
|
protected abstract void |
setInterestedInWrite(T session,
boolean isInterested)
register a session for writing
|
protected abstract int |
transferFile(T 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 write(AbstractIoSession, IoBuffer, int) call. |
void |
updateTrafficControl(T session)
Controls the traffic of the specified
session depending of the
IoSession.isReadSuspended() and IoSession.isWriteSuspended()
flags |
void |
updateTrafficMask(T session) |
protected abstract void |
wakeup()
Interrupt the {@link AbstractPollingIoProcessor#select(int) call.
|
protected abstract int |
write(T 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. |
protected int |
writeBuffer(T session,
WriteRequest req,
IoBuffer buf,
boolean hasFragmentation,
int maxLength,
long currentTime) |
protected AbstractPollingIoProcessor(Executor executor)
AbstractPollingIoProcessor with the given Executor
for handling I/Os events.executor - the Executor for handling I/O eventspublic final boolean isDisposing()
IoProcessor.dispose() method has
been called. Please note that this method will return true
even after all the related resources are released.isDisposing in interface IoProcessor<T extends AbstractIoSession>public final boolean isDisposed()
isDisposed in interface IoProcessor<T extends AbstractIoSession>public final void dispose()
dispose in interface IoProcessor<T extends AbstractIoSession>protected abstract void dispose0()
throws Exception
IoProcessor for polling
the client connectionsException - if some low level IO error occursprotected abstract int select(long timeout)
throws Exception
timeout - milliseconds before the call timeout if no event appearException - if some low level IO error occursprotected abstract int select()
throws Exception
Exception - if some low level IO error occursprotected abstract boolean isSelectorEmpty()
IoSession polled by this IoProcessor
is emptyIoProcessorprotected abstract void wakeup()
protected abstract SessionState getState(T session)
session - the IoSession to inspectprotected Object getWriteRequestMessage(T session, WriteRequest writeRequest)
protected abstract boolean isWritable(T session)
session - the session queriedprotected abstract boolean isReadable(T session)
session - the session queriedprotected abstract void setInterestedInWrite(T session, boolean isInterested) throws Exception
session - the session registeredisInterested - true for registering, false for removingExceptionprotected abstract void setInterestedInRead(T session, boolean isInterested) throws Exception
session - the session registeredisInterested - true for registering, false for removingExceptionprotected abstract boolean isInterestedInRead(T session)
session - the session queriedprotected abstract boolean isInterestedInWrite(T session)
session - the session queriedprotected abstract void init(T session) throws Exception
protected abstract void destroy(T session) throws Exception
protected abstract int read(T session, IoBuffer buf) throws Exception
IoSession into the given IoBuffer.
Is called when the session was found ready for reading.session - the session to readbuf - the buffer to fillException - any exception thrown by the underlying system callsprotected abstract int write(T session, IoBuffer buf, int length) throws Exception
IoSession, means to be called when a session
was found ready for writing.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 abstract int transferFile(T session, FileRegion region, int length) throws Exception
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 write(AbstractIoSession, IoBuffer, int) call.session - the session to writeregion - the file region to writelength - the length of the portion to sendException - any exception thrown by the underlying system callspublic final void add(T session)
session to the I/O processor so that
the I/O processor starts to perform any I/O operations related
with the session.add in interface IoProcessor<T extends AbstractIoSession>public final void remove(T session)
session from the I/O
processor so that the I/O processor closes the connection
associated with the session and releases any other related
resources.remove in interface IoProcessor<T extends AbstractIoSession>public final void flush(T session)
session.flush in interface IoProcessor<T extends AbstractIoSession>public final void updateTrafficMask(T session)
protected IoBuffer newReadBuffer(int readBufferSize)
protected int writeBuffer(T session, WriteRequest req, IoBuffer buf, boolean hasFragmentation, int maxLength, long currentTime) throws Exception
Exceptionpublic void updateTrafficControl(T session)
session depending of the
IoSession.isReadSuspended() and IoSession.isWriteSuspended()
flagsupdateTrafficControl in interface IoProcessor<T extends AbstractIoSession>Copyright © 2004–2017. All rights reserved.