public abstract class NioManagerThread extends Thread implements SourceLocal<NioEvent<?>>, Closeable, EnumStatus<NioManagerThread.NioManagerThreadStatus>
NioManager
service threads.Modifier and Type | Class and Description |
---|---|
static class |
NioManagerThread.NioManagerThreadStatus
An enumeration of thread states.
|
static class |
NioManagerThread.Request<I,O>
A subclass of
FutureTask for signaling manager threads and retrieving their internal states. |
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
protected Throwable |
exception
The exception that caused this thread to exit.
|
protected StateTable<NioConnection.NioConnectionStatus,NioEvent.NioEventType,NioEvent<?>> |
fsm
The external state machine.
|
protected StateTable<NioManagerThread.NioManagerThreadStatus,NioEvent.NioEventType,NioEvent<?>> |
fsmInternal
The internal state machine.
|
protected org.slf4j.Logger |
log
The
Logger for debugging messages. |
protected Queue<NioEvent<?>> |
queue
The event queue.
|
protected Set<NioManagerThread.Request<?,?>> |
requests
A weak
Set of NioManagerThread.Request s for cleanup purposes. |
protected Selector |
selector
A
Selector specific to this thread. |
protected NioManagerThread.NioManagerThreadStatus |
status
The current
NioManagerThread.NioManagerThreadStatus . |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Modifier | Constructor and Description |
---|---|
protected |
NioManagerThread(String name)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Stops this thread and waits for it to terminate.
|
protected void |
debug(String format,
Object... args)
Logs a debugging message.
|
protected void |
debug(Throwable exception,
String format,
Object... args)
Logs a debugging exception message.
|
protected abstract void |
doReadyOps(int readyOps,
SelectionKey key)
Performs actions stipulated by a ready operations bit vector on the given
SelectionKey . |
NioManagerThread.NioManagerThreadStatus |
getStatus()
Gets the status.
|
protected void |
handleClose(NioConnection conn)
Handles a connection closure notification.
|
protected void |
handleClosingEos(NioConnection conn)
Handles a connection end-of-stream notification.
|
protected void |
handleClosingUser(NioConnection conn)
Handles a connection close request.
|
protected void |
handleError(NioConnection conn,
Throwable exception)
Handles a connection error notification.
|
protected <V> void |
handleInvoke(NioManagerThread.Request<Callable<V>,V> request)
Handles a request to execute code on this thread.
|
protected void |
handleOp(NioConnection conn,
int mask,
boolean enabled)
Handles a connection operation interest change request.
|
protected void |
handleShutdown()
Handles a request to shut down this thread.
|
protected void |
initFsms()
Initializes the underlying
StateTable s. |
void |
onLocal(NioEvent<?> evt)
Enqueues the given event and wakes this thread up from a possible
Selector.select() . |
protected abstract void |
onStart()
On thread start.
|
protected abstract void |
onStop()
On thread stop.
|
protected abstract void |
purge(NioConnection conn)
A sequence of actions to take when deleting a connection, as far as this thread is concerned.
|
protected <I,O> Future<O> |
request(NioEvent.NioEventType type,
I argument,
NioConnection conn)
Retrieves this thread's internal state.
|
void |
run()
Runs the main operation readiness and event processing loop.
|
void |
setStatus(NioManagerThread.NioManagerThreadStatus status)
Sets the status.
|
String |
toString()
Creates a human-readable representation of this thread that includes the name and status.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
protected final Set<NioManagerThread.Request<?,?>> requests
Set
of NioManagerThread.Request
s for cleanup purposes.protected final org.slf4j.Logger log
Logger
for debugging messages.protected StateTable<NioConnection.NioConnectionStatus,NioEvent.NioEventType,NioEvent<?>> fsm
protected StateTable<NioManagerThread.NioManagerThreadStatus,NioEvent.NioEventType,NioEvent<?>> fsmInternal
protected Throwable exception
protected NioManagerThread.NioManagerThreadStatus status
NioManagerThread.NioManagerThreadStatus
.protected NioManagerThread(String name)
public void onLocal(NioEvent<?> evt)
Selector.select()
.onLocal
in interface SourceLocal<NioEvent<?>>
public String toString()
public NioManagerThread.NioManagerThreadStatus getStatus()
EnumStatus
getStatus
in interface EnumStatus<NioManagerThread.NioManagerThreadStatus>
public void setStatus(NioManagerThread.NioManagerThreadStatus status)
EnumStatus
setStatus
in interface EnumStatus<NioManagerThread.NioManagerThreadStatus>
public void run()
public void close()
close
in interface Closeable
close
in interface AutoCloseable
protected void initFsms()
StateTable
s.protected void debug(Throwable exception, String format, Object... args)
protected <I,O> Future<O> request(NioEvent.NioEventType type, I argument, NioConnection conn)
I
- the input type.O
- the output type.type
- the NioEvent.NioEventType
.argument
- the input argument.conn
- the originating NioConnection
.protected abstract void onStart()
protected abstract void onStop()
protected abstract void doReadyOps(int readyOps, SelectionKey key)
SelectionKey
.protected abstract void purge(NioConnection conn)
protected void handleOp(NioConnection conn, int mask, boolean enabled)
protected void handleClosingUser(NioConnection conn)
protected void handleClosingEos(NioConnection conn)
protected void handleClose(NioConnection conn)
protected void handleError(NioConnection conn, Throwable exception)
protected <V> void handleInvoke(NioManagerThread.Request<Callable<V>,V> request)
V
- the result type.protected void handleShutdown()