Class OperationManager


  • public class OperationManager
    extends java.lang.Object
    A class for managing and executing operations.

    This is a lightweight manager of task-like objects that are to be executed serially.

    An operation manager is similar to the Java AWT thread; it allows multiple operations to be queued and executed serially. An operation can be queued by calling schedule(Operation). The operation, if not canceled, will eventually be started using Runnable.run().

    Author:
    Garret Wilson
    • Constructor Detail

      • OperationManager

        public OperationManager()
        Default constructor.
    • Method Detail

      • getScheduledOperationQueue

        protected java.util.concurrent.BlockingQueue<OperationManager.ScheduledOperation> getScheduledOperationQueue()
        Returns:
        The queue for scheduling operations.
      • getScheduledOperationWorker

        protected java.lang.Runnable getScheduledOperationWorker()
        Returns:
        The worker that executes scheduled operations.
      • getExecutionThread

        protected java.lang.Thread getExecutionThread()
        Returns:
        The thread for asynchronous execution.
      • schedule

        public void schedule​(Operation operation)
        Schedules an operation for later, serial execution once with no delay.
        Parameters:
        operation - The operation to schedule.
        Throws:
        java.lang.NullPointerException - if the given operation is null.
        java.lang.IllegalStateException - if the operation cannot be scheduled at this time due to queue capacity restrictions.
      • schedule

        public void schedule​(Operation operation,
                             Duration delayTime)
        Schedules an operation for later, serial execution once with the given delay.
        Parameters:
        operation - The operation to schedule.
        delayTime - The delay past the scheduled time before the operation should begin (which may be 0).
        Throws:
        java.lang.NullPointerException - if the given operation and/or delay time is null.
        java.lang.IllegalStateException - if the operation cannot be scheduled at this time due to queue capacity restrictions.
      • schedule

        public void schedule​(Operation operation,
                             boolean repeated)
        Schedules an operation for later, serial execution with no delay.
        Parameters:
        operation - The operation to schedule.
        repeated - Whether this operation should be repeated.
        Throws:
        java.lang.NullPointerException - if the given operation is null.
        java.lang.IllegalStateException - if the operation cannot be scheduled at this time due to queue capacity restrictions.
      • schedule

        public void schedule​(Operation operation,
                             Duration delayTime,
                             boolean repeated)
        Schedules an operation for later, serial execution.
        Parameters:
        operation - The operation to schedule.
        delayTime - The delay past the scheduled time before the operation should begin (which may be 0).
        repeated - Whether this operation should be repeated.
        Throws:
        java.lang.NullPointerException - if the given operation and/or delay time is null.
        java.lang.IllegalStateException - if the operation cannot be scheduled at this time due to queue capacity restrictions.