Package com.iizix
Class SingleRetriggerableTask
- java.lang.Object
- com.iizix.SingleRetriggerableTask
public class SingleRetriggerableTask extends java.lang.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 Summary
Constructors Constructor Description SingleRetriggerableTask()
The single-runner task constructor without Worker and Runnable.SingleRetriggerableTask(Worker worker)
The single-runner task constructor without Runnable.SingleRetriggerableTask(Worker worker, java.lang.Runnable runnable)
The single-runner task constructor.SingleRetriggerableTask(java.lang.Runnable runnable)
The single-runner task constructor without Worker.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
cancelTask(boolean interruptTaskThread)
Cancels the task.boolean
isTriggered()
Returns if the runnable has been triggered.void
setPriority(int priority)
Sets the priority of the task that is by defaultWorkerTask.PRIORITY_LOWEST
.void
setRunnable(java.lang.Runnable runnable)
Assigns the Runnable.void
setWorker(Worker worker)
Sets the Worker for the task.boolean
trigger()
Triggers a task.
Constructor Detail
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(java.lang.Runnable runnable)
The single-runner task constructor without Worker.- Parameters:
runnable
- The runnable.
SingleRetriggerableTask
public SingleRetriggerableTask(Worker worker, java.lang.Runnable runnable)
The single-runner task constructor.- Parameters:
worker
- The Worker to run the task in.runnable
- The Runnable to execute.
Method Detail
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_LOWEST
to highestWorkerTask.PRIORITY_HIGHEST
.- Throws:
java.lang.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(java.lang.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 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:
java.lang.NullPointerException
- If the Worker isnull
.java.lang.NullPointerException
- If the Runnable isnull
.