uws.job.manager
Class PhaseManager

java.lang.Object
  extended by uws.job.manager.PhaseManager
All Implemented Interfaces:
java.io.Serializable

public class PhaseManager
extends java.lang.Object
implements java.io.Serializable

An instance of this class represents the current execution phase of a given job, and it describes the behavior of each phase transition.

Version:
02/2011
Author:
Grégory Mantelet (CDS)
See Also:
ExecutionPhase, AbstractJob, Serialized Form

Field Summary
protected  AbstractJob job
          The job whose the current phase is represented by this class.
protected  ExecutionPhase phase
          Current phase of the associated job.
 
Constructor Summary
PhaseManager(AbstractJob j)
          Builds the phase manager of the given job.
 
Method Summary
 AbstractJob getJob()
          Gets the job whose the execution phase is represented by this object.
 ExecutionPhase getPhase()
          Gets the current phase of the job.
 boolean isExecuting()
           
 boolean isFinished()
          Indicates whether the job is finished or not, considering its current phase.
 boolean isJobUpdatable()
          Indicates whether the job attributes (except errors and results) can be updated, considering its current phase.
protected  void setAbortedPhase(boolean force)
          Changes the current phase to ABORTED, stops the job and sets the end time if needed.
protected  void setCompletedPhase(boolean force)
          Changes the current phase to COMPLETED and set the end time.
protected  void setErrorPhase(boolean force)
          Changes the current phase to ERROR, stops the job and set the end time.
protected  void setExecutingPhase(boolean force)
          Changes the current phase to EXECUTING and then starts the job (after having set its start time attribute).
protected  void setHeldPhase(boolean force)
          Changes the current phase to HELD.
protected  void setPendingPhase(boolean force)
          Changes the current phase to PENDING.
 void setPhase(ExecutionPhase p)
          Lets changing, considering the order of execution phases, the current phase of the associated job.
 void setPhase(ExecutionPhase p, boolean force)
          Lets changing the current phase of the associated job.
protected  void setQueuedPhase(boolean force)
          Changes the current phase to QUEUED if the job can be queued, else this method will change the current phase to EXECUTING.
protected  void setSuspendedPhase(boolean force)
          Changes the current phase to SUSPENDED.
protected  void setUnknownPhase(boolean force)
          Changes the current phase to UNKNOWN.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

phase

protected ExecutionPhase phase
Current phase of the associated job.


job

protected final AbstractJob job
The job whose the current phase is represented by this class.

Constructor Detail

PhaseManager

public PhaseManager(AbstractJob j)
             throws UWSException
Builds the phase manager of the given job.

Parameters:
j - The job whose the execution phase must be represented by the built JobPhase instance.
Throws:
UWSException - If the given job is null.
Method Detail

getJob

public final AbstractJob getJob()
Gets the job whose the execution phase is represented by this object.

Returns:
The associated job.

getPhase

public final ExecutionPhase getPhase()
Gets the current phase of the job.

Returns:
The current job phase.

setPhase

public final void setPhase(ExecutionPhase p)
                    throws UWSException
Lets changing, considering the order of execution phases, the current phase of the associated job.

Parameters:
p - The new execution phase.
Throws:
UWSException - If the given phase is null or if the phase transition is forbidden.
See Also:
setPhase(ExecutionPhase, boolean)

setPhase

public void setPhase(ExecutionPhase p,
                     boolean force)
              throws UWSException
Lets changing the current phase of the associated job.

Parameters:
p - The new phase.
force - true to ignore the phases order, false otherwise.
Throws:
UWSException - If the given phase is null or if the phase transition is forbidden.
See Also:
setPendingPhase(boolean), #setRunPhase(boolean), setQueuedPhase(boolean), setExecutingPhase(boolean), setCompletedPhase(boolean), #setAbortPhase(boolean), setAbortedPhase(boolean), setErrorPhase(boolean), setHeldPhase(boolean), setSuspendedPhase(boolean), setUnknownPhase(boolean)

