public class Multiplexer extends Object implements RunnableWhichThrows<IOException>, Stoppable
Selector that also manages timers and multiple threads.| Modifier and Type | Class and Description |
|---|---|
static interface |
Multiplexer.TimerKey
An identifier for a created timer.
|
| Constructor and Description |
|---|
Multiplexer() |
| Modifier and Type | Method and Description |
|---|---|
SelectionKey |
register(SelectableChannel sc,
int ops,
RunnableWhichThrows<IOException> runnable)
Executes the given runnable exactly once iff the channel becomes
acceptable,
connected, readable and/or writable. |
void |
run()
Handles channels and timers; returns never.
|
void |
stop()
|
Multiplexer.TimerKey |
timer(long expiry,
Runnable runnable)
Registers the given runnable for exactly one execution by this
Multiplexer's run() method
when the current time is equal to (or slightly greater than) expiry. |
public Multiplexer()
throws IOException
IOExceptionpublic void run()
throws IOException
stop() was called.run in interface RunnableWhichThrows<IOException>IOExceptionpublic SelectionKey register(SelectableChannel sc, int ops, RunnableWhichThrows<IOException> runnable) throws ClosedChannelException
acceptable,
connected, readable and/or writable.
To cancel the reigstration, invoke SelectionKey.cancel() on the returned object.
ClosedChannelExceptionpublic Multiplexer.TimerKey timer(long expiry, Runnable runnable)
Multiplexer's run() method
when the current time is equal to (or slightly greater than) expiry.
Registering the same runnable more than once (and even with equal expiry) will lead to the runnable being run that many times.
Registering a runnable for an expiry that lies in the past will lead to the runnable being executed by
this Multiplexer's run() method very soon.
Invoking the Multiplexer.TimerKey.cancel() method on the returned object prevents the runnable from being
executed (iff its execution has not yet begun).
Copyright © 2018 Arno Unkrig. All rights reserved.