uws.job.manager
Class DefaultExecutionManager

java.lang.Object
  extended by uws.job.manager.DefaultExecutionManager
All Implemented Interfaces:
java.io.Serializable, ExecutionManager

public class DefaultExecutionManager
extends java.lang.Object
implements ExecutionManager

Default implementation of the ExecutionManager interface.

This manager does not have a queue. That is to say that all jobs are always immediately starting. Consequently this manager is just user to gather all running jobs.

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

Field Summary
protected  java.util.Map<java.lang.String,AbstractJob> runningJobs
          List of running jobs.
 
Constructor Summary
DefaultExecutionManager()
          Builds an execution manager without queue.
 
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()
          Always returns 0.
 int getNbRunningJobs()
          Gets the total number of running jobs.
 java.util.Iterator<AbstractJob> getQueuedJobs()
          Always returns a Null Iterator (iterator whose next() returns null and hasNext() returns false).
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

runningJobs

protected transient java.util.Map<java.lang.String,AbstractJob> runningJobs
List of running jobs.

Constructor Detail

DefaultExecutionManager

public DefaultExecutionManager()
Builds an execution manager without queue.

See Also:
sync()
Method Detail

sync

public void sync()
Description copied from interface: ExecutionManager

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.

Specified by:
sync in interface ExecutionManager

getRunningJobs

public final java.util.Iterator<AbstractJob> getRunningJobs()
Description copied from interface: ExecutionManager
Gets the list of running jobs.

Specified by:
getRunningJobs in interface ExecutionManager
Returns:
An iterator on the running jobs.

getNbRunningJobs

public final int getNbRunningJobs()
Description copied from interface: ExecutionManager
Gets the total number of running jobs.

Specified by:
getNbRunningJobs in interface ExecutionManager
Returns:
The number of running jobs.

getQueuedJobs

public java.util.Iterator<AbstractJob> getQueuedJobs()
Always returns a Null Iterator (iterator whose next() returns null and hasNext() returns false).

Specified by:
getQueuedJobs in interface ExecutionManager
Returns:
An iterator on the queued jobs.
See Also:
ExecutionManager.getQueuedJobs()

getNbQueuedJobs

public int getNbQueuedJobs()
Always returns 0.

Specified by:
getNbQueuedJobs in interface ExecutionManager
Returns:
The number of queued jobs.
See Also:
ExecutionManager.getNbQueuedJobs()

setNoQueue

public void setNoQueue()
Description copied from interface: ExecutionManager
Lets indicating that no more jobs must be put in the queue. Consequently all current queued jobs have to start immediately.

Specified by:
setNoQueue in interface ExecutionManager

hasQueue

public boolean hasQueue()
Description copied from interface: ExecutionManager
Indicates whether this execution manager has a queue or not.

Specified by:
hasQueue in interface ExecutionManager
Returns:
true if this manager has a queue, false otherwise.

refresh

public void refresh()
             throws UWSException
Description copied from interface: ExecutionManager
Refreshes the lists of running and queued jobs.

Specified by:
refresh in interface ExecutionManager
Throws:
UWSException - If there is an error while refreshing this manager.

execute

public ExecutionPhase execute(AbstractJob jobToExecute)
                       throws UWSException
Description copied from interface: ExecutionManager

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

Specified by:
execute in interface ExecutionManager
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

public boolean isReadyForExecution(AbstractJob jobToExecute)
Description copied from interface: ExecutionManager

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

Specified by:
isReadyForExecution in interface ExecutionManager
Parameters:
jobToExecute - The job to execute.
Returns:
true if the job can start immediately, false otherwise.

update

public void update(AbstractJob job)
            throws UWSException
Description copied from interface: ExecutionManager

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.

Specified by:
update in interface ExecutionManager
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

public void remove(AbstractJob jobToRemove)
            throws UWSException
Description copied from interface: ExecutionManager
Removes the job from this manager whatever is its current execution phase.

Specified by:
remove in interface ExecutionManager
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.