Class OrchestratorEngine
java.lang.Object
com.iantapply.orchestra.engine.OrchestratorEngine
- All Implemented Interfaces:
AutoCloseable
Durable, at-least-once orchestration engine. Action implementations should use
ActionContext.idempotencyKey() when calling systems that support deduplication.-
Constructor Summary
ConstructorsConstructorDescriptionOrchestratorEngine(com.iantapply.orchestra.port.DefinitionRepository definitions, com.iantapply.orchestra.port.ExecutionRepository executions, com.iantapply.orchestra.port.DistributedLock locks, com.iantapply.orchestra.port.TargetResolver targets, ActionRegistry registry, Clock clock, int workerCount, int queueCapacity) Creates an engine with bounded worker concurrency and queue capacity.OrchestratorEngine(com.iantapply.orchestra.port.DefinitionRepository definitions, com.iantapply.orchestra.port.ExecutionRepository executions, com.iantapply.orchestra.port.DistributedLock locks, com.iantapply.orchestra.port.TargetResolver targets, ActionRegistry registry, Clock clock, EngineOptions options) Creates an engine with explicit operational timing and capacity options.OrchestratorEngine(com.iantapply.orchestra.port.DefinitionRepository definitions, com.iantapply.orchestra.port.ExecutionRepository executions, com.iantapply.orchestra.port.DistributedLock locks, com.iantapply.orchestra.port.TargetResolver targets, ActionRegistry registry, Clock clock, EngineOptions options, Consumer<String> failureCounter) Creates an engine whose operational failure paths increment named counters. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the number of workers currently executing a task.voidaddListener(com.iantapply.orchestra.api.EventLifecycleListener listener) Registers a lifecycle listener.booleanCancels an execution.voidclose()Stops polling and shuts down engine workers.booleanPauses an execution.intReturns the number of execution tasks currently waiting for a worker.voidrecover()Immediately scans persisted state; called on startup to recover interrupted work.booleanResumes an execution.booleanReschedules a failed execution from its first stage.Creates a durable execution for a known definition.booleansetVariable(UUID id, String key, Object value) Atomically sets or removes an execution variable.voidstart()Starts the due-execution polling loop once.Schedules an event immediately with no initial variables.
-
Constructor Details
-
OrchestratorEngine
public OrchestratorEngine(com.iantapply.orchestra.port.DefinitionRepository definitions, com.iantapply.orchestra.port.ExecutionRepository executions, com.iantapply.orchestra.port.DistributedLock locks, com.iantapply.orchestra.port.TargetResolver targets, ActionRegistry registry, Clock clock, int workerCount, int queueCapacity) Creates an engine with bounded worker concurrency and queue capacity.- Parameters:
definitions- event definition storeexecutions- durable execution storelocks- distributed execution lease providertargets- target resolverregistry- action and condition registryclock- engine clockworkerCount- number of concurrent execution workersqueueCapacity- maximum queued execution tasks
-
OrchestratorEngine
public OrchestratorEngine(com.iantapply.orchestra.port.DefinitionRepository definitions, com.iantapply.orchestra.port.ExecutionRepository executions, com.iantapply.orchestra.port.DistributedLock locks, com.iantapply.orchestra.port.TargetResolver targets, ActionRegistry registry, Clock clock, EngineOptions options) Creates an engine with explicit operational timing and capacity options.- Parameters:
definitions- event definition storeexecutions- durable execution storelocks- distributed execution lease providertargets- target resolverregistry- action and condition registryclock- engine clockoptions- operational timing and capacity options
-
OrchestratorEngine
public OrchestratorEngine(com.iantapply.orchestra.port.DefinitionRepository definitions, com.iantapply.orchestra.port.ExecutionRepository executions, com.iantapply.orchestra.port.DistributedLock locks, com.iantapply.orchestra.port.TargetResolver targets, ActionRegistry registry, Clock clock, EngineOptions options, Consumer<String> failureCounter) Creates an engine whose operational failure paths increment named counters.- Parameters:
definitions- event definition storeexecutions- durable execution storelocks- distributed execution lease providertargets- target resolverregistry- action and condition registryclock- engine clockoptions- operational timing and capacity optionsfailureCounter- consumer of metric names for failures and rejected work
-
-
Method Details
-
start
public void start()Starts the due-execution polling loop once. -
schedule
Creates a durable execution for a known definition.- Parameters:
definitionId- event definition identifierstartAt- requested start timevariables- initial execution variables- Returns:
- new execution identifier
-
startNow
-
addListener
public void addListener(com.iantapply.orchestra.api.EventLifecycleListener listener) Registers a lifecycle listener.- Parameters:
listener- lifecycle listener retained until the engine closes
-
pause
Pauses an execution.- Parameters:
id- execution identifier- Returns:
- whether the execution was found and atomically paused
-
resume
Resumes an execution.- Parameters:
id- execution identifier- Returns:
- whether the execution was found and atomically resumed
-
cancel
Cancels an execution.- Parameters:
id- execution identifier- Returns:
- whether the execution was found and atomically cancelled
-
retry
Reschedules a failed execution from its first stage.- Parameters:
id- execution identifier- Returns:
- whether the failed execution was atomically rescheduled
-
setVariable
-
recover
public void recover()Immediately scans persisted state; called on startup to recover interrupted work. -
queuedTaskCount
public int queuedTaskCount()Returns the number of execution tasks currently waiting for a worker.- Returns:
- queued task count
-
activeWorkerCount
public int activeWorkerCount()Returns the number of workers currently executing a task.- Returns:
- active worker count
-
close
public void close()Stops polling and shuts down engine workers.- Specified by:
closein interfaceAutoCloseable
-