|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.lang.Thread frysk.event.EventLoop
public abstract class EventLoop
Implements an event loop.
Nested Class Summary | |
---|---|
private class |
EventLoop.ExecuteRequest
|
private class |
EventLoop.Running
Run the event-loop. |
Nested classes/interfaces inherited from class java.lang.Thread |
---|
Thread.State, Thread.UncaughtExceptionHandler |
Field Summary | |
---|---|
private static Log |
fine
|
private Exception |
firstSet
|
private boolean |
isGoingToBlock
The event loop will enter a blocking poll. |
private List |
pendingEvents
Maintain a FIFO of events that are ready to be processed. |
private EventLoop.ExecuteRequest |
request
|
private EventLoop.Running |
running
|
private Map |
signalHandlers
Collection of signals; assume that very few signals are being watched and hence that a small map is sufficient. |
private boolean |
stop
|
private ProcessIdentifier |
tid
The EventLoop's thread ID. |
private SortedMap |
timerEvents
List of timer events. |
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
---|---|
protected |
EventLoop()
The EventLoop uses Signal.IO to wake up, or unblock, the event-loop thread when a request comes in. |
Method Summary | |
---|---|
void |
add(Event e)
Add the event to the end of the queue of events that need to be processed. |
void |
add(SignalEvent signalEvent)
Add the signal handler, signals are processed and then delivered using the event-loop. |
void |
add(TimerEvent t)
Add a timer event that will expire at some stage in the future. |
abstract void |
add(WaitBuilder waitBuilder)
Add support for the notification of waitpid events. |
protected abstract void |
block(long millisecondTimeout)
Block for up-to TIMEOUT, or until an event arrives, or possibly no-reason. |
private void |
checkForTimerEvents()
Move any expired timer events onto the event queue. |
void |
execute(Event e)
Execute the event on the event-loop thread; return when completed. |
static EventLoop |
factory()
Return the current prefered flavour of the event-loop. |
private long |
getTimerEventMillisecondTimeout()
Return the number of milliseconds until the next timer, or -1 if there is no pending timer (-1 implies an infinite timeout). |
(package private) boolean |
isCurrentThread()
|
protected void |
processSignal(Signal sig)
Process the signal. |
private Event |
remove()
Remove and return the first pending event, or null if there are no pending event. |
void |
remove(Event e)
Remove the pending event. |
void |
remove(SignalEvent signalEvent)
Remove the signal event handler, further occurances of the signal are discarded. |
void |
remove(TimerEvent t)
Remove the timer event from the event queue. |
void |
requestStop()
Request that the event-loop stop. |
void |
run()
|
private void |
runEventLoop(boolean pendingOnly)
Run the event-loop. |
void |
runPending()
Run the event loop until there are no pending events. |
boolean |
runPolling(long timeout)
Run the full event loop (checking for both synchronous and asynchronous events) for at most TIMEOUT milliseconds. |
protected abstract void |
signalAdd(Signal sig)
Add Signal to the signals that can be received. |
protected abstract void |
signalEmpty()
Clear the signal set being used by the event-loop. |
void |
start()
Start the EventLoop thread; note that this forces a brief synchronization with that thread to ensure that it is ready. |
private void |
updateTid()
|
private void |
wakeupBlockedEventLoop()
|
private void |
wakeupIfBlocked()
If the event loop is blocking, wake it up. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final Log fine
private ProcessIdentifier tid
private Exception firstSet
private volatile boolean isGoingToBlock
private SortedMap timerEvents
private Map signalHandlers
private List pendingEvents
private final EventLoop.ExecuteRequest request
private volatile boolean stop
private EventLoop.Running running
Constructor Detail |
---|
protected EventLoop()
Method Detail |
---|
protected abstract void signalEmpty()
protected abstract void signalAdd(Signal sig)
public abstract void add(WaitBuilder waitBuilder)
protected abstract void block(long millisecondTimeout)
final boolean isCurrentThread()
private void wakeupBlockedEventLoop()
private void updateTid()
private void wakeupIfBlocked()
remove()
for where this flag is set.
public void add(TimerEvent t)
TimerEvent.getTimeMillis
.
public void remove(TimerEvent t)
private long getTimerEventMillisecondTimeout()
private void checkForTimerEvents()
public void add(SignalEvent signalEvent)
public void remove(SignalEvent signalEvent)
protected void processSignal(Signal sig)
public void add(Event e)
public void remove(Event e)
public void execute(Event e)
private Event remove()
private void runEventLoop(boolean pendingOnly)
public void requestStop()
public final void runPending()
public final boolean runPolling(long timeout)
public final void run()
run
in interface Runnable
run
in class Thread
public void start()
start
in class Thread
public static EventLoop factory()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |