Publishing State

A component has access to a currentStatePublisher Actor, which can be used to publish its CurrentState. Any subscriber of this component will receive the published state.

Note

This feature is provided for optimized communication between an Assembly and an HCD only. See Matching state for command completion.

CurrentState can be used in a number of ways. Two use cases are:

  1. An HCD can have detailed information that it publishes for its Assemblies periodically. The Assemblies use the CurrentState information to create events that describe the state of the Assembly and HCD.
  2. ‘CurrentState’ information published by the HCD can be used by an Assembly to complete commands that have been submitted to the Assembly.

The CommandService shows examples of the use of CurrentState for the second use case. See Matching state for command completion.

A subscriber can subscribe to all CurrentState published by an HCD or to specific CurrentState specified by its StateName. The publisher does not need to do anything special to support these features.

Scala
source// Publish the CurrentState using parameter set created using a sample Choice parameter
currentStatePublisher.publish(CurrentState(filterAsmPrefix, StateName("testStateName"), Set(choiceKey.set(initChoice))))
Java
sourceCurrentState initState = currentState.add(SampleComponentState.choiceKey().set(SampleComponentState.initChoice()));
currentStatePublisher.publish(initState);
Key<Integer> encoder = JKeyType.IntKey().make("encoder", JUnits.encoder);
int expectedEncoderValue = setup.jGet(encoder).orElseThrow().head();

CurrentState currentState = new CurrentState(prefix(), new StateName("HCDState")).add(encoder.set(expectedEncoderValue));
currentStatePublisher.publish(currentState);