Package snap.util

Class TaskRunner<T>

java.lang.Object
snap.util.TaskRunner<T>
All Implemented Interfaces:
TaskMonitor
Direct Known Subclasses:
TaskRunnerPanel

public abstract class TaskRunner<T> extends Object implements TaskMonitor
A class for running operations in the background.
  • Field Details

  • Constructor Details

    • TaskRunner

      public TaskRunner()
      Constructor.
    • TaskRunner

      public TaskRunner(TaskMonitor aMonitor)
      Constructor for given monitor.
  • Method Details

    • getName

      public String getName()
      Returns the name of runner (and thread).
    • setName

      public void setName(String aName)
      Sets the name of runner (and thread).
    • getMonitor

      public TaskMonitor getMonitor()
      Returns the monitor.
    • setMonitor

      public void setMonitor(TaskMonitor aMonitor)
      Sets the monitor.
    • startTasks

      public void startTasks(int aTaskCount)
      Advise the monitor of the total number of subtasks (invoke only once).
      Specified by:
      startTasks in interface TaskMonitor
    • beginTask

      public void beginTask(String aTitle, int theTotalWork)
      Begin processing a single task.
      Specified by:
      beginTask in interface TaskMonitor
    • updateTask

      public void updateTask(int theWorkDone)
      Denote that some work units have been completed.
      Specified by:
      updateTask in interface TaskMonitor
    • endTask

      public void endTask()
      Finish the current task, so the next can begin.
      Specified by:
      endTask in interface TaskMonitor
    • getStatus

      public TaskRunner.Status getStatus()
      Returns the status.
    • setStatus

      protected void setStatus(TaskRunner.Status aStatus)
      Sets the status.
    • getThread

      public Thread getThread()
      Returns the thread.
    • join

      public TaskRunner<T> join()
      Joins the runner.
    • join

      public TaskRunner<T> join(int aTimeout)
      Joins the runner.
    • isActive

      public boolean isActive()
      Returns whether thread is still active.
    • isCancelled

      public boolean isCancelled()
      Whether runner has been cancelled.
      Specified by:
      isCancelled in interface TaskMonitor
      Returns:
      true if the user asked the process to stop working.
    • getStartTime

      public long getStartTime()
      Returns the start time.
    • getEndTime

      public long getEndTime()
      Returns the end time.
    • getElapsedTime

      public long getElapsedTime()
      Returns the elapsed time.
    • getSystemTime

      protected long getSystemTime()
      Returns the system time.
    • start

      public TaskRunner<T> start()
      Starts the runner.
    • cancel

      public void cancel()
      Cancels the runner.
    • run

      public abstract T run() throws Exception
      The method to run.
      Throws:
      Exception
    • success

      public void success(T aResult)
      The method run on success.
    • cancelled

      public void cancelled(Exception e)
      The method to run when cancelled.
    • failure

      public void failure(Exception e)
      The method to run on failure.
    • finished

      public void finished()
      The method to run when finished (after success()/failure() call).
    • getResult

      public T getResult()
      Returns the result.
    • getException

      public Throwable getException()
      Returns the exception.
    • invokeRun

      protected void invokeRun()
      Runs the run method.
    • invokeFinished

      protected void invokeFinished()
      Runs the success method.
    • addPropChangeListener

      public void addPropChangeListener(PropChangeListener aLsnr)
      Add listener.
    • removePropChangeListener

      public void removePropChangeListener(PropChangeListener aLsnr)
      Remove listener.
    • firePropChange

      protected void firePropChange(String aProp, Object oldVal, Object newVal)
      Fires a property change for given property name, old value, new value and index.