Class PhonWorker

java.lang.Object
java.lang.Thread
ca.phon.worker.PhonWorker
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
PhonShutdownThread

public class PhonWorker extends Thread
A worker thread for the application. Tasks are place on the worker thread using the invokeLater(Runnable) method. Tasks are run FIFO.
  • Constructor Details

    • PhonWorker

      protected PhonWorker()
      Constructor
  • Method Details

    • getInstance

      public static PhonWorker getInstance()
      Get the static instance
    • createWorker

      public static PhonWorker createWorker()
      Creates a new PhonWorker thread and returns it. The new thread is not maintained by this class and the reference to it should be kept and shutdown by the requsting class.
      Returns:
      a new PhonWorker thread
    • createWorker

      public static PhonWorker createWorker(ConcurrentLinkedQueue<Runnable> queue)
      Create a new worker using a shared queue.
      Returns:
      a new PhonWorker thread
    • invokeOnNewWorker

      public static PhonTask invokeOnNewWorker(Runnable toRun)
    • invokeOnNewWorker

      public static PhonTask invokeOnNewWorker(Runnable toRun, Runnable onFinish)
    • invokeOnNewWorker

      public static PhonTask invokeOnNewWorker(Runnable toRun, Runnable onFinish, PhonTaskErrorHandler onError)
      Invoke provided runnable on a new thread and return the generated PhonTask
      Parameters:
      toRun -
      onFinish -
    • invokeLater

      public void invokeLater(Runnable task)
      Add a task to the queue.
      Parameters:
      task -
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • getShutdownThread

      public static PhonWorker getShutdownThread()
    • shutdown

      public void shutdown()
      Shutdown the worker thread. The currently executing task must complete first.
    • isStaticWorkerThread

      public static boolean isStaticWorkerThread()
      Tells if the currently running thread is the worker thread.
      Returns:
      true if we are running in the worker thread, false otherwise
    • hasTasks

      public boolean hasTasks()
    • isHaltOnError

      public boolean isHaltOnError()
    • setHaltOnError

      public void setHaltOnError(boolean haltOnError)
    • getFinalTask

      public Runnable getFinalTask()
    • setFinalTask

      public void setFinalTask(Runnable finalTask)
    • getTasks

      public Collection<Runnable> getTasks()
    • isFinishWhenQueueEmpty

      public boolean isFinishWhenQueueEmpty()
    • setFinishWhenQueueEmpty

      public void setFinishWhenQueueEmpty(boolean finishWhenQueueEmpty)