panda.task.TaskScheduler Maven / Gradle / Ivy
package panda.task;
import java.util.Date;
import java.util.concurrent.ScheduledFuture;
/**
* Task scheduler interface that abstracts the scheduling of
* {@link Runnable Runnables} based on different kinds of triggers.
*
* The 'default' implementation is
* {@link ThreadPoolTaskScheduler},
* wrapping a native {@link java.util.concurrent.ScheduledExecutorService}
* and adding extended trigger capabilities.
*
*
This interface is roughly equivalent to a JSR-236
* {@code ManagedScheduledExecutorService} as supported in Java EE 6
* environments.
*
*/
public interface TaskScheduler extends AsyncTaskExecutor {
/**
* Schedule the given {@link Runnable}, invoking it whenever the trigger
* indicates a next execution time.
*
Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param trigger an implementation of the {@link Trigger} interface,
* wrapping a cron expression
* @return a {@link ScheduledFuture} representing pending completion of the task,
* or {@code null} if the given Trigger object never fires (i.e. returns
* {@code null} from {@link Trigger#nextExecutionTime})
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
*/
ScheduledFuture> schedule(Runnable task, Trigger trigger);
/**
* Schedule the given {@link Runnable}, invoking it at the specified execution time.
*
Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param startTime the desired execution time for the task
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
* @return a {@link ScheduledFuture} representing pending completion of the task
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
*/
ScheduledFuture> schedule(Runnable task, Date startTime);
/**
* Creates and executes a one-shot action that becomes enabled after the given delay.
*
* @param task the task to execute
* @param delay the milliseconds from now to delay execution
* @return a ScheduledFuture representing pending completion of the task and whose
* get() method will return null upon completion
*/
ScheduledFuture> schedule(Runnable task, long delay);
/**
* Schedule the given {@link Runnable}, invoking it at the specified execution time
* and subsequently with the given period.
*
Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param initialDelay the time to delay first execution
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
* @param period the interval between successive executions of the task (in milliseconds)
* @return a {@link ScheduledFuture} representing pending completion of the task
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
*/
ScheduledFuture> scheduleAtFixedRate(Runnable task, long initialDelay, long period);
/**
* Schedule the given {@link Runnable}, invoking it at the specified execution time
* and subsequently with the given period.
*
Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param startTime the desired first execution time for the task
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
* @param period the interval between successive executions of the task (in milliseconds)
* @return a {@link ScheduledFuture} representing pending completion of the task
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
*/
ScheduledFuture> scheduleAtFixedRate(Runnable task, Date startTime, long period);
/**
* Schedule the given {@link Runnable}, starting as soon as possible and
* invoking it with the given period.
*
Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param period the interval between successive executions of the task (in milliseconds)
* @return a {@link ScheduledFuture} representing pending completion of the task
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
*/
ScheduledFuture> scheduleAtFixedRate(Runnable task, long period);
/**
* Schedule the given {@link Runnable}, invoking it at the specified execution time
* and subsequently with the given delay between the completion of one execution
* and the start of the next.
*
Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param initialDelay the time to delay first execution
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
* @param delay the delay between the completion of one execution and the start
* of the next (in milliseconds)
* @return a {@link ScheduledFuture} representing pending completion of the task
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
*/
ScheduledFuture> scheduleWithFixedDelay(Runnable task, long initialDelay, long delay);
/**
* Schedule the given {@link Runnable}, invoking it at the specified execution time
* and subsequently with the given delay between the completion of one execution
* and the start of the next.
*
Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param startTime the desired first execution time for the task
* (if this is in the past, the task will be executed immediately, i.e. as soon as possible)
* @param delay the delay between the completion of one execution and the start
* of the next (in milliseconds)
* @return a {@link ScheduledFuture} representing pending completion of the task
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
*/
ScheduledFuture> scheduleWithFixedDelay(Runnable task, Date startTime, long delay);
/**
* Schedule the given {@link Runnable}, starting as soon as possible and
* invoking it with the given delay between the completion of one execution
* and the start of the next.
*
Execution will end once the scheduler shuts down or the returned
* {@link ScheduledFuture} gets cancelled.
* @param task the Runnable to execute whenever the trigger fires
* @param delay the interval between successive executions of the task (in milliseconds)
* @return a {@link ScheduledFuture} representing pending completion of the task
* for internal reasons (e.g. a pool overload handling policy or a pool shutdown in progress)
*/
ScheduledFuture> scheduleWithFixedDelay(Runnable task, long delay);
}