|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object uws.job.manager.QueuedExecutionManager
public class QueuedExecutionManager
Implementation of the interface ExecutionManager
which lets managing an execution queue in function of a maximum number of running jobs:
if there are more running jobs than a given number, the jobs to execute are put in the queue until a running job stops.
The order of queued jobs are preserved: it is implemented by a FIFO queue.
Note:
By overriding isReadyForExecution(AbstractJob)
you can easily change the condition
which lets deciding when to put a job in the queue. By default: when there are more running jobs than nbMaxRunningJobs
.
Field Summary | |
---|---|
protected int |
nbMaxRunningJobs
The maximum number of running jobs. |
static int |
NO_QUEUE
The value of nbMaxRunningJobs which indicates that there is no queue. |
protected java.util.Vector<AbstractJob> |
queuedJobs
List of queued jobs. |
protected java.util.Map<java.lang.String,AbstractJob> |
runningJobs
List of running jobs. |
Constructor Summary | |
---|---|
QueuedExecutionManager()
Builds an execution manager without queue. |
|
QueuedExecutionManager(int maxRunningJobs)
Builds an execution manager with a queue. |
Method Summary | |
---|---|
ExecutionPhase |
execute(AbstractJob jobToExecute)
By default a job is executed if there are not yet more than getMaxRunningJobs() running jobs. |
int |
getMaxRunningJobs()
Gets the maximum number of running jobs. |
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()
Removes the first queued job(s) from the queue and executes it (them) ONLY IF it (they) can be executed (see isReadyForExecution(AbstractJob) ). |
void |
remove(AbstractJob jobToRemove)
Removes the job from this manager whatever is its current execution phase. |
void |
setMaxRunningJobs(int maxRunningJobs)
Sets the maximum number of running jobs. |
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 |
---|
protected transient java.util.Map<java.lang.String,AbstractJob> runningJobs
protected transient java.util.Vector<AbstractJob> queuedJobs
protected int nbMaxRunningJobs
public static final int NO_QUEUE
nbMaxRunningJobs
which indicates that there is no queue.
Constructor Detail |
---|
public QueuedExecutionManager()
sync()
public QueuedExecutionManager(int maxRunningJobs)
maxRunningJobs
- The maximum number of running jobs (must be > 0 to have a queue).sync()
Method Detail |
---|
public final void sync()
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.
sync
in interface ExecutionManager
public final java.util.Iterator<AbstractJob> getRunningJobs()
ExecutionManager
getRunningJobs
in interface ExecutionManager
public final int getNbRunningJobs()
ExecutionManager
getNbRunningJobs
in interface ExecutionManager
public final java.util.Iterator<AbstractJob> getQueuedJobs()
ExecutionManager
getQueuedJobs
in interface ExecutionManager
public final int getNbQueuedJobs()
ExecutionManager
getNbQueuedJobs
in interface ExecutionManager
public void setNoQueue()
ExecutionManager
setNoQueue
in interface ExecutionManager
public boolean hasQueue()
ExecutionManager
hasQueue
in interface ExecutionManager
public final int getMaxRunningJobs()
public void setMaxRunningJobs(int maxRunningJobs) throws UWSException
Sets the maximum number of running jobs.
Note: If the new maximum number of running jobs is increasing the list of running jobs is immediately updated BUT NOT IF it is decreasing (that is to say, running jobs will not be interrupted to be put in the queue, they continue to run) !
maxRunningJobs
- The new maximum number of running jobs (NO_QUEUE
or a negative value means no maximum number of running jobs: there will be no queue any more).
UWSException
- If there is an error while updating the list of running jobs (in other words if some queued jobs can not be executed).refresh()
public final void refresh() throws UWSException
Removes the first queued job(s) from the queue and executes it (them)
ONLY IF it (they) can be executed (see isReadyForExecution(AbstractJob)
).
Note: Nothing is done if there is no queue.
refresh
in interface ExecutionManager
UWSException
- If there is an error during the phase transition of one or more jobs.sync()
,
hasQueue()
,
isReadyForExecution(AbstractJob)
,
AbstractJob.start(boolean)
public final ExecutionPhase execute(AbstractJob jobToExecute) throws UWSException
By default a job is executed if there are not yet more than getMaxRunningJobs()
running jobs.
execute
in interface ExecutionManager
jobToExecute
- The job to execute.
EXECUTING
or QUEUED
or null if the given job is null).
UWSException
- If there is an error while changing the execution phase of the given job or if the job is already finished.refresh()
,
AbstractJob.isRunning()
,
hasQueue()
,
isReadyForExecution(AbstractJob)
,
AbstractJob.start(boolean)
,
AbstractJob.setPhase(ExecutionPhase)
public final boolean isReadyForExecution(AbstractJob jobToExecute)
ExecutionManager
Tells whether the given job can start immediately its execution or whether it must be put in the queue.
isReadyForExecution
in interface ExecutionManager
jobToExecute
- The job to execute.
public final void update(AbstractJob job) throws UWSException
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.
update
in interface ExecutionManager
job
- The job to "add" to this manager.
UWSException
- If there is an error while refreshing the list of running jobs or if any other error occurs.public final void remove(AbstractJob jobToRemove) throws UWSException
ExecutionManager
remove
in interface ExecutionManager
jobToRemove
- The job to remove.
UWSException
- If there is an error while refreshing the list of running jobs or if any other error occurs.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |