Class OrchestratorEngine

java.lang.Object
com.iantapply.orchestra.engine.OrchestratorEngine
All Implemented Interfaces:
AutoCloseable

public final class OrchestratorEngine extends Object implements AutoCloseable
Durable, at-least-once orchestration engine. Action implementations should use ActionContext.idempotencyKey() when calling systems that support deduplication.
  • Constructor Details

    • OrchestratorEngine

      public OrchestratorEngine(DefinitionRepository definitions, ExecutionRepository executions, DistributedLock locks, TargetResolver targets, ActionRegistry registry, Clock clock, int workerCount, int queueCapacity)
      Creates an engine with bounded worker concurrency and queue capacity.
      Parameters:
      definitions - event definition store
      executions - durable execution store
      locks - distributed execution lease provider
      targets - target resolver
      registry - action and condition registry
      clock - engine clock
      workerCount - number of concurrent execution workers
      queueCapacity - maximum queued execution tasks
  • Method Details

    • start

      public void start()
      Starts the due-execution polling loop once.
    • schedule

      public UUID schedule(String definitionId, Instant startAt, Map<String,Object> variables)
      Creates a durable execution for a known definition.
      Parameters:
      definitionId - event definition identifier
      startAt - requested start time
      variables - initial execution variables
      Returns:
      new execution identifier
    • startNow

      public UUID startNow(String definitionId)
      Schedules an event immediately with no initial variables.
      Parameters:
      definitionId - event definition to schedule immediately
      Returns:
      new execution identifier
    • addListener

      public void addListener(EventLifecycleListener listener)
      Registers a lifecycle listener.
      Parameters:
      listener - lifecycle listener retained until the engine closes
    • pause

      public boolean pause(UUID id)
      Pauses an execution.
      Parameters:
      id - execution identifier
      Returns:
      whether the execution was found and atomically paused
    • resume

      public boolean resume(UUID id)
      Resumes an execution.
      Parameters:
      id - execution identifier
      Returns:
      whether the execution was found and atomically resumed
    • cancel

      public boolean cancel(UUID id)
      Cancels an execution.
      Parameters:
      id - execution identifier
      Returns:
      whether the execution was found and atomically cancelled
    • retry

      public boolean retry(UUID id)
      Reschedules a failed execution from its first stage.
      Parameters:
      id - execution identifier
      Returns:
      whether the failed execution was atomically rescheduled
    • setVariable

      public boolean setVariable(UUID id, String key, Object value)
      Atomically sets or removes an execution variable.
      Parameters:
      id - execution identifier
      key - variable name
      value - new value, or null to remove it
      Returns:
      whether the update succeeded
    • recover

      public void recover()
      Immediately scans persisted state; called on startup to recover interrupted work.
    • close

      public void close()
      Stops polling and shuts down engine workers.
      Specified by:
      close in interface AutoCloseable