Class JobBarrier

java.lang.Object
org.opencastproject.job.api.JobBarrier

public final class JobBarrier extends Object
This class is a utility implementation that will wait for all given jobs to change their status to either one of:
  • Field Details

    • DEFAULT_POLLING_INTERVAL

      public static final long DEFAULT_POLLING_INTERVAL
      Default polling interval is 5 seconds
      See Also:
  • Constructor Details

    • JobBarrier

      public JobBarrier(Job waiter, ServiceRegistry registry)
      Creates a barrier without any jobs, using registry to poll for the outcome of the monitored jobs using the default polling interval DEFAULT_POLLING_INTERVAL. The waiter is the job which is waiting for the other jobs to finish. Use addJob(Job) to add jobs to monitor.
      Parameters:
      waiter - the job waiting for the other jobs to finish
      registry - the registry
    • JobBarrier

      public JobBarrier(Job waiter, ServiceRegistry registry, Job... jobs)
      Creates a barrier for jobs, using registry to poll for the outcome of the monitored jobs using the default polling interval DEFAULT_POLLING_INTERVAL. The waiter is the job which is waiting for the other jobs to finish.
      Parameters:
      waiter - the job waiting for the other jobs to finish
      registry - the registry
      jobs - the jobs to monitor
    • JobBarrier

      public JobBarrier(Job waiter, ServiceRegistry registry, long pollingInterval)
      Creates a wrapper for job, using registry to poll for the job outcome. The waiter is the job which is waiting for the other jobs to finish.
      Parameters:
      waiter - the job waiting for the other jobs to finish
      registry - the registry
      pollingInterval - the time in miliseconds between two polling operations
    • JobBarrier

      public JobBarrier(Job waiter, ServiceRegistry registry, long pollingInterval, Job... jobs)
      Creates a wrapper for job, using registry to poll for the job outcome. The waiter is the job which is waiting for the other jobs to finish.
      Parameters:
      waiter - the job waiting for the other jobs to finish
      registry - the registry
      pollingInterval - the time in miliseconds between two polling operations
      jobs - the job to poll
  • Method Details

    • waitForJobs

      public JobBarrier.Result 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 for
      JobCanceledException - if one of the jobs was canceled
    • addJob

      public void addJob(Job job) throws IllegalStateException
      Adds the job to the list of jobs to wait for. An IllegalStateException is thrown if the barrier has already been asked to wait for jobs by calling waitForJobs().
      Parameters:
      job - the job
      Throws:
      IllegalStateException - if the barrier already started waiting
    • getStatus

      public JobBarrier.Result getStatus()
      Returns the resulting status map.
      Returns:
      the status of the individual jobs