org.oddjob.framework
Class SimpleJob

java.lang.Object
  extended by org.oddjob.framework.BaseComponent
      extended by org.oddjob.framework.BasePrimary
          extended by org.oddjob.framework.SimpleJob
All Implemented Interfaces:
Runnable, ArooaContextAware, ArooaSessionAware, Forceable, PropertyChangeNotifier, Iconic, LogEnabled, Resetable, Stateful
Direct Known Subclasses:
ArchiveBrowserJob, DependsJob, ResetJob, RMIRegistryJob, SerializableJob, ServicesJob, SetJob, VariablesJob, WaitJob

public abstract class SimpleJob
extends BasePrimary
implements Runnable, Resetable, Stateful, Forceable

An abstract implementation of a job which provides common functionality to concrete sub classes.

Author:
Rob Gordon

Field Summary
protected  JobStateHandler stateHandler
           
protected  boolean stop
          This flag is set by the stop method and should be examined by any Stoppable sub classes in their processing loop.
 
Fields inherited from class org.oddjob.framework.BaseComponent
iconHelper
 
Constructor Summary
protected SimpleJob()
           
 
Method Summary
protected abstract  int execute()
          Execute this job.
protected  void fireDestroyedState()
          Internal method to fire state.
 void force()
          Force the job to COMPLETE.
protected  StateChanger<JobState> getStateChanger()
           
 boolean hardReset()
          Perform a hard reset on the job.
protected  void onDestroy()
          Subclasses override this method to clear up resources.
protected  void onReset()
          Allow sub classes to do something on reset.
protected  void onStop()
          Allow sub classes to do something on stop.
 void run()
          Implement the main execute method for a job.
protected  void sleep(long waitTime)
          Utility method to sleep a certain time.
 boolean softReset()
          Perform a soft reset on the job.
protected  JobStateHandler stateHandler()
           
 void stop()
          Allow subclasses to indicate they are stopping.
 
Methods inherited from class org.oddjob.framework.BasePrimary
configure, getName, logger, logger, loggerName, save, setName, toString
 
Methods inherited from class org.oddjob.framework.BaseComponent
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, onInitialised, removeIconListener, removePropertyChangeListener, removeStateListener, save, setArooaContext, setArooaSession
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.oddjob.Stateful
addStateListener, lastStateEvent, removeStateListener
 

Field Detail

stateHandler

protected transient JobStateHandler stateHandler

stop

protected transient volatile boolean stop
This flag is set by the stop method and should be examined by any Stoppable sub classes in their processing loop.

Constructor Detail

SimpleJob

protected SimpleJob()
Method Detail

stateHandler

protected JobStateHandler stateHandler()
Specified by:
stateHandler in class BaseComponent

getStateChanger

protected StateChanger<JobState> getStateChanger()

execute

protected abstract int execute()
                        throws Throwable
Execute this job.

Returns:
0 if the job is complete, anything else otherwise.
Throws:
Exception - If the unexpected occurs.
Throwable

run

public final void run()
Implement the main execute method for a job. This surrounds the doExecute method of the sub class and sets state for the job.

Specified by:
run in interface Runnable

sleep

protected void sleep(long waitTime)
Utility method to sleep a certain time.

Parameters:
waitTime - Milliseconds to sleep for.

stop

public final void stop()
                throws FailedToStopException
Allow subclasses to indicate they are stopping. The subclass must still implement Stoppable.

Throws:
FailedToStopException

onStop

protected void onStop()
               throws FailedToStopException
Allow sub classes to do something on stop.

Throws:
FailedToStopException

softReset

public boolean softReset()
Perform a soft reset on the job.

Specified by:
softReset in interface Resetable
Returns:
true if successful.

hardReset

public boolean hardReset()
Perform a hard reset on the job.

Specified by:
hardReset in interface Resetable
Returns:
true if successful.

onReset

protected void onReset()
Allow sub classes to do something on reset.


force

public void force()
Force the job to COMPLETE.

Specified by:
force in interface Forceable

onDestroy

protected void onDestroy()
Description copied from class: BaseComponent
Subclasses override this method to clear up resources.

Overrides:
onDestroy in class BaseComponent

fireDestroyedState

protected void fireDestroyedState()
Internal method to fire state.

Specified by:
fireDestroyedState in class BaseComponent