QJCC homepage

biz.chitec.quarterback.util
Class AsyncEventThread

java.lang.Object
  extended byjava.lang.Thread
      extended bybiz.chitec.quarterback.util.AsyncEventThread
All Implemented Interfaces:
java.lang.Runnable

public class AsyncEventThread
extends java.lang.Thread

Arbitrary asynchronous thread which handles something in an event-driven way. Modelled after AsyncEventDispatcher, which was developed earlier but static-only. This class works by starting a private subthread. That one is listening at a ThreadInterface. It receives AsyncEvents which contain either an AsyncEventHandler or a Runnable. That ones handling method (either AsyncEventHandler.handleAsyncEvent() or Runnable.run()) is executed in the asynchronous thread. Note: You have to call start() after instantiating AsyncEventThread. Otherwise, nothing will be executed. Call close() to finish operation. Tasks will be executed before operation stops, anyway.

Version:
$Id: 8d05346c43cd9c040227eb2edd3fdf0ef96d7510 $
Author:
cantamen/Dirk Hillbrecht 2005. Distributed under the terms of the GNU LGPL.
See Also:
AsyncEvent, AsyncEventHandler

Field Summary
private  ThreadInterface ti
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AsyncEventThread()
           
 
Method Summary
 void close()
           
 void invokeIfSleeping(AsyncEventHandler target)
           
 void invokeIfSleeping(java.util.EventObject e, AsyncEventHandler target)
           
 void invokeIfSleeping(java.lang.Runnable target)
           
 void invokeIfSleeping(java.lang.Runnable target, java.lang.Runnable alternative)
          Calls target in async thread if that one is free or alternative in current thread.
 void invokeLater(AsyncEventHandler target)
           
 void invokeLater(java.util.EventObject e, AsyncEventHandler target)
           
 void invokeLater(java.lang.Runnable target)
           
 boolean isIdle()
           
 boolean isMyThread()
          Returns true if running in the asynchronous dispatching thread handled by this class.
 void run()
          The asynchronous event handler
 void sendEvent(AsyncEvent ae)
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ti

private ThreadInterface ti
Constructor Detail

AsyncEventThread

public AsyncEventThread()
Method Detail

close

public void close()

isMyThread

public boolean isMyThread()
Returns true if running in the asynchronous dispatching thread handled by this class. Use this call to ensure that a given task is (not) being executed on the asynchronous dispatching thread.

Returns:
true if running on the asynchronous dispatching thread

isIdle

public boolean isIdle()

sendEvent

public void sendEvent(AsyncEvent ae)

invokeLater

public void invokeLater(AsyncEventHandler target)

invokeLater

public void invokeLater(java.util.EventObject e,
                        AsyncEventHandler target)

invokeIfSleeping

public void invokeIfSleeping(AsyncEventHandler target)

invokeIfSleeping

public void invokeIfSleeping(java.util.EventObject e,
                             AsyncEventHandler target)

invokeLater

public void invokeLater(java.lang.Runnable target)

invokeIfSleeping

public void invokeIfSleeping(java.lang.Runnable target)

invokeIfSleeping

public void invokeIfSleeping(java.lang.Runnable target,
                             java.lang.Runnable alternative)
Calls target in async thread if that one is free or alternative in current thread. target is executed in asynchronous thread, but only if asynchronous thread is currently idleing. Otherwise (asynchronous thread is currently executing another Runnable), alternative is executed in current thread and target is not executed at all.


run

public void run()
The asynchronous event handler


QJCC homepage