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 implement Object.equals(Object) and Object.hashCode() and ideally Object.toString() for logging purposes.

public class KeyedSerialScheduler<Key> extends Object
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.
  • Constructor Details

    • KeyedSerialScheduler

      public KeyedSerialScheduler(ExecutorService executor)
  • Method Details

    • schedule

      public CompletableFuture<Void> schedule(Key key, KeyedSerialScheduler.Task task)
      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.