blue-sky
blue-sky

Reputation: 53866

How to update properties of child actors from supervisor?

I'm using akka to create a supervisor :

mySupervisor = actorSys.actorOf(Props.create(MyActor.class, MyProperties()));

class MyProperties(){

    String param1;
    String param2;

    //param1 & param2 are set in a configuration file
}

Since creating a supervisor from the ActorSystem is expensive I'm just doing this once. I'm using the class MyProperties in order to access various parameters that are required within the actor. I do not want to add the logic for setting the propertes to the actor itself so the actor has little work to perform as possible and the usually these peoperties will not change. But when the properties do change how can I update the child actors of the supervisor ? I do not think I can change the state of mySupervisor (since immutable) so does this mean I will need to create a new supervisor with the new properties configuration ?

Upvotes: 1

Views: 197

Answers (1)

Ryan
Ryan

Reputation: 7247

You should never never ever ever ever ever change the state of an actor with anything except a message sent to that actor.

If you need to change the properties of a child actor, you can:

  • Kill the actor and create a replacement with the new properties
  • Send a message to the actor with new properties

In addition, messages sent to an actor should be immutable (final String param1). If you need to access an actor's internal state, you should send that actor a message asking for it and then have the actor reply to that request with whatever (immutable) state is needed.

Upvotes: 4

Related Questions