I'm trying to write an actor called ActorManager
which wraps another actor called RealActor
. The idea is that the ActorManager
can process all messages going in and out of RealActor
, allowing to add additional logic like filtering or buffering. The outside world is supposed to communicate with the RealActor
only through its manager, much like in real world.
A first draft would 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 */ }
}
}
This however raises the question how to construct both actors at once, or more specifically how to define the corresponding Props
given the circular dependency of the two actors. I'm not sure if the general lazy val
pattern is applicable when defining Props
.
I also would like to avoid the work-around of constructing one of the two first, combined with introducing an explicit Register
protocol to connect them.