【问题标题】:'Unit' method on Akka TypedActor times out, but should be asynchronousAkka TypedActor 上的“Unit”方法超时,但应该是异步的
【发布时间】:2011-08-10 17:24:28
【问题描述】:

我正在尝试使用 Akka TypedActors (1.1.2)。我有一个类似的界面

trait Namespace  {
  def cellCount: Int
  def isEmpty: Boolean
  def cell(key: String): Option[CellOperations[_]]
  def cellsLike(key: String): List[CellOperations[_]]
  def updateOrCreateCell[T](n: String, v: Option[T]=None, d:List[DataOps[T]]=List.empty[DataOps[T]])
}

我有一个定义明确的 NamespaceImpl 来扩展它。

class NamespaceImpl extends TypedActor with Namespace with Logging {
    ...
}

我通过 Spring 来创建 actor:

<akka:typed-actor id="namespace"
                  interface="com.fi.depends.namespace.akka.Namespace"
                  implementation="com.fi.depends.namespace.akka.NamespaceImpl"
                  timeout="10000"
                  scope="singleton">
</akka:typed-actor>

在运行时,我会定期对 updateOrCreateCell 的调用超时,据我了解,这种情况永远不会发生,因为该方法是 Unit 类型,因此我希望它生成异步调用。

在我看到的堆栈跟踪中:

akka.dispatch.FutureTimeoutException: Futures timed out after [10000] milliseconds
[NYCWD2328_1c52ee80-c372-11e0-8343-0023ae9118d8]
    at akka.dispatch.DefaultCompletableFuture.await(Future.scala:718)
    at akka.actor.ScalaActorRef$class.$bang$bang(ActorRef.scala:1332)
    at akka.actor.LocalActorRef.$bang$bang(ActorRef.scala:587)
    at akka.actor.ActorAspect.localDispatch(TypedActor.scala:966)
    at akka.actor.TypedActorAspect.dispatch(TypedActor.scala:904)
    at akka.actor.TypedActorAspect.invoke(TypedActor.scala:899)
    at com.fi.depends.namespace.akka.Namespace$$ProxiedByAWDelegation$$1314085842186_1__786390915__878797045___AW_JoinPoint.proceed(Unknown Source)
    at com.fi.depends.namespace.akka.Namespace$$ProxiedByAWDelegation$$1314085842186_1__786390915__878797045___AW_JoinPoint.invoke(Unknown Source)
    at com.fi.depends.namespace.akka.Namespace$$ProxiedByAWDelegation$$1314085842186.updateOrCreateCell$default$3(Unknown Source)

我看到 'ScalaActorRef$class.$bang$bang' 的事实告诉我有些地方很不对劲。

任何帮助将不胜感激。

【问题讨论】:

    标签: scala akka typedactor


    【解决方案1】:

    如果您实际上将“updateOrCreateCell”的返回类型指定为 Unit,会发生什么情况?

    【讨论】:

    • 嗨 Viktor——我试过了,得到了相同的异常和相同的堆栈跟踪。我正在尝试剥离我的特定应用程序的细节,以尝试找到一个有此问题的最小测试用例,但我可能要到本周末才能完成。 (我正在尝试将现有的 Scala Actors 应用程序移植到 Akka。我不想放弃 Typed Actors,因为它们使代码更加清晰。)
    • 我尝试在 1.2-RC2 上使用直接 TypedActor 重现您的问题,但我不能。顺便说一句,你知道我们已经为 Akka 2.0 准备了一个全新的 TypedActor 实现吗?:github.com/jboner/akka/blob/…
    【解决方案2】:

    Thread necro 处于最佳状态,但前几天我遇到了类似的异常,并认为它可能会在某个时候对某人有所帮助。 :)

    可能是您在NamespaceImpl 中有一个覆盖的receive 方法吗? 因为我这样做了(从 Actor 切换到 TypedActor),这让事情变得一团糟,就像它为你所做的那样......

    顺便说一句:这就是您可以覆盖 receive 并仍然在其中做一些事情的方法:

    override def receive = {
      super.receive andThen {
        case message => {
          logger.debug("Received message: " + message)
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-11
      • 1970-01-01
      • 2018-05-21
      • 2019-12-02
      • 2020-05-30
      • 2020-05-15
      • 1970-01-01
      • 1970-01-01
      • 2015-05-15
      相关资源
      最近更新 更多