public final class EventLoop
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
EventLoop.State
Possible states for a nested event loop object.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.Object |
returnValue |
private static java.util.Deque<EventLoop> |
stack |
private EventLoop.State |
state |
Constructor and Description |
---|
EventLoop() |
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
enter()
Starts a nested event loop.
|
EventLoop.State |
getState()
Gets the current
EventLoop.State of this EventLoop instance. |
void |
leave(java.lang.Object ret)
Requests this nested event loop to terminate.
|
private static final java.util.Deque<EventLoop> stack
private EventLoop.State state
private java.lang.Object returnValue
public EventLoop.State getState()
EventLoop.State
of this EventLoop instance.
This method must only be invoked on the main (event handling)
thread.public java.lang.Object enter()
IDLE
state when calling this
method. Upon entering the nested event loop, the state of the object
changes to ACTIVE
. When the method returns, the EventLoop object
is back to the IDLE
state.
Calling this method temporarily blocks processing of the current event,
and starts a nested event loop to handle other native events. To
proceed with the blocked execution path, the application should call the
leave(Object)
method.
Note that this method must only be invoked on the main (event handling)
thread.
An application may enter several nested loops recursively. Each nested
event loop must be represented by a separate EventLoop instance. There's
no limit of recursion other than that imposed by the native stack size.java.lang.RuntimeException
- if the current thread is not the main threadjava.lang.IllegalStateException
- if the EventLoop object isn't IDLEpublic void leave(java.lang.Object ret)
ACTIVE
state when calling
this method. This method switches the state of the object to LEAVING
.
After calling this method and returning from the current event handler,
the execusion returns to the point where the enter()
method
was called previously. You may specify a return value for the
enter() method by passing the argument retValue
to
the leave().
Calls to enter() and leave() may be interleaved for different event
loops. If the EventLoop object is not innermost (i.e. not most recently
started), calling leave() just switches this EventLoop object to the
LEAVING
state w/o actually terminating it after returning from
the current event handler. The enter() method that started this event
loop only returns after all inner event loops are terminated.
Note that this method must only be invoked on the main (event handling)
thread.java.lang.RuntimeException
- if the current thread is not the main threadjava.lang.IllegalStateException
- if the nested event loop isn't ACTIVE