Package com.globalmentor.model
Class OperationManager
- java.lang.Object
-
- com.globalmentor.model.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 usingRunnable.run()
.- Author:
- Garret Wilson
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
OperationManager.ScheduledOperation
Encapsulates an operation that has been scheduled, along with any delay or repeat.static class
OperationManager.ScheduledOperationWorker
Worker for processing scheduled operations.
-
Constructor Summary
Constructors Constructor Description OperationManager()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.Thread
getExecutionThread()
protected java.util.concurrent.BlockingQueue<OperationManager.ScheduledOperation>
getScheduledOperationQueue()
protected java.lang.Runnable
getScheduledOperationWorker()
void
schedule(Operation operation)
Schedules an operation for later, serial execution once with no delay.void
schedule(Operation operation, boolean repeated)
Schedules an operation for later, serial execution with no delay.void
schedule(Operation operation, Duration delayTime)
Schedules an operation for later, serial execution once with the given delay.void
schedule(Operation operation, Duration delayTime, boolean repeated)
Schedules an operation for later, serial execution.
-
-
-
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 isnull
.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 isnull
.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 isnull
.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 isnull
.java.lang.IllegalStateException
- if the operation cannot be scheduled at this time due to queue capacity restrictions.
-
-