Akka PingPong示例不会在Scala工作表中运行

时间:2018-10-28 02:05:52

标签: scala intellij-idea akka

我正在尝试运行Akka文档here中的乒乓示例。当我通过Akka的站点在ScalaFiddle中运行它时,一切都会按预期进行。当我复制/粘贴并在IntelliJ scala工作表中运行它时,我得到一个java.lang.IllegalArgumentException: no matching constructor found on class A$A14$A$A14$Pinger for arguments []。这是怎么了?代码包括在下面。

根据this bug,我的工作表未“在编译器进程中运行”。否则,我尝试在“ eclipse兼容模式”以及“ REPL模式”和“交互模式”下运行。最后,“运行前制作项目”设置无效。

import akka.actor.{ ActorSystem, Actor, ActorRef, Props, PoisonPill }
import language.postfixOps
import scala.concurrent.duration._

case object Ping
case object Pong

class Pinger extends Actor {
  var countDown = 100

  def receive = {
    case Pong =>
      println(s"${self.path} received pong, count down $countDown")

      if (countDown > 0) {
        countDown -= 1
        sender() ! Ping
      } else {
        sender() ! PoisonPill
        self ! PoisonPill
      }
  }
}

class Ponger(pinger: ActorRef) extends Actor {
  def receive = {
    case Ping =>
      println(s"${self.path} received ping")
      pinger ! Pong
  }
}

val system = ActorSystem("pingpong")

val pinger = system.actorOf(Props[Pinger], "pinger")

val ponger = system.actorOf(Props(classOf[Ponger], pinger), "ponger")

import system.dispatcher
system.scheduler.scheduleOnce(500 millis) {
  ponger ! Ping
}

0 个答案:

没有答案