Errai 3.0.1-SNAPSHOT

org.jboss.errai.bus.server.async
Class TimedTask

java.lang.Object
  extended by org.jboss.errai.bus.server.async.TimedTask
All Implemented Interfaces:
Comparable<TimedTask>, Runnable, AsyncTask

public abstract class TimedTask
extends Object
implements Runnable, Comparable<TimedTask>, AsyncTask

A TimedTask is used for scheduling tasks, and making sure they are run at appropriate times and intervals


Field Summary
protected  boolean cancelled
           
protected  Runnable exitHandler
           
protected  InterruptHandle interruptHook
           
protected  long nextRuntime
           
protected  long period
           
 
Constructor Summary
TimedTask()
           
 
Method Summary
 boolean calculateNextRuntime()
           
 void cancel()
           
 void cancel(boolean interrupt)
          Prevents this task from being scheduled again, optionally interrupting the task if it is currently running.
 int compareTo(TimedTask o)
           
 long getPeriod()
          Gets the period of the task, and when it should be run next
 boolean isCancelled()
          Returns true if the task has been cancelled or is expired.
 boolean isDue(long time)
           
 long nextRuntime()
          Gets the time in which the task will be run.
 void setExitHandler(Runnable runnable)
          Sets the task that should be run after all executions of this task have completed.
 void setPeriod(long period)
          Sets the period in which the task should be run next
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 
Methods inherited from interface org.jboss.errai.common.client.api.tasks.AsyncTask
isFinished
 

Field Detail

nextRuntime

protected volatile long nextRuntime

period

protected volatile long period

cancelled

protected volatile boolean cancelled

interruptHook

protected volatile InterruptHandle interruptHook

exitHandler

protected volatile Runnable exitHandler
Constructor Detail

TimedTask

public TimedTask()
Method Detail

getPeriod

public long getPeriod()
Gets the period of the task, and when it should be run next

Returns:
the interval length

setPeriod

public void setPeriod(long period)
Sets the period in which the task should be run next

Parameters:
period -

cancel

public void cancel()

nextRuntime

public long nextRuntime()
Gets the time in which the task will be run. If -1 is returned, the task is permanently de-scheduled.

Returns:
the time the task will be run in milliseconds

cancel

public void cancel(boolean interrupt)
Description copied from interface: AsyncTask
Prevents this task from being scheduled again, optionally interrupting the task if it is currently running.

Specified by:
cancel in interface AsyncTask
Parameters:
interrupt - if true, and this task is presently being executed, Thread.interrupt() will be called on the thread currently executing this task.

isCancelled

public boolean isCancelled()
Returns true if the task has been cancelled or is expired.

Specified by:
isCancelled in interface AsyncTask
Returns:

calculateNextRuntime

public boolean calculateNextRuntime()

isDue

public boolean isDue(long time)

setExitHandler

public void setExitHandler(Runnable runnable)
Description copied from interface: AsyncTask
Sets the task that should be run after all executions of this task have completed. The supplied runnable is guaranteed to be invoked exactly once, even if this task has already completed or it has been cancelled.

Specified by:
setExitHandler in interface AsyncTask
Parameters:
runnable - the logic to execute when this task has completed all of its executions, either because it completed normally, by throwing an exception, or because it was cancelled by a call to AsyncTask.cancel(boolean).

compareTo

public int compareTo(TimedTask o)
Specified by:
compareTo in interface Comparable<TimedTask>

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.