Sounds like a good use case of message adapter. Something like this:
object DetectorStateMachine {
import ServerMonitoring._
trait Command
private case class ServerHealthKafkaWrapper(kafka: ServerHealthKafka) extends Command
private case class ServerHealthSapWrapper(kafka: ServerHealthSap) extends Command
case class State(kafka: ServerHealthKafka, sap: ServerHealthSap)
def create(informant: ActorRef[InformantEvent]): Behavior[Command] =
Behaviors.setup { context =>
context.log.info(s"=============> Start DetectorStateMachine <=============")
val kafkaAdapter: ActorRef[ServerHealthKafka] =
context.messageAdapter[ServerHealthKafka](ServerHealthKafkaWrapper.apply)
val sapAdapter: ActorRef[ServerHealthSap] =
context.messageAdapter[ServerHealthSap](ServerHealthSapWrapper.apply)
// TODO: initiate the interaction with Kafka using the `kafkaAdapter` as `replyTo`
// TODO: initiate the interaction with SAP using the `sapAdapter` as `replyTo`
def loop(state: State): Behavior[Command] = {
Behaviors.receiveMessage {
case ServerHealthKafkaWrapper(KafkaActiveConfirmed) =>
loop(state.copy(kafka = KafkaActiveConfirmed))
case ServerHealthKafkaWrapper(KafkaInactiveConfirmed) =>
loop(state.copy(kafka = KafkaInactiveConfirmed))
case ServerHealthSapWrapper(SapActiveConfirmed) =>
loop(state.copy(sap = SapActiveConfirmed))
case ServerHealthSapWrapper(SapInactiveConfirmed) =>
loop(state.copy(sap = SapInactiveConfirmed))
}
}
loop(State(KafkaInactiveConfirmed, SapInactiveConfirmed))
}
}