Class KeyedSerialScheduler<Key>
java.lang.Object
com.inductiveautomation.eventstream.gateway.KeyedSerialScheduler<Key>
- Type Parameters:
Key- The type of the key used to identify and group tasks. Must implementObject.equals(Object)andObject.hashCode()and ideallyObject.toString()for logging purposes.
The KeyedSerialScheduler class is a utility designed to manage the scheduling and execution
of tasks associated with distinct keys. It ensures that tasks tied to a particular key
are executed in FIFO order. This class supports concurrent scheduling and handles task
synchronization internally. Concurrency is determined by the ExecutorService provided.
Tasks scheduled after shutdown will throw an IllegalStateException.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThrows an IllegalStateException if the current thread is not executing a task.schedule(Key key, KeyedSerialScheduler.Task task) Schedules a task for execution.voidshutdown()Waits for all tasks to complete and shuts down the scheduler.
-
Constructor Details
-
KeyedSerialScheduler
-
-
Method Details
-
schedule
Schedules a task for execution. If no tasks are currently scheduled for the given key, the task will be executed immediately. Otherwise, the task will be queued and executed when the current task completes. -
shutdown
public void shutdown()Waits for all tasks to complete and shuts down the scheduler. Any tasks scheduled after shutdown will throw an IllegalStateException. -
requireInQueue
public void requireInQueue()Throws an IllegalStateException if the current thread is not executing a task.
-