uws.job.manager
Interface ExecutionManager

All Superinterfaces:
java.io.Serializable
All Known Implementing Classes:
DefaultExecutionManager, QueuedExecutionManager

public interface ExecutionManager
extends java.io.Serializable

Lets managing the execution of a set of jobs.

It is used by a job to decide whether it can be executed or whether it must be put in a queue. This decision is done by the function isReadyForExecution(AbstractJob) when execute(AbstractJob) is called.

Besides the job must notify its manager when it is asked to start (execute(AbstractJob)) and to end (remove(AbstractJob)).

Note: update(AbstractJob) is used only when the job is changing its execution manager while executing.

Version:
02/2011
Author:
Grégory Mantelet (CDS)

Method Summary
 ExecutionPhase execute(AbstractJob jobToExecute)
          Lets deciding whether the given job can start immediately or whether it must be put in the queue.
 int getNbQueuedJobs()
          Gets the total number of queued jobs.
 int getNbRunningJobs()
          Gets the total number of running jobs.
 java.util.Iterator<AbstractJob> getQueuedJobs()
          Gets the list of queued jobs.
 java.util.Iterator<AbstractJob> getRunningJobs()
          Gets the list of running jobs.
 boolean hasQueue()
          Indicates whether this execution manager has a queue or not.
 boolean isReadyForExecution(AbstractJob jobToExecute)
          Tells whether the given job can start immediately its execution or whether it must be put in the queue.
 void refresh()
          Refreshes the lists of running and queued jobs.
 void remove(AbstractJob jobToRemove)
          Removes the job from this manager whatever is its current execution phase.
 void setNoQueue()
          Lets indicating that no more jobs must be put in the queue.
 void sync()
          This method is called just after a de-serialization.
 void update(AbstractJob job)
          Puts the given job into the appropriate list of jobs: if EXECUTING, the job must be put in the list of running jobs, but if QUEUED, it must be put into the queue.
 

Method Detail

sync

void sync()

This method is called just after a de-serialization. It resets all: just after a de-serialization there is no running jobs so all jobs lists are cleared.


getRunningJobs

java.util.Iterator<AbstractJob> getRunningJobs()
Gets the list of running jobs.

Returns:
An iterator on the running jobs.

getNbRunningJobs

int getNbRunningJobs()
Gets the total number of running jobs.

Returns:
The number of running jobs.

getQueuedJobs

java.util.Iterator<AbstractJob> getQueuedJobs()
Gets the list of queued jobs.

Returns:
An iterator on the queued jobs.

getNbQueuedJobs

int getNbQueuedJobs()
Gets the total number of queued jobs.

Returns:
The number of queued jobs.

setNoQueue

void setNoQueue()
Lets indicating that no more jobs must be put in the queue. Consequently all current queued jobs have to start immediately.


hasQueue

boolean hasQueue()
Indicates whether this execution manager has a queue or not.

Returns:
true if this manager has a queue, false otherwise.

refresh

void refresh()
             throws UWSException
Refreshes the lists of running and queued jobs.

Throws:
UWSException - If there is an error while refreshing this manager.

execute

ExecutionPhase execute(AbstractJob jobToExecute)
                       throws UWSException

Lets deciding whether the given job can start immediately or whether it must be put in the queue.

Parameters:
jobToExecute - The job to execute.
Returns:
The resulting execution phase of the given job.
Throws:
UWSException - If there is an error while changing the execution phase of the given job or if any other error occurs.
See Also:
AbstractJob.start(boolean), AbstractJob.setPhase(ExecutionPhase)

isReadyForExecution

boolean isReadyForExecution(AbstractJob jobToExecute)

Tells whether the given job can start immediately its execution or whether it must be put in the queue.

Parameters:
jobToExecute - The job to execute.
Returns:
true if the job can start immediately, false otherwise.

update

void update(AbstractJob job)
            throws UWSException

Puts the given job into the appropriate list of jobs: if EXECUTING, the job must be put in the list of running jobs, but if QUEUED, it must be put into the queue. In another case, nothing is done except refreshing the list of running jobs.

Parameters:
job - The job to "add" to this manager.
Throws:
UWSException - If there is an error while refreshing the list of running jobs or if any other error occurs.

remove

void remove(AbstractJob jobToRemove)
            throws UWSException
Removes the job from this manager whatever is its current execution phase.

Parameters:
jobToRemove - The job to remove.
Throws:
UWSException - If there is an error while refreshing the list of running jobs or if any other error occurs.