public abstract class AbstractQueuedExecutionManager extends java.lang.Object implements ExecutionManager
ExecutionManager which lets
managing an execution queue.
When calling execute(UWSJob), ALL jobs are put into the list of
queued jobs (so their phase is changed to ExecutionPhase.QUEUED).
A call to refresh(), reads this list and tries to execute the first
job of the list. The function isReadyForExecution(UWSJob) decides
whether the first job of the queue can be executed NOW or not.
Note: The order of queued jobs is preserved: it is implemented by a FIFO queue.
Note:
After a call to stopAll(), this manager is still able to execute
new jobs. Except if it was not possible to stop them properly, stopped jobs
could be executed again by calling afterwards execute(UWSJob) with
these jobs in parameter.
| Modifier and Type | Field and Description |
|---|---|
protected UWSLog |
logger |
protected java.util.Vector<UWSJob> |
queuedJobs
List of queued jobs.
|
protected java.util.Map<java.lang.String,UWSJob> |
runningJobs
List of running jobs.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractQueuedExecutionManager(UWSLog logger)
Builds an execution manager without queue.
|
| Modifier and Type | Method and Description |
|---|---|
ExecutionPhase |
execute(UWSJob jobToExecute)
Refreshes this manager and then put the given job into the queue (if
it is not already into it).
|
int |
getNbQueuedJobs()
Gets the total number of queued jobs.
|
int |
getNbRunningJobs()
Gets the total number of running jobs.
|
java.util.Iterator<UWSJob> |
getQueuedJobs()
Gets the list of queued jobs.
|
java.util.Iterator<UWSJob> |
getRunningJobs()
Gets the list of running jobs.
|
boolean |
hasQueue()
Tells whether there is a waiting queue.
|
abstract boolean |
isReadyForExecution(UWSJob jobToExecute)
Tells whether the given job can be executed NOW.
|
void |
refresh()
Removes the first queued job(s) from the queue and executes it (them)
ONLY IF it (they) can be executed (see
isReadyForExecution(UWSJob)). |
void |
remove(UWSJob jobToRemove)
Removes the given job from the lists of queued and running jobs and
then refreshes the manager.
|
protected void |
startJob(UWSJob jobToStartNow)
Starts immediately the given job.
|
void |
stopAll()
Stop all running jobs.
|
protected java.util.Map<java.lang.String,UWSJob> runningJobs
protected java.util.Vector<UWSJob> queuedJobs
protected final UWSLog logger
protected AbstractQueuedExecutionManager(UWSLog logger)
public final java.util.Iterator<UWSJob> getRunningJobs()
ExecutionManagergetRunningJobs in interface ExecutionManagerpublic final int getNbRunningJobs()
ExecutionManagergetNbRunningJobs in interface ExecutionManagerpublic final java.util.Iterator<UWSJob> getQueuedJobs()
ExecutionManagergetQueuedJobs in interface ExecutionManagerpublic final int getNbQueuedJobs()
ExecutionManagergetNbQueuedJobs in interface ExecutionManagerpublic boolean hasQueue()
public abstract boolean isReadyForExecution(UWSJob jobToExecute)
jobToExecute - public final void refresh()
isReadyForExecution(UWSJob)).
Note: Nothing is done if there is no queue.
Note: If any error occurs while refreshing this manager, it SHOULD be logged using the service logger.
refresh in interface ExecutionManagerhasQueue(),
isReadyForExecution(UWSJob),
startJob(UWSJob),
ExecutionManager.refresh()protected void startJob(UWSJob jobToStartNow) throws UWSException
jobToStartNow - The job to start.UWSException - If there is an error while starting the job.UWSJob.start(boolean)public final ExecutionPhase execute(UWSJob jobToExecute)
Note: If any error occurs while executing the given job, it SHOULD be logged using the service logger.
execute in interface ExecutionManagerjobToExecute - The job to execute.EXECUTING or
QUEUED
or null if the given job is null).refresh(),
UWSJob.isRunning(),
isReadyForExecution(UWSJob),
UWSJob.setPhase(ExecutionPhase),
ExecutionManager.execute(UWSJob)public final void remove(UWSJob jobToRemove)
Note: If any error occurs while removing a job from this manager, it SHOULD be logged using the service logger.
remove in interface ExecutionManagerjobToRemove - The job to remove.ExecutionManager.remove(uws.job.UWSJob)public final void stopAll()
ExecutionManagerStop all running jobs. No more job, even the queued ones, must be executed after a call to this function. All stopped or aborted queued jobs should be set forcedly back to the PENDING status.
Note:
A call to ExecutionManager.execute(UWSJob) would re-activate this manager. However jobs stopped or
aborted using this function might not be starting again. These behaviors at implementation-dependent.
stopAll in interface ExecutionManager