net.floodlightcontroller.core.util
Class SingletonTask
java.lang.Object
net.floodlightcontroller.core.util.SingletonTask
public class SingletonTask
- extends java.lang.Object
This allows you to represent a task that should be queued for future execution
but where you only want the task to complete once in response to some sequence
of events. For example, if you get a change notification and want to reload state,
you only want to reload the state once, at the end, and don't want to queue
an update for every notification that might come in.
The semantics are as follows:
* If the task hasn't begun yet, do not queue a new task
* If the task has begun, set a bit to restart it after the current task finishes
Constructor Summary |
SingletonTask(java.util.concurrent.ScheduledExecutorService ses,
java.lang.Runnable task)
Construct a new SingletonTask for the given runnable. |
Method Summary |
void |
reschedule(long delay,
java.util.concurrent.TimeUnit unit)
Schedule the task to run if there's not already a task scheduled
If there is such a task waiting that has not already started, it
cancel that task and reschedule it to run at the given time. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
logger
protected static org.slf4j.Logger logger
context
protected SingletonTask.SingletonTaskContext context
task
protected java.lang.Runnable task
ses
protected java.util.concurrent.ScheduledExecutorService ses
SingletonTask
public SingletonTask(java.util.concurrent.ScheduledExecutorService ses,
java.lang.Runnable task)
- Construct a new SingletonTask for the given runnable. The context
is used to manage the state of the task execution and can be shared
by more than one instance of the runnable.
- Parameters:
context
- Task
-
reschedule
public void reschedule(long delay,
java.util.concurrent.TimeUnit unit)
- Schedule the task to run if there's not already a task scheduled
If there is such a task waiting that has not already started, it
cancel that task and reschedule it to run at the given time. If the
task is already started, it will cause the task to be rescheduled once
it completes to run after delay from the time of reschedule.
- Parameters:
delay
- the delay in schedulingunit
- the timeunit of the delay