Package com.iizix

Class SingleRetriggerableTask

java.lang.Object
com.iizix.SingleRetriggerableTask

public class SingleRetriggerableTask extends Object
As single-runner task that is run by a trigger and will run in the worker. Only one instance will be triggered until it starts or completes.
Author:
Christopher Mindus
  • Constructor Details

    • SingleRetriggerableTask

      public SingleRetriggerableTask()
      The single-runner task constructor without Worker and Runnable.

      The Worker must be provided later using setWorker(Worker).

      The runnable must be set using setRunnable(Runnable).

    • SingleRetriggerableTask

      public SingleRetriggerableTask(Worker worker)
      The single-runner task constructor without Runnable.

      The Runnable must be set using setRunnable(Runnable).

      Parameters:
      worker - The Worker to run the task in.
    • SingleRetriggerableTask

      public SingleRetriggerableTask(Runnable runnable)
      The single-runner task constructor without Worker.
      Parameters:
      runnable - The runnable.
    • SingleRetriggerableTask

      public SingleRetriggerableTask(Worker worker, Runnable runnable)
      The single-runner task constructor.
      Parameters:
      worker - The Worker to run the task in.
      runnable - The Runnable to execute.
  • Method Details

    • setPriority

      public void setPriority(int priority)
      Sets the priority of the task that is by default WorkerTask.PRIORITY_LOWEST.
      Parameters:
      priority - The new priority of coming tasks to run, range from lowest WorkerTask.PRIORITY_LOWEST to highest WorkerTask.PRIORITY_HIGHEST.
      Throws:
      IllegalArgumentException - If priority is out of range.
    • setWorker

      public void setWorker(Worker worker)
      Sets the Worker for the task.
      Parameters:
      worker - The Worker to run the task in.
    • setRunnable

      public void setRunnable(Runnable runnable)
      Assigns the Runnable.
      Parameters:
      runnable - The Runnable to execute.
    • isTriggered

      public boolean isTriggered()
      Returns if the runnable has been triggered.
      Returns:
      true if triggered, false otherwise.
    • cancelTask

      public int cancelTask(boolean interruptTaskThread)
      Cancels the task.
      Parameters:
      interruptTaskThread - Flag indicating if the task thread should be interrupted (if running) with call to thread.interrupt();.
      Returns:
      1 for success, zero for no task and -1 for failure.
    • trigger

      public boolean trigger()
      Triggers a task.
      Returns:
      true If the task has been posted, false if already posted.
      Throws:
      NullPointerException - If the Worker is null.
      NullPointerException - If the Runnable is null.