S
- the type of the IoSession
this processor can handleIoProcessor<S>
AprIoProcessor
, NioProcessor
public abstract class AbstractPollingIoProcessor<S extends AbstractIoSession> extends Object implements IoProcessor<S>
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 and Type | Field | Description |
---|---|---|
protected AtomicBoolean |
wakeupCalled |
Modifier | Constructor | Description |
---|---|---|
protected |
AbstractPollingIoProcessor(Executor executor) |
Create an
AbstractPollingIoProcessor with the given
Executor for handling I/Os events. |
Modifier and Type | Method | Description |
---|---|---|
void |
add(S 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<S> |
allSessions() |
|
protected abstract void |
destroy(S session) |
Destroy the underlying client socket handle
|
void |
dispose() |
Releases any resources allocated by this processor.
|
protected abstract void |
doDispose() |
Dispose the resources used by this
IoProcessor for polling the
client connections. |
void |
flush(S session) |
Flushes the internal write request queue of the specified
session . |
protected abstract SessionState |
getState(S session) |
Get the state of a session (One of OPENING, OPEN, CLOSING)
|
protected abstract void |
init(S session) |
Initialize the polling of a session.
|
protected abstract boolean |
isBrokenConnection() |
Check that the select() has not exited immediately just because of a
broken connection.
|
boolean |
isDisposed() |
|
boolean |
isDisposing() |
|
protected abstract boolean |
isInterestedInRead(S session) |
Tells if this session is registered for reading
|
protected abstract boolean |
isInterestedInWrite(S session) |
Tells if this session is registered for writing
|
protected abstract boolean |
isReadable(S session) |
Tells if 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(S session) |
Tells if the session ready for writing
|
protected abstract int |
read(S session,
IoBuffer buf) |
|
protected abstract 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, registring all the sockets
on it.
|
void |
remove(S 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<S> |
selectedSessions() |
|
protected abstract void |
setInterestedInRead(S session,
boolean isInterested) |
Set the session to be informed when a read event should be processed
|
protected abstract void |
setInterestedInWrite(S session,
boolean isInterested) |
Set the session to be informed when a write event should be processed
|
protected abstract int |
transferFile(S 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(S session) |
Controls the traffic of the specified
session depending of the
IoSession.isReadSuspended() and IoSession.isWriteSuspended()
flags |
void |
updateTrafficMask(S session) |
Updates the traffic mask for a given session
|
protected abstract void |
wakeup() |
Interrupt the
select(long) call. |
protected abstract int |
write(S 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. |
void |
write(S session,
WriteRequest writeRequest) |
Writes the WriteRequest for the specified
session . |
protected AtomicBoolean wakeupCalled
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()
isDisposing
in interface IoProcessor<S extends AbstractIoSession>
IoProcessor.dispose()
method has
been called. Please note that this method will return true
even after all the related resources are released.public final boolean isDisposed()
isDisposed
in interface IoProcessor<S extends AbstractIoSession>
public final void dispose()
dispose
in interface IoProcessor<S extends AbstractIoSession>
protected abstract void doDispose() throws Exception
IoProcessor
for polling the
client connections. The implementing class doDispose method will be
called.Exception
- 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 emptyIoProcessor
protected abstract void wakeup()
select(long)
call.protected abstract SessionState getState(S session)
session
- the IoSession
to inspectprotected abstract boolean isWritable(S session)
session
- the queried sessionprotected abstract boolean isReadable(S session)
session
- the queried sessionprotected abstract void setInterestedInWrite(S session, boolean isInterested) throws Exception
session
- the session for which we want to be interested in write eventsisInterested
- true for registering, false for removingException
- If there was a problem while registering the sessionprotected abstract void setInterestedInRead(S session, boolean isInterested) throws Exception
session
- the session for which we want to be interested in read eventsisInterested
- true for registering, false for removingException
- If there was a problem while registering the sessionprotected abstract boolean isInterestedInRead(S session)
session
- the queried sessionprotected abstract boolean isInterestedInWrite(S session)
session
- the queried sessionprotected abstract void init(S session) throws Exception
protected abstract void destroy(S session) throws Exception
protected abstract int read(S 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(S session, IoBuffer buf, int length) throws IOException
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 bufferIOException
- any exception thrown by the underlying system callsprotected abstract int transferFile(S 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(S 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<S extends AbstractIoSession>
session
- The added sessionpublic final void remove(S 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<S extends AbstractIoSession>
session
- The session to be removedpublic void write(S session, WriteRequest writeRequest)
session
.write
in interface IoProcessor<S extends AbstractIoSession>
session
- The session we want the message to be writtenwriteRequest
- the WriteRequest to writepublic final void flush(S session)
session
.flush
in interface IoProcessor<S extends AbstractIoSession>
session
- The session we want the message to be writtenpublic final void updateTrafficMask(S session)
session
- the session to updateprotected abstract void registerNewSelector() throws IOException
IOException
- If we got an exceptionprotected abstract boolean isBrokenConnection() throws IOException
IOException
- If we got an exceptionpublic void updateTrafficControl(S session)
session
depending of the
IoSession.isReadSuspended()
and IoSession.isWriteSuspended()
flagsupdateTrafficControl
in interface IoProcessor<S extends AbstractIoSession>
session
- The session to be updatedCopyright © 2004–2018 Apache MINA Project. All rights reserved.