Package org.opencastproject.job.api
Class JobBarrier
java.lang.Object
org.opencastproject.job.api.JobBarrier
This class is a utility implementation that will wait for all given jobs to change their status to either one of:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classResult of a waiting operation on a certain number of jobs. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault polling interval is 5 seconds -
Constructor Summary
ConstructorsConstructorDescriptionJobBarrier(Job waiter, ServiceRegistry registry) Creates a barrier without any jobs, usingregistryto poll for the outcome of the monitored jobs using the default polling intervalDEFAULT_POLLING_INTERVAL.JobBarrier(Job waiter, ServiceRegistry registry, long pollingInterval) Creates a wrapper forjob, usingregistryto poll for the job outcome.JobBarrier(Job waiter, ServiceRegistry registry, long pollingInterval, Job... jobs) Creates a wrapper forjob, usingregistryto poll for the job outcome.JobBarrier(Job waiter, ServiceRegistry registry, Job... jobs) Creates a barrier forjobs, usingregistryto poll for the outcome of the monitored jobs using the default polling intervalDEFAULT_POLLING_INTERVAL. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the job to the list of jobs to wait for.Returns the resulting status map.Waits for a status change and returns the new status.waitForJobs(long timeout) Waits for a status change on all jobs and returns.
-
Field Details
-
DEFAULT_POLLING_INTERVAL
public static final long DEFAULT_POLLING_INTERVALDefault polling interval is 5 seconds- See Also:
-
-
Constructor Details
-
JobBarrier
Creates a barrier without any jobs, usingregistryto poll for the outcome of the monitored jobs using the default polling intervalDEFAULT_POLLING_INTERVAL. Thewaiteris the job which is waiting for the other jobs to finish. UseaddJob(Job)to add jobs to monitor.- Parameters:
waiter- the job waiting for the other jobs to finishregistry- the registry
-
JobBarrier
Creates a barrier forjobs, usingregistryto poll for the outcome of the monitored jobs using the default polling intervalDEFAULT_POLLING_INTERVAL. Thewaiteris the job which is waiting for the other jobs to finish.- Parameters:
waiter- the job waiting for the other jobs to finishregistry- the registryjobs- the jobs to monitor
-
JobBarrier
Creates a wrapper forjob, usingregistryto poll for the job outcome. Thewaiteris the job which is waiting for the other jobs to finish.- Parameters:
waiter- the job waiting for the other jobs to finishregistry- the registrypollingInterval- the time in miliseconds between two polling operations
-
JobBarrier
Creates a wrapper forjob, usingregistryto poll for the job outcome. Thewaiteris the job which is waiting for the other jobs to finish.- Parameters:
waiter- the job waiting for the other jobs to finishregistry- the registrypollingInterval- the time in miliseconds between two polling operationsjobs- the job to poll
-
-
Method Details
-
waitForJobs
Waits for a status change and returns the new status.- Returns:
- the status
-
waitForJobs
public JobBarrier.Result waitForJobs(long timeout) throws JobCanceledException, IllegalStateException Waits for a status change on all jobs and returns. If waiting for the status exceeds a certain limit, the method returns even if some or all of the jobs are not yet finished. The same is true if at least one of the jobs fails or gets stopped or deleted.- Parameters:
timeout- the maximum amount of time to wait- Throws:
IllegalStateException- if there are no jobs to wait forJobCanceledException- if one of the jobs was canceled
-
addJob
Adds the job to the list of jobs to wait for. AnIllegalStateExceptionis thrown if the barrier has already been asked to wait for jobs by callingwaitForJobs().- Parameters:
job- the job- Throws:
IllegalStateException- if the barrier already started waiting
-
getStatus
Returns the resulting status map.- Returns:
- the status of the individual jobs
-