All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jalse.actions.ActionScheduler Maven / Gradle / Ivy

There is a newer version: 1.1.0
Show newest version
package jalse.actions;

import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;

/**
 * This is the JALSE equivalent to {@link Executor}. {@link Action} can be scheduled to be run once
 * now, in the future and periodically at an interval. When an action is run work can be performed
 * using a supplied actor, scheduler defines the actor type as well as a means to maintain
 * previously scheduled/running actions.
 *
 * @author Elliot Ford
 *
 * @param 
 *            Actor type to schedule referencing work.
 */
public interface ActionScheduler {

    /**
     * Cancels all tasks currently running/scheduled (scheduled by this).
     */
    void cancelAllScheduledForActor();

    /**
     * Schedules an action for immediate execution.
     *
     * @param action
     *            Action to schedule.
     * @return Context associated with the action (immutable).
     */
    default MutableActionContext scheduleForActor(final Action action) {
	return scheduleForActor(action, 0L, TimeUnit.NANOSECONDS);
    }

    /**
     * Schedules an action for execution with a supplied initial delay and repeat period.
     *
     * @param action
     *            Action to schedule.
     * @param initialDelay
     *            Initial delay before schedule (can be {@code 0}).
     * @param period
     *            Period for repeating (can be {@code 0}).
     * @param unit
     *            Time unit of initial delay and period.
     * @return Context associated with the action (immutable).
     */
    MutableActionContext scheduleForActor(final Action action, final long initialDelay, final long period,
	    final TimeUnit unit);

    /**
     * Schedules an action to be executed after the supplied delay.
     *
     * @param action
     *            Action to schedule.
     * @param initialDelay
     *            Delay before schedule.
     * @param unit
     *            TimeUnit of the delay.
     * @return Context associated with the action (immutable).
     */
    default MutableActionContext scheduleForActor(final Action action, final long initialDelay,
	    final TimeUnit unit) {
	return scheduleForActor(action, initialDelay, 0L, unit);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy