Akka Java : create an actor with constructor takin

2020-08-12 18:27发布

问题:

How could i create an actor with a customized constructor in java ? 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

回答1:

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

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



标签: java akka