com.virtuosotechnologies.lib.asyncjob
Class AbstractAsyncJobRunner.ExecutionImpl

java.lang.Object
  extended bycom.virtuosotechnologies.lib.asyncjob.AbstractAsyncJobRunner.ExecutionImpl
All Implemented Interfaces:
AsyncJobExecution
Enclosing class:
AbstractAsyncJobRunner

protected class AbstractAsyncJobRunner.ExecutionImpl
extends Object
implements AsyncJobExecution

Basic execution tracker implementation. Subclasses can implement startJob() by creating an instance of this class, and then calling runJobSynchronously() in an appropriate thread context. This class is fully synchronized and thread safe.


Constructor Summary
protected AbstractAsyncJobRunner.ExecutionImpl(AsyncJob job)
          Subclass-visible constructor.
 
Method Summary
 void addAsyncJobListener(AsyncJobListener listener)
          Add an execution listener.
 AsyncJob getAsyncJob()
          Get the job being run
 AsyncJobRunner getAsyncJobRunner()
          Get the runner running this job
 AsyncJobException getException()
          Get the job failure exception.
 Object getResult()
          Get the job result value.
 boolean isFinished()
          Has the job finished yet?
 boolean isStarted()
          Has the job started yet?
 void removeAsyncJobListener(AsyncJobListener listener)
          Remove an execution listener.
 void runJobSynchronously()
          Run a job synchronously in the current thread.
 boolean waitForCompletion()
          Wait until the job is finished.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractAsyncJobRunner.ExecutionImpl

protected AbstractAsyncJobRunner.ExecutionImpl(AsyncJob job)
Subclass-visible constructor.

Parameters:
job - the AsyncJob that will be run
Method Detail

getAsyncJobRunner

public AsyncJobRunner getAsyncJobRunner()
Get the runner running this job

Specified by:
getAsyncJobRunner in interface AsyncJobExecution
Returns:
the AsyncJobRunner

getAsyncJob

public AsyncJob getAsyncJob()
Get the job being run

Specified by:
getAsyncJob in interface AsyncJobExecution
Returns:
the AsyncJob

waitForCompletion

public boolean waitForCompletion()
                          throws InterruptedException
Wait until the job is finished.

Specified by:
waitForCompletion in interface AsyncJobExecution
Returns:
true if the job succeeded, false if it failed
Throws:
InterruptedException

isStarted

public boolean isStarted()
Has the job started yet?

Specified by:
isStarted in interface AsyncJobExecution
Returns:
true if the job has started

isFinished

public boolean isFinished()
Has the job finished yet?

Specified by:
isFinished in interface AsyncJobExecution
Returns:
true if the job has finished

getResult

public Object getResult()
Get the job result value.

Specified by:
getResult in interface AsyncJobExecution
Returns:
the result value (which may be null) or null if the job is not finished or failed.

getException

public AsyncJobException getException()
Get the job failure exception.

Specified by:
getException in interface AsyncJobExecution
Returns:
the exception with which the job failed, or null if the job is not finished or did not fail.

addAsyncJobListener

public void addAsyncJobListener(AsyncJobListener listener)
Add an execution listener.

Specified by:
addAsyncJobListener in interface AsyncJobExecution
Parameters:
listener - listener to add

removeAsyncJobListener

public void removeAsyncJobListener(AsyncJobListener listener)
Remove an execution listener.

Specified by:
removeAsyncJobListener in interface AsyncJobExecution
Parameters:
listener - listener to remove

runJobSynchronously

public void runJobSynchronously()
Run a job synchronously in the current thread. Performs all event broadcasting. Subclasses of AbstractAsyncJobRunner may use this method as a helper in their implementations of startJob().