C. How to customize a Job ?
3.b. Execution WITH queue
How does it work ?
You have surely noticed that there are two functions to start a job: one with no parameter and another with a boolean parameter. start() always calls the second start method with true if there is an execution manager, false otherwise.
An execution manager is an object which implements the ExecutionManager interface. Its goal is to gather all executing jobs. There is one execution manager per UWS and it is propagated to the managed jobs.
There are already two default implementations of this interface: DefaultExecutionManager and QueuedExecutionManager. The first one is the most simple implementation. It has no queue and so it manages only running jobs. On the contrary QueuedExecutionManager is able to queue any given job if the number of running jobs exceeds a given number. When a running job ends, the first queued job is removed from the queue and then executed.
Here is a simplified class diagram for these classes:
![UML class diagram of the ExecutionManager interface.](images/descriptionExecutionManager.png)
Now, lets supposing your UWS has an execution manager which can manage a queue (ExecutionManager.hasQueue() returns true). When you ask to start the job thanks to start(), start(boolean) is actually called with true as parameter. Then execute(AbstractJob) of the execution manager is called. This function has to execute or to queue the job according to the value returned by its function isReadyForExecution(AbstractJob): if true, the job is executed, otherwise the job is queued. Finally to start a job, the execution manager calls start(boolean) with false. In this case the starting is exactly the same than with no queue (see C.3.a. Execution WITHOUT queue).
Notes:
- Even if the set execution manager has no queue: start() = start(true). In that way it is possible to have a list of all running jobs through the used execution manager. It may be very usefull for a UWS administrator !
- Only if there is really no execution manager: start() = start(false) !
- The methods update(AbstractJob) and remove(AbstractJob) are used only when a job is added or removed to/from a UWS or when a job ends. Both update the list of running jobs and the list of queued jobs (if any). See their javadoc for more details.
How to customize ?
QueuedExecutionManager proposes one possible management of an execution queue. If your needs are different you can either extend QueuedExecutionManager or implement the interface ExecutionManager. Once done you just have to use the function setExecutionManager(ExecutionManager) on your UWS or on one or several given jobs (if you want to manage them independently from a UWS).
When changing the execution manager of a UWS, the manager is automatically set to all managed jobs !