我在Java中使用Akka型演员。我有一个BatchManager
是与控制器的接口,还有一个JobManager
可创建一些工作程序并执行作业。 JobManager看起来像
interface JobManager {
public Future<String> execute();
public Future<AwaitableBatchStatusResponse> awaitCompletion();
public Future<BatchStatusResponse> getStatus();
public Future<String> reloadFailures();
public void jobComplete(JobMessage message);
}
其中
Future
是scala.concurrent.Future
。实现类会覆盖所有这些方法,尤其是class JobManagerImpl implements JobManager {
public JobManagerImpl() {
System.out.println("JobManagerImpl constructor start");
// do some stuff
System.out.println("JobMangerImpl constructor end");
}
@Override
public Future<String> execute() {
System.out.println("start execute on jobmanager");
// do some stuff
System.out.println("end execute in jobmanager");
return Futures.successful("blah");
}
}
JobManager
正在成功构造(在我要在构造函数末尾打印“ JobMangerImpl构造函数末尾”的情况下)。但是,BatchManager
然后在新的execute
上调用JobManager
,并被告知消息将变为死信(以及线程标题中的错误-堆栈跟踪在下面)。 JobManagerImpl#execute中的我的printlns没有被运行。Enqueue job: d90c4d58-3142-48cd-8f3e-96e75d4ca7d1
Execute job: d90c4d58-3142-48cd-8f3e-96e75d4ca7d1
start create job manager in poll
JobManagerImpl constructor start : d90c4d58-3142-48cd-8f3e-96e75d4ca7d1
JobMangerImpl constructor end
end create jobManager in poll
begin execute in batchmanager
end execute in batchmanager
JobManagerImpl constructor start : d90c4d58-3142-48cd-8f3e-96e75d4ca7d1
JobMangerImpl constructor end
[INFO] [07/15/2015 15:36:07.088] [PerformanceAsync-akka.actor.default-dispatcher-10] [akka://PerformanceAsync/deadLetters] Message [java.lang.String] from Actor[akka://PerformanceAsync/user/StandardJobManager#1902186473] to Actor[akka://PerformanceAsync/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[ERROR] [07/15/2015 15:36:07.089] [PerformanceAsync-akka.actor.default-dispatcher-8] [akka://PerformanceAsync/user/StandardJobManager/StandardJobManager:d90c4d58-3142-48cd-8f3e-96e75d4ca7d1:JobManager] Class akka.actor.TypedActor$MethodCall can not access a member of class com.async.JobManager with modifiers "public abstract"
java.lang.IllegalAccessException: Class akka.actor.TypedActor$MethodCall can not access a member of class com.async.JobManager with modifiers "public abstract"
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:101)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:295)
at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:287)
at java.lang.reflect.Method.invoke(Method.java:476)
at akka.actor.TypedActor$MethodCall.apply(TypedActor.scala:145)
at akka.actor.TypedActor$TypedActor$$anonfun$receive$1$$anonfun$applyOrElse$2.apply(TypedActor.scala:311)
at akka.actor.TypedActor$TypedActor.withContext(TypedActor.scala:299)
at akka.actor.TypedActor$TypedActor$$anonfun$receive$1.applyOrElse(TypedActor.scala:306)
at akka.actor.Actor$class.aroundReceive(Actor.scala:465)
at akka.actor.TypedActor$TypedActor.aroundReceive(TypedActor.scala:246)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:516)
at akka.actor.ActorCell.invoke(ActorCell.scala:487)
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:238)
at akka.dispatch.Mailbox.run(Mailbox.scala:220)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
我很困惑-我已经用公共方法覆盖了所有
JobManager
方法,那么Akka为什么无法访问它们? 最佳答案
看来问题是我在JobManagerImpl
的静态内部类中创建了BatchManagerImpl
-此内部类处于一种奇怪的困境中,其中TypedActor.get(TypedActor.context())
不会在a之外使用该异常TypedActor上下文,但是以这种方式实例化的任何内容在内部均已损坏。