简体   繁体   English

Akka Java:使用带参数的构造函数创建一个actor

[英]Akka Java : create an actor with constructor taking parameters

How could i create an actor with a customized constructor in java ? 我如何在java中创建一个带有自定义构造函数的actor? I have searched through the documentation but didn't found it. 我搜索了文档,但没有找到它。

Here is my Actor: 这是我的演员:

public class ResizePhotoActor extends UntypedActor {

private int width;
private int height;
private String caption;

public ResizePhotoActor(int width, int height, String caption) {
    this.height = height;
    this.width = width;
    this.caption = caption;
}

public void onReceive(Object message) throws Exception {


}
}

I have tried this : 我试过这个:

        ActorRef imageActorRef = system.actorOf(
            Props.create(new ResizePhotoActor(1, 2, "")));

But it doesn't work. 但它不起作用。

Thank you 谢谢

ActorRef imageActorRef = system.actorOf(Props.create(ResizePhotoActor.class, 1, 2, ""));

文件: http//doc.akka.io/docs/akka/current/java/actors.html#Props

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM