Package kilim.nio
Class NioSelectorScheduler
- java.lang.Object
-
- kilim.nio.NioSelectorScheduler
-
public class NioSelectorScheduler extends java.lang.ObjectThis class wraps a selector and runs it in a separate thread. It runs one or more ListenTasks (bound to their respective ports), which in turn spawn as many session tasks (seelisten(int, Class, Scheduler)) as the number of new http connections. The supplied scheduler is used to execute the tasks. It is possible, although not typical, to run tasks in the NioSelectorScheduler itself, as it too is a scheduler. Usage is as follows:NioSelectorScheduler nss = new NioSelectorScheduler(); nss.listen(8080, MySessionTask.class, Scheduler.getDefaultScheduler(); class MySessionTask extends SessionTask { ... }- See Also:
SessionTask
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classNioSelectorScheduler.ListenTaskclassNioSelectorScheduler.RegistrationTask(package private) classNioSelectorScheduler.SelectorThreadstatic interfaceNioSelectorScheduler.SessionFactory
-
Field Summary
Fields Modifier and Type Field Description static intLISTEN_BACKLOG(package private) Mailbox<SockEvent>regboxSessionTask registers its endpoint with the selector by sending a SockEvent message on this mailbox.private Taskregtask(package private) booleanrunningprivate java.nio.channels.Selectorselprivate NioSelectorScheduler.SelectorThreadselectorThread(package private) java.util.concurrent.atomic.AtomicBooleanupdate
-
Constructor Summary
Constructors Constructor Description NioSelectorScheduler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intlisten(int port, java.lang.Class<? extends SessionTask> sockTaskClass, Scheduler sockTaskScheduler)intlisten(int port, NioSelectorScheduler.SessionFactory factory, Scheduler sockTaskScheduler)private intlisten(NioSelectorScheduler.ListenTask t, Scheduler sockTaskScheduler)voidshutdown()
-
-
-
Field Detail
-
LISTEN_BACKLOG
public static int LISTEN_BACKLOG
-
sel
private java.nio.channels.Selector sel
-
selectorThread
private NioSelectorScheduler.SelectorThread selectorThread
-
regbox
final Mailbox<SockEvent> regbox
SessionTask registers its endpoint with the selector by sending a SockEvent message on this mailbox.
-
update
java.util.concurrent.atomic.AtomicBoolean update
-
regtask
private final Task regtask
-
running
volatile boolean running
-
-
Method Detail
-
listen
public int listen(int port, NioSelectorScheduler.SessionFactory factory, Scheduler sockTaskScheduler) throws java.io.IOException- Throws:
java.io.IOException
-
listen
public int listen(int port, java.lang.Class<? extends SessionTask> sockTaskClass, Scheduler sockTaskScheduler) throws java.io.IOException- Throws:
java.io.IOException
-
listen
private int listen(NioSelectorScheduler.ListenTask t, Scheduler sockTaskScheduler)
-
shutdown
public void shutdown()
-
-