阿卡调度员找不到我的演员?

时间:2012-05-20 01:04:58

标签: scala akka

看起来我没有正确设置我的演员,但不知道我会怎么做。我成立了一个由Akka安排的演员。但是,我得到的编译器错误是:not found: value MaidActor

代码:

/**
 * the engine maid
 */
class MaidActor extends Actor {
  def receive = {
    case "ChatMaid" => {
      println("A hot french maid will now clean up the chat database")
    }
  }
}

/**
 * scheduled jobs to run in the background
 */
object EngineJobs {

  /**
   * clean old chats to save database space
   */
  def setupJobs = {
      Akka.system.scheduler.schedule(0 seconds, 120 minutes, MaidActor, "ChatMaid")
  }

}

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我解决了它:)

能够通过正确设置我的EngineJobs对象来修复它。这是通过像这样创建一个新的ActorSystem来完成的:

/**
 * the engine maid
 */
class MaidActor extends Actor {
  def receive = {
    case "tick" => {
      Logger.info("A hot french maid will now clean up the chat database")
      models.Chat.cleanOldChats
    }
  }
}

/**
 * scheduled jobs to run in the background
 */
object EngineJobs {

  val system = ActorSystem("jobs")
  val Tick = "tick"
  val ChatMaid = system.actorOf(Props(new MaidActor))

  /**
   * set up jobs to be run in engine
   */
  def setupJobs = {
      Akka.system.scheduler.schedule(0 seconds, 10 seconds, ChatMaid, Tick)
  }

}