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:
- By extending
ComponentHandlers(JComponentHandlersfor Java) abstract class and implement each handler. - By extending
DefaultComponentHandlers(JDefaultComponentHandlersfor Java) class and only override handlers those handlers which are needed to change.
Examples for case 1:
- Assembly/Scala
-
source
class AssemblyComponentHandlers(ctx: ActorContext[TopLevelActorMessage], cswCtx: CswContext) extends ComponentHandlers(ctx, cswCtx) - Assembly/Java
-
source
public 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
-
source
class HcdComponentHandlers(ctx: ActorContext[TopLevelActorMessage], cswCtx: CswContext) extends ComponentHandlers(ctx, cswCtx) - Hcd/Java
-
source
public 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
-
source
class TCSAssemblyCompHandlers(ctx: ActorContext[TopLevelActorMessage], cswCtx: CswContext) extends DefaultComponentHandlers(ctx, cswCtx) { - Assembly/Java
-
source
public 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
-
source
class TCSHcdCompHandlers(ctx: ActorContext[TopLevelActorMessage], cswCtx: CswContext) extends DefaultComponentHandlers(ctx, cswCtx) { - Hcd/Java
-
source
public 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(); }
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.*
A component can be created by a factory which extends the ComponentBehaviorFactory base class and provides a definition of the handlers method to return the appropriate implementation of ComponentHandlers.
- Assembly/Scala
-
source
class AssemblyComponentBehaviorFactory extends ComponentBehaviorFactory { protected override def handlers(ctx: ActorContext[TopLevelActorMessage], cswCtx: CswContext): ComponentHandlers = new AssemblyComponentHandlers(ctx, cswCtx) } - Assembly/Java
-
source
public class JAssemblyComponentBehaviorFactory extends JComponentBehaviorFactory { @Override public JComponentHandlers jHandlers(ActorContext<TopLevelActorMessage> ctx, JCswContext cswCtx) { return new JAssemblyComponentHandlers(ctx, cswCtx); } } - Hcd/Scala
-
source
class HcdComponentBehaviorFactory extends ComponentBehaviorFactory { protected override def handlers(ctx: ActorContext[TopLevelActorMessage], cswCtx: CswContext): ComponentHandlers = new HcdComponentHandlers(ctx, cswCtx) } - Hcd/Java
-
source
public class JHcdComponentBehaviorFactory extends JComponentBehaviorFactory { @Override public JComponentHandlers jHandlers(ActorContext<TopLevelActorMessage> ctx, JCswContext cswCtx) { return new JHcdComponentHandlers(ctx, cswCtx); } }