Package com.iizix
Class SingleRetriggerableTask
java.lang.Object
com.iizix.SingleRetriggerableTask
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 Summary
ConstructorsConstructorDescriptionThe single-runner task constructor without Worker and Runnable.SingleRetriggerableTask(Worker worker) The single-runner task constructor without Runnable.SingleRetriggerableTask(Worker worker, Runnable runnable) The single-runner task constructor.SingleRetriggerableTask(Runnable runnable) The single-runner task constructor without Worker.Method Summary
Modifier and TypeMethodDescriptionintcancelTask(boolean interruptTaskThread) Cancels the task.booleanReturns if the runnable has been triggered.voidsetPriority(int priority) Sets the priority of the task that is by defaultWorkerTask.PRIORITY_LOWEST.voidsetRunnable(Runnable runnable) Assigns the Runnable.voidSets the Worker for the task.booleantrigger()Triggers a task.
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
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
The single-runner task constructor without Worker.- Parameters:
runnable- The runnable.
SingleRetriggerableTask
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 defaultWorkerTask.PRIORITY_LOWEST.- Parameters:
priority- The new priority of coming tasks to run, range from lowestWorkerTask.PRIORITY_LOWESTto highestWorkerTask.PRIORITY_HIGHEST.- Throws:
IllegalArgumentException- If priority is out of range.
setWorker
Sets the Worker for the task.- Parameters:
worker- The Worker to run the task in.
setRunnable
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 tothread.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 isnull.NullPointerException- If the Runnable isnull.