What is the behavior if I send a message to an Actor pool whose Actors then, upon receiving that message, send a message to self
? In this case, is sending to self
going to send messages to the pool, or to the specific Actor instance that sent the message?
Pseudocode of this scenario would look like the following
...
val system: ActorSystem = ActorSystem()
val actorPool: ActorRef = system.actorOf(
Props(new SomeActor(someDependency))
.withRouter(RoundRobinPool(conf.someActorPoolSize))
actorPool ! "hello"
class SomeActor(someDependency: SomeDependency) extends Actor {
def receive = {
case hello @ "hello" => self ! hello + " world"
// ^Does the above send to the entire Pool, or does this specific
// Actor just send the message directly to itself?
case msg @ "hello world" => println(msg)
// ^Do I know that the same Actor insntance that sent me "hello world"
// is also going to execute "println(msg)", or could any Actor in the
// Pool have sent the "hello world" message?
}
}
SomeActor
is the only type of Actor in the system. This helps clarify what the last code comment is asking. Ignore the fact thatsomeDependency
is never used - it's only there to more accurately reflect the actual code I have in my real application. – josiah