我在Java中使用Akka类型的actor。我有一个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不能接触到它们?
答案 0 :(得分:0)
看来问题是我在JobManagerImpl
的静态内部类中创建了BatchManagerImpl
- 这个内部类在TypedActor.get(TypedActor.context())
没有&#39的奇怪处境中; t抛出一个在TypedActor上下文之外使用的异常,但是以这种方式实例化的任何东西都在内部被破坏。
答案 1 :(得分:0)
我猜,TypedActor方法调用使用的是类JobManager
而不是JobManagerImpl
。
虽然你/ Akka已经实例化了JobManagerImpl
,因为我们可以看到构造函数SOP,但是Akka试图通过反射来调用方法,但它使用类JobManager.class
代替JobManagerImpl.class
。 JobManager.class
作为一个接口,将其所有方法都作为 “公共抽象” 方法,这些方法可以在异常堆栈跟踪中看到。
我不确定你是否有任何地方传递Class<?>
个物品。请查看。