I'm trying to forward a message (say, "msg") from one actor to another actor selected randomly.
It works perfectly fine unless the randomly picked actor is again one of the earlier actor. Scala waits indefinitely when such a scenario occurs. I want the program to pass the message irrespective of it receiving already (i.e., infinite looping of the message between the actors)
Actor A ---- msg ---> Actor B
Actor B ---- msg ---> Actor C
Actor C ---- msg ---> Actor A
After this, the program does not exit nor does it continue passing the message. Can you please point where i'm wrong?
class MyActor extends Actor {
def act() {
react{
case str : String =>
// Picking a random actor
val randNo : Int = Random.nextInt(5)
actorArray(randNo) ! str
}
}
}
Thanks, MS