Java 初始化Akka中的演员,播放2.4.2
我的应用程序有一个组件,Java 初始化Akka中的演员,播放2.4.2,java,playframework-2.0,akka,Java,Playframework 2.0,Akka,我的应用程序有一个组件,Processor.java,它监听来自外部源的事件。我想使用参与者将这些事件传递到套接字中。我有一类处理这些事件的演员: public class EventProcessor extends UntypedActor { static ActorRef channel = Akka.system().actorOf(Props.create(EventProcessor.class)); public void onReceive(Object m
Processor.java
,它监听来自外部源的事件。我想使用参与者将这些事件传递到套接字中。我有一类处理这些事件的演员:
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.Props类中的构造函数Props不能应用于给定类型;
必需:akka.actor.Deploy、java.lang.Class、scala.collection.immutable.Seq
找到:java.lang.Class
原因:实际参数列表和正式参数列表长度不同
在我的例子中,在Akka中实例化演员的正确方法是什么 用Props.create(Actor.class)
替换新道具(YourActor.class)
。
我有同样的编译错误,它对我有效。
看
final Props props = Props.create(MyActor.class, arg1, arg2);