ch.aplu.util
Class JRunner

java.lang.Object
  extended by ch.aplu.util.JRunner

public class JRunner
extends java.lang.Object

A helper class in order to execute a method in a separate thread and to get a notification callback when the thread terminates. (Simple version of SwingWorker.)


Constructor Summary
JRunner(java.lang.Object exposedObj)
          Create a JRunner instance with given reference to a class instance.
 
Method Summary
 void cancel()
          Continue the halted thread and block until the thread is dead.
 void cancel(long millis)
          Continue the halted thread and wait for the thread to die at most the given time (in ms).
 void join()
          Block until the internal thread dies.
 void join(long millis)
          Wait for the internal thread to die at most the given time (in ms).
 void resume()
          Continue the halted thread.
 void run(java.lang.String methodName)
          Create a thread and invoke the parameterless method with given name.
 boolean waitIfRequested()
          Halt temporarily the execution of the internal thread if it was requested by calling waitRequest() and block until cancel() or resume() is called.
 void waitRequest()
          Set the waitRequest flag.
 void waitRequest(boolean wait)
          Clear or set the waitRequest flag.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JRunner

public JRunner(java.lang.Object exposedObj)
Create a JRunner instance with given reference to a class instance. The class should declare a public method that will be called in a separate thread by invoking run().

Method Detail

run

public void run(java.lang.String methodName)
Create a thread and invoke the parameterless method with given name.
The thread terminates when the given method returns.

The given method must have a void or boolean return type. The boolean return value can be used as follows:

If the given method returns false and the the class declares a method void done(String methodName), done() is called with its corresponding methodName. done() is invoked by the event dispatch thread (EDT), so that Swing methods may be called directly.

If the given method returns true and the the class declares a method void killed(String methodName), killed() is called with its corresponding methodName. killed() is invoked by the event dispatch thread (EDT), so that Swing methods may be called directly.


join

public void join(long millis)
Wait for the internal thread to die at most the given time (in ms).

See Also:
join()

join

public void join()
Block until the internal thread dies.

See Also:
join(long)

waitIfRequested

public boolean waitIfRequested()
Halt temporarily the execution of the internal thread if it was requested by calling waitRequest() and block until cancel() or resume() is called. Return true if cancel() is called. Return false, if resume() is called.

See Also:
waitRequest(), cancel(), resume()

resume

public void resume()
Continue the halted thread. If the thread is not halted, clear any pending waitRequest.

See Also:
waitRequest()

cancel

public void cancel(long millis)
Continue the halted thread and wait for the thread to die at most the given time (in ms). If the thread is not halted, clear any pending waitRequest.

See Also:
cancel(), waitRequest()

cancel

public void cancel()
Continue the halted thread and block until the thread is dead. If the thread is not halted, clear any pending waitRequest.

See Also:
cancel(long), waitRequest()

waitRequest

public void waitRequest()
Set the waitRequest flag. The next time waitIfRequested() is called, the thread will halt. If the thread is already halted, nothing happens.

See Also:
waitIfRequested()

waitRequest

public void waitRequest(boolean wait)
Clear or set the waitRequest flag.

See Also:
waitIfRequested()