Reputation: 1212
I have two classes A, B both extends untypedActor and i created another actor C to watch these two actors by using getContext().watch(actorRef of A/b), when any of those those two actors A,B is terminated i am getting a Terminated message to C on which i have to restart it after some task depending on which actor terminated is either A or B.
How can i know which actor is terminated by any method like
if(terminatedActor instanceOf A){
// Do task on termination of A
// create A
}else if(terminatedActor instanceOf B ){
// Do task on termination of B
// create B
}
Upvotes: 0
Views: 689
Reputation: 1212
I need to monitor only 2-3 types of actor, so i implemented different monitor for each of these types.
Upvotes: 0
Reputation: 1761
As the ActorRef is just a proxy to the implementation it doesn't give you the information you need.
The way I manage this is to store a reference to the actors I create in the supervisor which indicates the type. There are various ways you could do this, one approach I've used is to store the ActorRef's in a Map. You can then use the Terminated ActorRef to get the value from the Map that tells you what type it was. Alternatively just create internal properties on the UntypedActor to hold the refs then check one until you find a match and recreate it.
Upvotes: 2