|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.sgs.impl.nio.Reactor
class Reactor
Reactive implementation of the Reactor pattern; an asynchronous IO
dispatcher. When an asynchronous IO operation is initiated, the reactor
enables interest in that operation with a Selector, returning
a future that will be completed when the operation becomes ready and the
IO is performed.
The actual behavior of completing the IO operation is provided by the asynchronous channel implementations; the reactor merely signals readiness and invokes the completion handler for the operation as the operations complete or are canceled.
| Nested Class Summary | |
|---|---|
(package private) static class |
Reactor.AsyncOp<R>
A FutureTask that can be canceled by a timeout exception. |
(package private) class |
Reactor.PendingOperation
Manages a single asynchronous IO operation for a Reactor.ReactiveAsyncKey. |
(package private) class |
Reactor.ReactiveAsyncKey
Provides support for initiating asynchronous IO operations on an underlying reactive channel registered with this Reactor. |
| Field Summary | |
|---|---|
protected static int |
DONE
State: terminated |
(package private) Executor |
executor
The executor for this Reactor. |
(package private) ReactiveChannelGroup |
group
The channel group for this reactor, used to obtain completion handler runners. |
protected int |
lifecycleState
The lifecycle state of this reactor. |
(package private) static Logger |
log
The logger for this class. |
protected static int |
RUNNING
State: open and running |
(package private) Selector |
selector
The Selector that waits for available IO operations on
registered channels. |
(package private) Object |
selectorLock
Selector guard. |
protected static int |
SHUTDOWN
State: graceful shutdown in progress |
protected static int |
SHUTDOWN_NOW
State: forced shutdown in progress |
(package private) DelayQueue<com.sun.sgs.impl.nio.Reactor.TimeoutHandler> |
timeouts
Operations that having pending timeouts. |
| Constructor Summary | |
|---|---|
Reactor(ReactiveChannelGroup group,
Executor executor)
Creates a new reactor instance with the given channel group and executor. |
|
| Method Summary | ||
|---|---|---|
(package private)
|
awaitReady(Reactor.ReactiveAsyncKey asyncKey,
int op,
Reactor.AsyncOp<R> task)
Registers interest in an IO operation on the channel associated with the given AsyncKey, returning a future representing the
result of the operation. |
|
(package private) boolean |
performWork()
Performs a single iteration of the reactor's event loop, and returns a flag indicating whether the reactor is still running. |
|
(package private) Reactor.ReactiveAsyncKey |
register(SelectableChannel ch)
Registers the given SelectableChannel with this reactor,
returning an AsyncKey that can be used to initiate asynchronous
operations on that channel. |
|
(package private) void |
shutdown()
Notifies this reactor that it should shutdown when it has no registered channels. |
|
(package private) void |
shutdownNow()
Notifies this reactor that it should shutdown immediately, closing any open channels registered with it. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
static final Logger log
final Object selectorLock
select() again until the code that awakened
it has released this guard.
The selector must obtain this lock and release it
before blocking on select().
If both the selectorLock and AsyncKey need to be
locked, the selectorLock must be locked first.
protected int lifecycleState
protected static final int RUNNING
protected static final int SHUTDOWN
protected static final int SHUTDOWN_NOW
protected static final int DONE
final ReactiveChannelGroup group
final Selector selector
Selector that waits for available IO operations on
registered channels.
final Executor executor
Reactor. Typically an executor is
shared by all reactors in a group, but each reactor may have its
own logical executor.
final DelayQueue<com.sun.sgs.impl.nio.Reactor.TimeoutHandler> timeouts
| Constructor Detail |
|---|
Reactor(ReactiveChannelGroup group,
Executor executor)
throws IOException
group - the channel group for this reactorexecutor - the executor for tasks in this reactor
IOException - if an I/O error occurs, e.g. while opening
the Selector for this reactor| Method Detail |
|---|
void shutdown()
AsynchronousChannelGroup.shutdown()
void shutdownNow()
throws IOException
IOException - if an I/O error occursAsynchronousChannelGroup.shutdownNow()
boolean performWork()
throws IOException
false if this reactor is stopped,
otherwise true
IOException - if an I/O error occurs
Reactor.ReactiveAsyncKey register(SelectableChannel ch)
throws IOException
SelectableChannel with this reactor,
returning an AsyncKey that can be used to initiate asynchronous
operations on that channel.
ch - the SelectableChannel to register
AsyncKey for the given channel
ShutdownChannelGroupException - if the reactor is shutdown
IOException - if an IO error occurs
<R> void awaitReady(Reactor.ReactiveAsyncKey asyncKey,
int op,
Reactor.AsyncOp<R> task)
AsyncKey, returning a future representing the
result of the operation.
When the requested operation becomes ready, the given task
is invoked so that it may perform the IO operation. The selector's
interest in all ready operations is cleared before dispatching to the
task.
Several checks are performed on the channel at this point to avoid
race conditions where the check succeeds but the condition
immediately becomes false. We lock both the selectorLock and
the asyncKey to ensure that we get a proper view of the state
when registering the operation, and so that if the state later
changes the operation will be terminated properly.
If the channel is closed, ClosedAsynchronousChannelException
is thrown.
Additional checks are performed on SocketChannels:
OP_READ or OP_WRITE
and the channel is not connected, NotYetConnectedException
is thrown.
OP_CONNECT and the channel is
already connected, AlreadyConnectedException is thrown.
R - the result typeasyncKey - the key for async operations on the channelop - the SelectionKey operation requestedtask - the task to invoke when the operation becomes ready
ClosedAsynchronousChannelException - if the channel is closed
NotYetConnectedException - if a read or write operation is
requested on an unconnected SocketChannel
AlreadyConnectedException - if a connect operation is requested
on a connected SocketChannel
|
RedDwarf, Version 0.10.1 2010-03-14 10:56:12 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||