Akka Java:使用带有参数的构造函数创建一个actor [英] Akka Java : create an actor with constructor taking parameters
本文介绍了Akka Java:使用带有参数的构造函数创建一个actor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Java中使用自定义构造函数创建actor?我已经搜索了文档,但没有找到它。
How could i create an actor with a customized constructor in java ? I have searched through the documentation but didn't found it.
这是我的演员:
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 {
}
}
我已经尝试过:
ActorRef imageActorRef = system.actorOf(
Props.create(new ResizePhotoActor(1, 2, "")));
但这不起作用。
谢谢
推荐答案
ActorRef imageActorRef = system.actorOf(Props.create(ResizePhotoActor.class, 1, 2, ""));
文档: http://doc.akka.io/docs/akka/current/java/actors.html#Props
这篇关于Akka Java:使用带有参数的构造函数创建一个actor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文