I am trying to write an actor called ActorManagerthat wraps another actor called RealActor. The idea is that it ActorManagercan handle all messages coming in and out RealActor, which allows you to add additional logic, such as filtering or buffering. It is assumed that the outside world should communicate with RealActoronly through its manager, as in the real world.
The first draft will look like this:
class ActorManager(realActor: ActorRef) extends Actor {
def receive = {
case _ => { /* pre-process messages */ }
}
}
class RealActor(actorManager: ActorRef) extends Actor {
def receive = {
case _ => { /* actual business logic */ }
}
}
However, this raises the question of how to build both participants at once, or, more specifically, how to determine the appropriate one Propstaking into account the circular dependence of the two participants. I am not sure if a generic template islazy val applicable in the definition Props.
, Register .