Class SelectorKernel.SelectorThread
java.lang.Object
java.lang.Thread
com.jme3.network.kernel.tcp.SelectorKernel.SelectorThread
- All Implemented Interfaces:
Runnable
- Enclosing class:
SelectorKernel
This class is purposely tucked neatly away because
messing with the selector from other threads for any
reason is very bad. This is the safest architecture.
- Author:
- Paul Speed
-
Nested Class Summary
Nested classes/interfaces inherited from class Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaccept(SelectionKey key) Accepts a new incoming TCP connection.protected voidCancels and closes the specified endpoint.protected voidcancel(SelectionKey key, SocketChannel c) Cancels and closes the specified selection key and channel.voidclose()Stops the selector thread and closes its resources.voidconnect()Opens and binds the selector infrastructure.protected voidread(SelectionKey key) Reads pending bytes from a readable channel.voidrun()protected voidselect()Waits for and dispatches selector activity.protected voidRecomputes selector interest ops for endpoints with pending output.protected voidWakes the selector if it is blocked inselect().protected voidwrite(SelectionKey key) Flushes pending endpoint data to a writable channel.Methods inherited from class Thread
activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, threadId, toString, yield
-
Constructor Details
-
SelectorThread
public SelectorThread()Creates the selector thread.
-
-
Method Details
-
connect
Opens and binds the selector infrastructure.- Throws:
IOException- if the selector or socket cannot be opened
-
close
Stops the selector thread and closes its resources.- Throws:
IOException- if socket shutdown failsInterruptedException- if interrupted while waiting for shutdown
-
wakeupSelector
protected void wakeupSelector()Wakes the selector if it is blocked inselect(). -
setupSelectorOptions
protected void setupSelectorOptions()Recomputes selector interest ops for endpoints with pending output. -
accept
Accepts a new incoming TCP connection.- Parameters:
key- the selected accept key- Throws:
IOException- if the connection cannot be accepted or configured
-
cancel
Cancels and closes the specified endpoint.- Parameters:
p- the endpoint to cancel- Throws:
IOException- if closing the channel fails
-
cancel
Cancels and closes the specified selection key and channel.- Parameters:
key- the key to cancelc- the channel to close- Throws:
IOException- if closing the channel fails
-
read
Reads pending bytes from a readable channel.- Parameters:
key- the readable key- Throws:
IOException- if the read fails
-
write
Flushes pending endpoint data to a writable channel.- Parameters:
key- the writable key- Throws:
IOException- if writing fails
-
select
Waits for and dispatches selector activity.- Throws:
IOException- if selector processing fails
-
run
-