我正在创建一个像:
这样的演员 mySupervisor = actorSys.actorOf(Props.create(MyActor.class, createProperties()));
public MyProperties createProperties(){
MyProperties mp = new MyProperties();
mp.setParam1("test1");
mp.setParam2("test2");
return mp;
}
public class MyProperties {
private String param1;
private String param2;
public String getParam1() {
return param1;
}
public void setParam1(String param1) {
this.param1 = param1;
}
public String getParam2() {
return param2;
}
public void setParam2(String param2) {
this.param2 = param2;
}
}
MyActor:
public class MyActor extends UntypedActor{
private MyProperties props;
@Override
public void onReceive(Object argMessage) throws Exception {
if(argMessage instanceof MyProperties ){
this.props = (MyProperties) argMessage;
}
ActorRef newActor = getContext().actorOf(Props.create(NewActor.class, this.props));
newActor.tell(.... do some work)
}
}
MyProperties对象可以在运行时更改,因为它是从外部配置文件填充的,所以要使用我使用的这些属性更新actor MyActor:
mySupervisor.tell(createProperties(), mySupervisor);
测试此行为符合预期,因为mySupervisor
创建的新actor包含正确的属性,但这是实现此目的的正确方法吗? :调用mySupervisor
上的tell方法传递MyProperties
的新实例并传入mySupervisor
引用?