Module video

Class Worker


public class Worker extends ProgressObservable
The Worker is used to process jobs inside the plugin. Although the real processing is done inside a corresponding WorkerThread, the plugin communicates the the Worker only. To program lifetime there can only be one instance of this class, which can be created using the instance() method. An arbitrary amount of JobListeners can be add to this Worker. Jobs can be added to the Worker using the addJob(Job) method. To make sure the program doesn't continue until a job has finished, you can call the waitUntilFinished() method.
Author:
Dominick Leppich
  • Method Details

    • instance

      public static Worker instance()
      Get (and create on first call) an instance of the Worker class.
      Returns:
      A Worker instance
    • addJobListener

      public void addJobListener(JobListener listener)
      Add a JobListener to the Worker.
      Parameters:
      listener - - JobListener to add
    • removeJobListener

      public void removeJobListener(JobListener listener)
      Removes a JobListener from the Worker.
      Parameters:
      listener - - JobListener to remove
    • addJob

      public boolean addJob(Job job)
      Add a new Job to the worker. The job is queued at the end.
      Parameters:
      job - - Job to add
      Returns:
      True, if adding the Job was successfull
    • hasJobs

      public boolean hasJobs()
      Check if there are queued jobs.
      Returns:
      True, if the worker has queued jobs
    • waitUntilFinished

      public void waitUntilFinished()
      Let the calling thread wait, until the worker finishes processing all jobs.
    • cancel

      public void cancel() throws InterruptedException
      Cancel the job processing. The current processed Job is lost.
      Throws:
      InterruptedException - if the WorkerThread is interrupted