我的应用程序中有一个组件Processor.java
,它侦听来自外部源的事件。我想使用actor将这些事件传递到套接字。我有一个处理这些事件的actor类:
public class EventProcessor extends UntypedActor {
static ActorRef channel = Akka.system().actorOf(Props.create(EventProcessor.class));
public void onReceive(Object message) throws Exception {
// do stuff here
}
public void handleMessage(String event) {
// tell another actor to do stuff here
}
}
我希望能够在Process.java
中实例化类型为EventProcessor
的演员。现在,我有这个:
ActorRef act = Akka.system().actorOf(new Props(EventProcessor.class), null);
act.handleMessage(str);
我得到一个编译错误:
constructor Props in class akka.actor.Props cannot be applied to given types;
required: akka.actor.Deploy,java.lang.Class<?>,scala.collection.immutable.Seq<java.lang.Object>
found: java.lang.Class<models.EventProcessor>
reason: actual and formal argument lists differ in length
在我的例子中,在Akka中实例化actor的正确方法是什么?
将new Props(YourActor.class)
替换为Props.create(Actor.class)
。我有同样的编译错误,它为我工作。见http://doc.akka.io/api/akka/2.3.1/akka/actor/Props.html
final Props props = Props.create(MyActor.class, arg1, arg2);