com.virtuosotechnologies.lib.asyncjob
Class AbstractAsyncJob

java.lang.Object
  extended bycom.virtuosotechnologies.lib.asyncjob.AbstractAsyncJob
All Implemented Interfaces:
AsyncJob

public abstract class AbstractAsyncJob
extends Object
implements AsyncJob

Abstract base implementation of AsyncJob. This provides a simple ModifiablePropertySet for manipulating the properties, and includes a basic interrupt() method indicating that the task cannot be interrupted. Subclasses must implement the run() method.


Field Summary
 
Fields inherited from interface com.virtuosotechnologies.lib.asyncjob.AsyncJob
CAN_CANCEL_PROPERTY, COMPLETED_PROGRESS_STRING_PROPERTY, FAILED_PROGRESS_STRING_PROPERTY, INDETERMINATE_PROGRESS, INITIAL_FRACTION_DONE_PROPERTY, INITIAL_PROGRESS_STRING_PROPERTY, JOB_NAME_PROPERTY, PRESTART_PROGRESS_STRING_PROPERTY
 
Constructor Summary
protected AbstractAsyncJob()
          Constructor.
protected AbstractAsyncJob(PropertySet defaultProperties)
          Constructor.
protected AbstractAsyncJob(String jobName, boolean canCancel)
          Constructor.
protected AbstractAsyncJob(String jobName, boolean canCancel, float initialFractionDone)
          Constructor.
protected AbstractAsyncJob(String jobName, boolean canCancel, float initialFractionDone, String initialProgressString)
          Constructor.
protected AbstractAsyncJob(String jobName, boolean canCancel, float initialFractionDone, String initialProgressString, String preStartProgressString, String completedProgressString, String failedProgressString)
          Constructor.
 
Method Summary
protected  ModifiablePropertySet getModifiableProperties()
          Get a modifiable view of the properties for this AsyncJob.
 PropertySet getProperties()
          Get the properties for this AsyncJob
 boolean interrupt(AsyncJobException exception)
          Interrupt the job if it is currently running.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.virtuosotechnologies.lib.asyncjob.AsyncJob
run
 

Constructor Detail

AbstractAsyncJob

protected AbstractAsyncJob(PropertySet defaultProperties)
Constructor. This is the easiest constructor to use if you have an existing PropertySet to use as the job's properties.

Parameters:
defaultProperties - a PropertySet to use as the default properties for the BasicModifiablePropertySet used for the job's properties.

AbstractAsyncJob

protected AbstractAsyncJob(String jobName,
                           boolean canCancel,
                           float initialFractionDone,
                           String initialProgressString,
                           String preStartProgressString,
                           String completedProgressString,
                           String failedProgressString)
Constructor. Allows you to specify several specific well-known properties.

Parameters:
jobName - user-visible name for this job.
canCancel - true if this job can be canceled.
initialFractionDone - initial value for the fraction done in the progress report
initialProgressString - initial value for the user-visible string in the progress report.
preStartProgressString - the user-visible progress string for the pre-start state.
completedProgressString - the user-visible progress string for the completed state.
failedProgressString - the user-visible progress string for the failed state.

AbstractAsyncJob

protected AbstractAsyncJob(String jobName,
                           boolean canCancel,
                           float initialFractionDone,
                           String initialProgressString)
Constructor. Allows you to specify several specific well-known properties.

Parameters:
jobName - user-visible name for this job.
canCancel - true if this job can be canceled.
initialFractionDone - initial value for the fraction done in the progress report
initialProgressString - initial value for the user-visible string in the progress report.

AbstractAsyncJob

protected AbstractAsyncJob(String jobName,
                           boolean canCancel,
                           float initialFractionDone)
Constructor. Allows you to specify several specific well-known properties.

Parameters:
jobName - user-visible name for this job.
canCancel - true if this job can be canceled.
initialFractionDone - initial value for the fraction done in the progress report

AbstractAsyncJob

protected AbstractAsyncJob(String jobName,
                           boolean canCancel)
Constructor. Allows you to specify several specific well-known properties.

Parameters:
jobName - user-visible name for this job.
canCancel - true if this job can be canceled.

AbstractAsyncJob

protected AbstractAsyncJob()
Constructor. Uses default values for all properties.

Method Detail

getProperties

public PropertySet getProperties()
Get the properties for this AsyncJob

Specified by:
getProperties in interface AsyncJob
Returns:
a PropertySet containing the properties

getModifiableProperties

protected ModifiablePropertySet getModifiableProperties()
Get a modifiable view of the properties for this AsyncJob. This is protected because it should only be used by subclasses to update the properties prior to the job being started. The properties for the job generally should not be modified by any other entity.

Returns:
a ModifiablePropertySet containing the properties

interrupt

public boolean interrupt(AsyncJobException exception)
Interrupt the job if it is currently running. The implementation should respond by throwing the given AsyncJobException out of run. If no custom exception is specified, the job should throw a new AsyncJobInterruptedException.

This default implementation returns false to indicate that the job cannot be interrupted.

Specified by:
interrupt in interface AsyncJob
Parameters:
exception - custom exception to throw
Returns:
true if the job was interrupted. Return false if the job was not running or cannot be interrupted.