Class CloudOrchestrationActor<TLogic>

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.

Type Parameters

  • TLogic extends AnyActorLogic

Hierarchy

  • Actor<TLogic>
    • CloudOrchestrationActor

Constructors

  • 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.

    Type Parameters

    • TLogic extends AnyActorLogic

    Parameters

    • logic: TLogic

      The logic instance that dictates the behavior of the actor.

    • options: CloudOrchestrationActorOptions<TLogic>

      Optional. Configuration options for the actor. These options include custom middleware for cloud event processing, and an optional snapshot for state restoration.

    Returns CloudOrchestrationActor<TLogic>

Properties

_id: string
_parent?: ActorRef<any, any>
_syncSnapshot?: boolean
clock: Clock

The clock that is responsible for setting and clearing timeouts, such as delayed events and transitions.

id: string

The unique identifier for this actor relative to its parent.

logic: TLogic

The logic instance that dictates the behavior of the actor.

middleware: undefined | CloudOrchestrationMiddlewares

Optional. Configuration options for the actor. These options include custom middleware for cloud event processing, and an optional snapshot for state restoration.

orchestrationEvents: CloudEvent<Record<string, any>>[] = []
ref: ActorRef<SnapshotFrom<TLogic>, EventFromLogic<TLogic>>
sessionId: string

The globally unique process ID for this invocation.

src: string | AnyActorLogic
stateMachineVersion: `${number}.${number}.${number}`
system: AnyActorSystem

The system to which this actor belongs.

Accessors

  • get eventsToEmit(): CloudEvent<Record<string, any>>[]
  • 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.

    Returns CloudEvent<Record<string, any>>[]

    An array of CloudEvents that have been prepared for emission, based on the actor's logic and state.

Methods

  • Returns InteropSubscribable<SnapshotFrom<TLogic>>

  • 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.

    Parameters

    • event: CloudEvent<Record<string, any>>

      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.

    Returns void

    Throws

    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.

    Returns Snapshot<unknown>

    Remarks

    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

    See

    https://stately.ai/docs/persistence

  • Read an actor’s snapshot synchronously.

    Returns SnapshotFrom<TLogic>

    Remarks

    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.

    See

    • Actor.subscribe to subscribe to an actor’s snapshot values.
    • Actor.getPersistedSnapshot to persist the internal state of an actor (which is more than just a snapshot).
  • Processes 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.

    Parameters

    • pathsToUpdate: string[]
    • snapshot: AnyMachineSnapshot

      The snapshot of the state machine, providing a complete picture of the current state.

    Returns void

  • Sends an event to the running Actor to trigger a transition.

    Parameters

    • event: EventFromLogic<TLogic>

      The event to send

    Returns void

  • Starts the Actor from the initial state

    Returns this

  • Stops the Actor and unsubscribe all listeners.

    Returns this

  • Subscribe an observer to an actor’s snapshot values.

    Parameters

    • observer: Observer<SnapshotFrom<TLogic>>

      Either a plain function that receives the latest snapshot, or an observer object whose .next(snapshot) method receives the latest snapshot

    Returns Subscription

    Remarks

    The observer will receive the actor’s snapshot value when it is emitted. The observer can be:

    • A plain function that receives the latest snapshot, or
    • An observer object whose .next(snapshot) method receives the latest snapshot

    Example

    // Observer as a plain function
    const subscription = actor.subscribe((snapshot) => {
    console.log(snapshot);
    });

    Example

    // 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:

    Example

    const subscription = actor.subscribe((snapshot) => {
    // ...
    });

    // Unsubscribe the observer
    subscription.unsubscribe();

    When the actor is stopped, all of its observers will automatically be unsubscribed.

  • Parameters

    • Optional nextListener: ((snapshot) => void)
        • (snapshot): void
        • Parameters

          • snapshot: SnapshotFrom<TLogic>

          Returns void

    • Optional errorListener: ((error) => void)
        • (error): void
        • Parameters

          • error: any

          Returns void

    • Optional completeListener: (() => void)
        • (): void
        • Returns void

    Returns Subscription

  • Returns {
        id: string;
        xstate$$type: number;
    }

    • id: string
    • xstate$$type: number

Generated using TypeDoc