org.oddjob.jobs
Class AbstractJob

java.lang.Object
  extended byorg.oddjob.jobs.AbstractJob
All Implemented Interfaces:
Iconic, Resetable, java.lang.Runnable, java.io.Serializable, Stateful

public abstract class AbstractJob
extends java.lang.Object
implements java.io.Serializable, java.lang.Runnable, Resetable, Stateful, Iconic

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

See Also:
Serialized Form
Author:
Rob Gordon

Field Summary
protected  java.beans.PropertyChangeSupport changes
          Implement property change support which sub classes can take advantage of.
protected  StatefulChildHelper childHelper
          Intended to be used by decendent classes to help implement Structural.
protected  boolean destroyed
          This flag is set once the object is destroyed Methods in subclass should check this flag.
protected  IconHelper iconHelper
          Used to notify clients of an icon change.
protected  Lock lock
          This locks the component.
protected  JobStateHandler stateHandler
          A state handler to delagate state change functionality to.
protected  boolean stop
          This flag is set by the stop method and should be examined by any Stoppable sub classes in their processing loop.
 
Constructor Summary
AbstractJob()
           
 
Method Summary
 void addIconListener(IconListener listener)
          Add an icon listener.
 void addJobStateListener(JobStateListener listener)
          Add a job state listener.
 void addPropertyChangeListener(java.beans.PropertyChangeListener l)
          Add a property change listener.
 void addStructuralListener(StructuralListener listener)
          Add a listener.
 void destroy()
          Destroy this component.
protected abstract  int execute()
          Execute this job.
 Location getLocation()
           
 java.lang.String getLogger()
           
 java.lang.String getName()
          Get the job name.
protected  RuntimeConfiguration getRuntimeConfigurable()
           
 void hardReset()
          Perform a hard reset on the job.
 IconTip iconForId(java.lang.String iconId)
          Return an icon tip for a given id.
 JobStateEvent lastJobStateEvent()
          Returns the last JobState event.
 org.apache.log4j.Logger logger()
          Allow sub classes access to the logger.
 void removeIconListener(IconListener listener)
          Remove an icon listener.
 void removeJobStateListener(JobStateListener listener)
          Remove a job state listener.
 void removePropertyChangeListener(java.beans.PropertyChangeListener l)
          Remove a property change listener.
 void removeStructuralListener(StructuralListener listener)
          Remove a listener.
protected  boolean reset(StateTransform transform)
          Used by subclassses to perform a reset.
 void run()
          Implement the main execute method for a job.
 void setContext(ArooaContext context)
           
protected  void setJobStateException(java.lang.Throwable ex)
          Utility method to set the job state to exception.
 void setLogger(java.lang.String logger)
           
 void setName(java.lang.String name)
          Set the job name.
protected  void sleep(long waitTime)
          Utility method to sleep a certain time.
 void softReset()
          Perform a soft reset on the job.
 void stop()
          Allow subclasses to indicate they are stopping.
 java.lang.String toString()
          Override toString.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

changes

protected transient java.beans.PropertyChangeSupport changes
Implement property change support which sub classes can take advantage of.


iconHelper

protected IconHelper iconHelper
Used to notify clients of an icon change.


childHelper

protected transient StatefulChildHelper childHelper
Intended to be used by decendent classes to help implement Structural.


stateHandler

protected JobStateHandler stateHandler
A state handler to delagate state change functionality to.


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.


destroyed

protected transient volatile boolean destroyed
This flag is set once the object is destroyed Methods in subclass should check this flag.


lock

protected transient Lock lock
This locks the component. It can be used by methods in subclasses to ensure the component is locked before proceeding.

Constructor Detail

AbstractJob

public AbstractJob()
Method Detail

logger

public org.apache.log4j.Logger logger()
Allow sub classes access to the logger.

Returns:
The logger.

setContext

public void setContext(ArooaContext context)

getLocation

public Location getLocation()

getRuntimeConfigurable

protected RuntimeConfiguration getRuntimeConfigurable()

setJobStateException

protected void setJobStateException(java.lang.Throwable ex)
Utility method to set the job state to exception.

Parameters:
ex - The exception.

sleep

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

Parameters:
waitTime - Milliseconds to sleep for.

stop

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


execute

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

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

run

public final void run()
               throws OddjobLockedException
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 java.lang.Runnable
Throws:
OddjobLockedException

setName

public void setName(java.lang.String name)
Set the job name. Used by subclasses to set the job name.

Parameters:
name - The name of the job.

getName

public java.lang.String getName()
Get the job name.

Returns:
The job name.

lastJobStateEvent

public JobStateEvent lastJobStateEvent()
Returns the last JobState event. This is useful when Jobs are being used directly in code, and only one thread is using the job. Otherwise a JobStateListener should always be used.

This is not a property so that it can't be accessed directly in scripts.

Returns:
The last JobStateEvent. Will never bu null.

addJobStateListener

public void addJobStateListener(JobStateListener listener)
Add a job state listener.

Specified by:
addJobStateListener in interface Stateful
Parameters:
listener - The listener.

removeJobStateListener

public void removeJobStateListener(JobStateListener listener)
Remove a job state listener.

Specified by:
removeJobStateListener in interface Stateful
Parameters:
listener - The listener.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
Add a property change listener.

Parameters:
l - The property change listener.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
Remove a property change listener.

Parameters:
l - The property change listener.

reset

protected boolean reset(StateTransform transform)
Used by subclassses to perform a reset.

Parameters:
transform - A state transform.
Returns:
true if it succeeds, false otherwise.

softReset

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

Specified by:
softReset in interface Resetable

hardReset

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

Specified by:
hardReset in interface Resetable

iconForId

public IconTip iconForId(java.lang.String iconId)
Return an icon tip for a given id. Part of the Iconic interface.

Specified by:
iconForId in interface Iconic
Parameters:
iconId - The icon id.
Returns:
The IconTip or null if it doesn't exist.

addIconListener

public void addIconListener(IconListener listener)
Add an icon listener. Part of the Iconic interface.

Specified by:
addIconListener in interface Iconic
Parameters:
listener - The listener.

removeIconListener

public void removeIconListener(IconListener listener)
Remove an icon listener. Part of the Iconic interface.

Specified by:
removeIconListener in interface Iconic
Parameters:
listener - The listener.

addStructuralListener

public void addStructuralListener(StructuralListener listener)
Add a listener. The listener will immediately recieve add notifications for all existing children.

Parameters:
listener - The listener.

removeStructuralListener

public void removeStructuralListener(StructuralListener listener)
Remove a listener.

Parameters:
listener - The listner.

toString

public java.lang.String toString()
Override toString.


destroy

public void destroy()
Destroy this component.


getLogger

public java.lang.String getLogger()
Returns:
Returns the logger.

setLogger

public void setLogger(java.lang.String logger)
Parameters:
logger - The logger to set.