Constructor for CloudOrchestrationActor. Initializes the actor with given logic and options. The constructor also configures an inspection handler to process machine snapshots, which is crucial for capturing state changes and orchestrating corresponding cloud events.
The logic instance that dictates the behavior of the actor.
Optional. Configuration options for the actor. These options include custom middleware for cloud event processing, and an optional snapshot for state restoration.
Private
_idOptional
_parentOptional
_syncThe clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.
The unique identifier for this actor relative to its parent.
The logic instance that dictates the behavior of the actor.
Private
middlewareOptional. Configuration options for the actor. These options include custom middleware for cloud event processing, and an optional snapshot for state restoration.
Private
orchestrationThe globally unique process ID for this invocation.
Private
stateThe system to which this actor belongs.
Getter method that provides the list of orchestrated CloudEvents. These events are ready to be emitted and typically represent the actor's response to state changes or external inputs.
An array of CloudEvents that have been prepared for emission, based on the actor's logic and state.
Processes a CloudEvent and dispatches it as an actor event. This method applies any configured middleware to transform the CloudEvent before sending it to the actor's internal state machine. This is essential for integrating external cloud events into the actor's workflow.
The CloudEvent to be processed. It must be a structured cloudevent, see. That is, it must of of type CloudEvent<Record<string, any>> and it must be a JSON event.
Error - Throws an error if the 'datacontenttype' of the CloudEvent is not valid, or if the 'statemachineversion' specified in the CloudEvent does not match the actor's state machine version. The error message provides details about the nature of the validation failure.
Obtain the internal state of the actor, which can be persisted.
The internal state can be persisted from any actor, not only machines.
Note that the persisted state is not the same as the snapshot from Actor.getSnapshot. Persisted state represents the internal state of the actor, while snapshots represent the actor's last emitted value.
Can be restored with ActorOptions.state
Read an actor’s snapshot synchronously.
The snapshot represent an actor's last emitted value.
When an actor receives an event, its internal state may change. An actor may emit a snapshot when a state transition occurs.
Note that some actors, such as callback actors generated with fromCallback
, will not emit snapshots.
Private
processProcesses a snapshot of the actor's state machine. This method is responsible for extracting relevant information from the snapshot, determining the appropriate cloud orchestration events, and queuing them for emission. It is typically triggered in response to state changes in the actor.
The snapshot of the state machine, providing a complete picture of the current state.
Sends an event to the running Actor to trigger a transition.
The event to send
Subscribe an observer to an actor’s snapshot values.
Either a plain function that receives the latest snapshot, or an observer object whose .next(snapshot)
method receives the latest snapshot
The observer will receive the actor’s snapshot value when it is emitted. The observer can be:
.next(snapshot)
method receives the latest snapshot// Observer as a plain function
const subscription = actor.subscribe((snapshot) => {
console.log(snapshot);
});
// Observer as an object
const subscription = actor.subscribe({
next(snapshot) {
console.log(snapshot);
},
error(err) {
// ...
},
complete() {
// ...
},
});
The return value of actor.subscribe(observer)
is a subscription object that has an .unsubscribe()
method. You can call subscription.unsubscribe()
to unsubscribe the observer:
const subscription = actor.subscribe((snapshot) => {
// ...
});
// Unsubscribe the observer
subscription.unsubscribe();
When the actor is stopped, all of its observers will automatically be unsubscribed.
Optional
nextListener: ((snapshot) => void)Optional
errorListener: ((error) => void)Optional
completeListener: (() => void)Generated using TypeDoc
A specialized Actor class designed for cloud orchestration scenarios. It extends the XState Actor class, incorporating cloud-related functionalities. This actor is capable of handling CloudEvents and orchestrating them based on its internal logic and state, using middleware for custom processing.