使用新属性文件调用actor的tell

时间:2014-04-05 19:28:47

标签: scala akka

我正在创建一个像:

这样的演员
 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引用?

0 个答案:

没有答案