Java 8(好吧,Groovy)在这里使用Akka com.typesafe.akka:akka-actor_2.11:2.5.4
。我试图创建一个创建/拥有/管理另一个角色(AppMaster
)的角色(StateChecker
)并计划发送此StateChecker
一条CheckState
消息每4秒钟一次:
class CheckState {}
class StateChecker extends AbstractActor {
// For this question, it really doesn't matter what this actor does
}
class AppMaster extends AbstractActor {
ActorRef stateChecker
@Override
Receive createReceive() {
receiveBuilder()
.match(Init, { message ->
stateChecker = context.actorOf(Props.create(StateChecker, "yes", 20), "state-checker")
FiniteDuration startDur = Duration.Zero()
FiniteDuration freqDur = Duration.create(4000, TimeUnit.MILLISECONDS)
CheckState checkState = new CheckState()
ExecutionContextExecutor executor = context.system().dispatcher()
context.system().scheduler().schedule(startDur, freqDur, stateChecker, checkState,
executor)
})
.build()
}
}
当我运行时,我得到以下异常:
groovy.lang.MissingMethodException: No signature of method: akka.actor.LightArrayRevolverScheduler.schedule() is applicable for argument types: (scala.concurrent.duration.FiniteDuration, scala.concurrent.duration.FiniteDuration, akka.actor.LocalActorRef, com.me.myapp.messages.CheckState, akka.dispatch.Dispatcher) values: [0 days, 4000 milliseconds, Actor[akka://myapp/user/myapp-master/o1-keeper#-1837899613], ...]
Possible solutions: schedule(scala.concurrent.duration.FiniteDuration, scala.concurrent.duration.FiniteDuration, java.lang.Runnable, scala.concurrent.ExecutionContext), schedule(scala.concurrent.duration.FiniteDuration, scala.concurrent.duration.FiniteDuration, scala.Function0, scala.concurrent.ExecutionContext), schedule(scala.concurrent.duration.FiniteDuration, scala.concurrent.duration.FiniteDuration, akka.actor.ActorRef, java.lang.Object, scala.concurrent.ExecutionContext, akka.actor.ActorRef)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
我在日志语句中添加了,并且在调度期间抛出了异常:
context.system().scheduler().schedule(startDur, freqDur, stateChecker, checkState,
executor)
知道我需要做些什么才能解决这个问题?由于这是我在Akka的Java API中遇到的问题,我做需要通过Java API获得答案。
答案 0 :(得分:1)
问题是您传递给#include <stdio.h>
int main()
{
const int i=1;
int a[i];
printf("Hello World");
return 0;
}
方法的参数不匹配该方法的重载版本。您可以在JavaDoc中看到schedule()
的重载版本的签名。
您尝试使用的版本是以下method:
schedule()
您错过了最后一个参数,即Cancellable schedule(scala.concurrent.duration.FiniteDuration initialDelay,
scala.concurrent.duration.FiniteDuration interval,
ActorRef receiver,
java.lang.Object message,
scala.concurrent.ExecutionContext executor,
ActorRef sender)
被指定为已安排消息的发件人。如果ActorRef
并不关心向谁发送StateChecker
消息,那么最简单的解决方法是将CheckState
作为最后一个参数传递:
null