org.ijsberg.iglu.util.execution
Class Executable

java.lang.Object
  extended by org.ijsberg.iglu.util.execution.Executable
All Implemented Interfaces:
Runnable

public abstract class Executable
extends Object
implements Runnable

Subclasses implement a piece of code that should be executed in a special way, such as:

Executables are (usually) stateful and should be instantiated for each and every call. It's convenient to define executables as anonymous inner classes. E.g.: new Executable(){protected Object execute(){System.out.println("this message is printed asynchronously");return null;}}.executeAsync();


Constructor Summary
Executable()
           
 
Method Summary
protected abstract  Object execute()
          Implements code to be executed.
 void executeAsync()
          Executes asynchronously.
 void executeAsyncDelayed(long delay)
          Executes after delay ms.
 void executeAsyncTimed(long timeout)
          Executes asynchronously.
 Object executeDelayed(long delay)
           
 Object executeTimed(long timeout)
          Executes synchronously.
 Throwable getExecutionException()
           
 Thread getExecutionThread()
           
 Object getReturnValue()
           
 void interrupt()
          Tries to interrupt execution.
 boolean isFinished()
           
 void run()
          Used to invoke executable asynchronously.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Executable

public Executable()
Method Detail

run

public void run()
Used to invoke executable asynchronously.

Specified by:
run in interface Runnable

executeAsync

public void executeAsync()
Executes asynchronously.


executeAsyncTimed

public void executeAsyncTimed(long timeout)
Executes asynchronously. After timeout ms the abort method is invoked if the executable has not finished processing

Parameters:
timeout - timeout value in milliseconds

executeAsyncDelayed

public void executeAsyncDelayed(long delay)
Executes after delay ms.

Parameters:
delay -

executeTimed

public Object executeTimed(long timeout)
                    throws TimeOutException,
                           InterruptedException,
                           Throwable
Executes synchronously. After timeout ms the abort method is invoked if the executable has not finished processing.

Parameters:
timeout - timeout value in milliseconds
Returns:
Throws:
TimeOutException - in case the call is timed out
InterruptedException - if execution was interrupted before timeout
Throwable - in case the executable throws

executeDelayed

public Object executeDelayed(long delay)
                      throws TimeOutException,
                             Throwable
Parameters:
delay -
Returns:
Throws:
TimeOutException
Throwable

execute

protected abstract Object execute()
                           throws Throwable
Implements code to be executed.

Returns:
Throws:
Throwable

interrupt

public void interrupt()
Tries to interrupt execution. Execution code is interrupted if it sleeps once in a while.


getExecutionException

public Throwable getExecutionException()
Returns:
the (runtime) exception that may have occurred during execution

isFinished

public boolean isFinished()
Returns:
true if execution has been finished (un)successfully

getExecutionThread

public Thread getExecutionThread()
Returns:

getReturnValue

public Object getReturnValue()
Returns:


Copyright © 2011. All Rights Reserved.