Creating an Assembly or Hcd Component

To create a component(Assembly or HCD), ComponentHandlers are needed. These handlers are executed by an Akka Actor (Top Level Actor or TLA) defined in the framework which handles the lifecycle and supervision of each component.

There are two ways to create ComponentHandlers:

  1. By extending ComponentHandlers(JComponentHandlers for Java) abstract class and implement each handler.
  2. By extending DefaultComponentHandlers(JDefaultComponentHandlers for Java) class and only override handlers those handlers which are needed to change.

Examples for case 1:

Assembly/Scala
sourceclass AssemblyComponentHandlers(ctx: ActorContext[TopLevelActorMessage], cswCtx: CswContext)
    extends ComponentHandlers(ctx, cswCtx)
Assembly/Java
sourcepublic class JAssemblyComponentHandlers extends JComponentHandlers {

    private final ActorContext<TopLevelActorMessage> ctx;
    private final ComponentInfo componentInfo;
    private final CurrentStatePublisher currentStatePublisher;
    private final CommandResponseManager commandResponseManager;
    private final ILocationService locationService;
    private final IEventService eventService;
    private final ILogger log;
    private final IConfigClientService configClient;
    private final Map<Connection, Optional<ICommandService>> runningHcds;
    private ActorRef<DiagnosticPublisherMessages> diagnosticPublisher;
    private ActorRef<CommandResponse.SubmitResponse> commandResponseAdapter;

    private final int timeout = 10;
    private final TimeUnit timeUnit = TimeUnit.SECONDS;

    public JAssemblyComponentHandlers(akka.actor.typed.javadsl.ActorContext<TopLevelActorMessage> ctx, JCswContext cswCtx) {
        super(ctx, cswCtx);
        this.ctx = ctx;
        this.componentInfo = cswCtx.componentInfo();
        this.commandResponseManager = cswCtx.commandResponseManager();
        this.currentStatePublisher = cswCtx.currentStatePublisher();
        this.locationService = cswCtx.locationService();
        this.eventService = cswCtx.eventService();
        log = cswCtx.loggerFactory().getLogger(this.getClass());
        configClient = JConfigClientFactory.clientApi(ctx.getSystem(), locationService);

        runningHcds = new HashMap<>();
        commandResponseAdapter = TestProbe.<CommandResponse.SubmitResponse>create(ctx.getSystem()).ref();
        commandResponseAdapter = TestProbe.<CommandResponse.SubmitResponse>create(ctx.getSystem()).ref();
    }
Hcd/Scala
sourceclass HcdComponentHandlers(ctx: ActorContext[TopLevelActorMessage], cswCtx: CswContext)
    extends ComponentHandlers(ctx, cswCtx)
Hcd/Java
sourcepublic class JHcdComponentHandlers extends JComponentHandlers {

    private final ActorContext<TopLevelActorMessage> ctx;
    private final ComponentInfo componentInfo;
    private final CommandResponseManager commandResponseManager;
    private final CurrentStatePublisher currentStatePublisher;
    private final ILocationService locationService;
    private final IEventService eventService;
    private final ILogger log;
    private IConfigClientService configClient;
    private ConfigData hcdConfig;
    private ActorRef<WorkerActorMsg> worker;
    private int current;
    private int stats;
    private final int timeout = 10;
    private final TimeUnit timeUnit = TimeUnit.SECONDS;

    public JHcdComponentHandlers(
            akka.actor.typed.javadsl.ActorContext<TopLevelActorMessage> ctx,
            JCswContext cswCtx
    ) {
        super(ctx, cswCtx);
        this.ctx = ctx;
        this.componentInfo = cswCtx.componentInfo();
        this.commandResponseManager = cswCtx.commandResponseManager();
        this.currentStatePublisher = cswCtx.currentStatePublisher();
        this.locationService = cswCtx.locationService();
        this.eventService = cswCtx.eventService();
        log = cswCtx.loggerFactory().getLogger(this.getClass());
    }

Examples for case 2:

Assembly/Scala
sourceclass TCSAssemblyCompHandlers(ctx: ActorContext[TopLevelActorMessage], cswCtx: CswContext)
    extends DefaultComponentHandlers(ctx, cswCtx) {
Assembly/Java
sourcepublic class JTCSAssemblyCompHandlers extends JDefaultComponentHandlers {

    private final CommandResponseManager commandResponseManager;
    private final TimeServiceScheduler timeServiceScheduler;

    public JTCSAssemblyCompHandlers(ActorContext<TopLevelActorMessage> ctx, JCswContext cswCtx) {
        super(ctx, cswCtx);
        this.commandResponseManager = cswCtx.commandResponseManager();
        this.timeServiceScheduler = cswCtx.timeServiceScheduler();
    }
Hcd/Scala
sourceclass TCSHcdCompHandlers(ctx: ActorContext[TopLevelActorMessage], cswCtx: CswContext)
    extends DefaultComponentHandlers(ctx, cswCtx) {
Hcd/Java
sourcepublic class JTCSHcdCompHandlers extends JDefaultComponentHandlers {

    private final CommandResponseManager commandResponseManager;
    private final TimeServiceScheduler timeServiceScheduler;

    public JTCSHcdCompHandlers(ActorContext<TopLevelActorMessage> ctx, JCswContext cswCtx) {
        super(ctx, cswCtx);
        this.commandResponseManager = cswCtx.commandResponseManager();
        this.timeServiceScheduler = cswCtx.timeServiceScheduler();
    }
Note

Converting a typed actor system to an untyped actor system

The ctx available to the component is of type akka.actor.typed.scaladsl.ActorContext in Scala or akka.actor.typed.javadsl.ActorContext in Java. This context can be used to get resources such as an actor system which is also typed. In order to get the untyped version of an actor system or actor references, Akka has provided some implicit extension methods in Scala and static methods in Java which can be used by adding the following import:

  • Scala: import akka.actor.typed.scaladsl.adapter._
  • Java: import akka.actor.typed.javadsl.Adapter.*