setPendingPhase

protected void setPendingPhase(boolean force)
                        throws UWSException
Changes the current phase to PENDING.

Parameters:
force - true to ignore the phases order, false otherwise.
Throws:
UWSException - If this phase transition is forbidden (by default: IF force=false AND currentPhase != PENDING or UNKNOWN).

setQueuedPhase

protected void setQueuedPhase(boolean force)
                       throws UWSException
Changes the current phase to QUEUED if the job can be queued, else this method will change the current phase to EXECUTING.

Parameters:
force - true to ignore the phases order, false otherwise.
Throws:
UWSException - If this phase transition is forbidden (by default: IF force=false AND currentPhase != QUEUED or HELD or PENDING or UNKNOWN).
See Also:
AbstractJob#isQueuedRequired(), setExecutingPhase(boolean)

setExecutingPhase

protected void setExecutingPhase(boolean force)
                          throws UWSException
Changes the current phase to EXECUTING and then starts the job (after having set its start time attribute).

Parameters:
force - true to ignore the phases order, false otherwise.
Throws:
UWSException - If this phase transition is forbidden (by default: IF force=false AND currentPhase != EXECUTING or SUSPENDED or QUEUED or UNKNOWN).
See Also:
AbstractJob.setStartTime(Date), #startJob()

setCompletedPhase

protected void setCompletedPhase(boolean force)
                          throws UWSException
Changes the current phase to COMPLETED and set the end time.

Parameters:
force - true to ignore the phases order, false otherwise.
Throws:
UWSException - If this phase transition is forbidden (by default: IF force=false AND currentPhase != COMPLETED or EXECUTING or UNKNOWN).
See Also:
AbstractJob.setEndTime(Date)

setAbortedPhase

protected void setAbortedPhase(boolean force)
                        throws UWSException
Changes the current phase to ABORTED, stops the job and sets the end time if needed.

Parameters:
force - true to ignore the phases order, false otherwise.
Throws:
UWSException - If this phase transition is forbidden (by default: IF force=false AND currentPhase = COMPLETED or ERROR).
See Also:
#stopJob(), AbstractJob.isRunning(), AbstractJob.setEndTime(Date)

setErrorPhase

protected void setErrorPhase(boolean force)
                      throws UWSException
Changes the current phase to ERROR, stops the job and set the end time.

Parameters:
force - true to ignore the phases order, false otherwise.
Throws:
UWSException - If this phase transition is forbidden (by default: IF force=false AND currentPhase = COMPLETED or ABORTED).
See Also:
#stopJob(), AbstractJob.setEndTime(Date)

setHeldPhase

protected void setHeldPhase(boolean force)
                     throws UWSException
Changes the current phase to HELD.

Parameters:
force - true to ignore the phases order, false otherwise.
Throws:
UWSException - If this phase transition is forbidden (by default: IF force=false AND currentPhase != HELD or PENDING or UNKNOWN).

setSuspendedPhase

protected void setSuspendedPhase(boolean force)
                          throws UWSException
Changes the current phase to SUSPENDED.

Parameters:
force - true to ignore the phases order, false otherwise.
Throws:
UWSException - By default, never !

setUnknownPhase

protected void setUnknownPhase(boolean force)
                        throws UWSException
Changes the current phase to UNKNOWN.

Parameters:
force - true to ignore the phases order, false otherwise.
Throws:
UWSException - By default, never !

isJobUpdatable

public boolean isJobUpdatable()

Indicates whether the job attributes (except errors and results) can be updated, considering its current phase.

Note: By default, it returns TRUE only if the current phase is equals to PENDING !

Returns:
true if the job can be updated, false otherwise.

isFinished

public boolean isFinished()

Indicates whether the job is finished or not, considering its current phase.

Note: By default, it returns TRUE only if the current phase is either COMPLETED, ABORTED or ERROR !

Returns:
true if the job is finished, false otherwise.

isExecuting

public boolean isExecuting()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object