|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.mina.core.polling.AbstractPollingIoProcessor<S>
S - the type of the IoSession this processor can handlepublic abstract class AbstractPollingIoProcessor<S extends AbstractIoSession>
An abstract implementation of 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.
| Field Summary | |
|---|---|
protected java.util.concurrent.atomic.AtomicBoolean |
wakeupCalled
|
| Constructor Summary | |
|---|---|
protected |
AbstractPollingIoProcessor(java.util.concurrent.Executor executor)
Create an AbstractPollingIoProcessor with the given
Executor for handling I/Os events. |
| Method Summary | |
|---|---|
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 java.util.Iterator<S> |
allSessions()
Get an Iterator for the list of IoSession polled by this
IoProcessor |
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 (preparing, open, closed) |
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()
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(S session)
is this session registered for reading |
protected abstract boolean |
isInterestedInWrite(S session)
is this session registered for writing |
protected abstract boolean |
isReadable(S 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(S session)
Is the session ready for writing |
protected abstract int |
read(S session,
IoBuffer buf)
Reads a sequence of bytes from a IoSession into the given
IoBuffer. |
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 java.util.Iterator<S> |
selectedSessions()
Get an Iterator for the list of IoSession found selected
by the last call of {@link AbstractPollingIoProcessor#select(int) |
protected abstract void |
setInterestedInRead(S session,
boolean isInterested)
register a session for reading |
protected abstract void |
setInterestedInWrite(S session,
boolean isInterested)
register a session for writing |
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)
|
protected abstract void |
wakeup()
Interrupt the {@link AbstractPollingIoProcessor#select(int) 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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected java.util.concurrent.atomic.AtomicBoolean wakeupCalled
| Constructor Detail |
|---|
protected AbstractPollingIoProcessor(java.util.concurrent.Executor executor)
AbstractPollingIoProcessor with the given
Executor for handling I/Os events.
executor - the Executor for handling I/O events| Method Detail |
|---|
public 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<S extends AbstractIoSession>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 java.lang.Exception
IoProcessor for polling the
client connections. The implementing class doDispose method will be called.
java.lang.Exception - if some low level IO error occurs
protected abstract int select(long timeout)
throws java.lang.Exception
timeout - milliseconds before the call timeout if no event appear
java.lang.Exception - if some low level IO error occurs
protected abstract int select()
throws java.lang.Exception
java.lang.Exception - if some low level IO error occursprotected abstract boolean isSelectorEmpty()
IoSession polled by this IoProcessor
is empty
IoProcessorprotected abstract void wakeup()
protected abstract java.util.Iterator<S> allSessions()
Iterator for the list of IoSession polled by this
IoProcessor
Iterator of IoSessionprotected abstract java.util.Iterator<S> selectedSessions()
Iterator for the list of IoSession found selected
by the last call of {@link AbstractPollingIoProcessor#select(int)
Iterator of IoSession read for I/Os operationprotected abstract SessionState getState(S session)
session - the IoSession to inspect
protected abstract boolean isWritable(S session)
session - the session queried
protected abstract boolean isReadable(S session)
session - the session queried
protected abstract void setInterestedInWrite(S session,
boolean isInterested)
throws java.lang.Exception
session - the session registeredisInterested - true for registering, false for removing
java.lang.Exception
protected abstract void setInterestedInRead(S session,
boolean isInterested)
throws java.lang.Exception
session - the session registeredisInterested - true for registering, false for removing
java.lang.Exceptionprotected abstract boolean isInterestedInRead(S session)
session - the session queried
protected abstract boolean isInterestedInWrite(S session)
session - the session queried
protected abstract void init(S session)
throws java.lang.Exception
session - the IoSession to add to the polling
java.lang.Exception - any exception thrown by the underlying system calls
protected abstract void destroy(S session)
throws java.lang.Exception
session - the IoSession
java.lang.Exception - any exception thrown by the underlying system calls
protected abstract int read(S session,
IoBuffer buf)
throws java.lang.Exception
IoSession into the given
IoBuffer. Is called when the session was found ready for reading.
session - the session to readbuf - the buffer to fill
java.lang.Exception - any exception thrown by the underlying system calls
protected abstract int write(S session,
IoBuffer buf,
int length)
throws java.lang.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 buffer
java.lang.Exception - any exception thrown by the underlying system calls
protected abstract int transferFile(S session,
FileRegion region,
int length)
throws java.lang.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 send
java.lang.Exception - 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>public 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>public final void flush(S session)
session.
flush in interface IoProcessor<S extends AbstractIoSession>public final void updateTrafficMask(S session)
protected abstract void registerNewSelector()
throws java.io.IOException
java.io.IOException - If we got an exception
protected abstract boolean isBrokenConnection()
throws java.io.IOException
java.io.IOException - If we got an exceptionpublic void updateTrafficControl(S session)
session depending of the
IoSession.isReadSuspended() and IoSession.isWriteSuspended()
flags
updateTrafficControl in interface IoProcessor<S extends AbstractIoSession>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||