2013-04-29 47 views
0

我試圖使用Akka和調度程序與Play!在java中的框架2.1.1。
我已經在Scala和Play 2.1.0中使用它,但是導入並不是全部正常。調度程序找不到的合適的方法2.1.1

我目前的進口:

import play.Application; 
import play.GlobalSettings; 
import play.Logger; 
import play.libs.*; 
import utils.MongoUtil; 
import play.libs.Akka; 
import akka.actor.ActorRef; 
import akka.actor.Props; 

import java.util.*; 
import java.util.concurrent.TimeUnit; 

import jobs.*; 

import models.User; 

import scala.concurrent.duration.Duration; 
import scala.concurrent.duration.FiniteDuration; 

import com.mongodb.*; 

我的代碼:

  ActorRef cron = Akka.system().actorOf(new Props(Cron.class)); 
      Akka.system().scheduler().schedule(
       Duration.create(0, TimeUnit.SECONDS), 
       Duration.create(24, TimeUnit.HOURS), 
       cron, 
       "tick" 
      ); 

堆棧跟蹤:

error: no suitable method found for schedule(FiniteDuration,FiniteDuration,ActorRef,String) 
[error]     Akka.system().scheduler().schedule(
[error]          ^
[error]  method Scheduler.schedule(FiniteDuration,FiniteDuration,Runnable,ExecutionContext) is not applicable 
[error]  (actual argument ActorRef cannot be converted to Runnable by method invocation conversion) 
[error]  method Scheduler.schedule(FiniteDuration,FiniteDuration,Function0<BoxedUnit>,ExecutionContext) is not applicable 
[error]  (actual argument ActorRef cannot be converted to Function0<BoxedUnit> by method invocation conversion) 
[error]  method Scheduler.schedule(FiniteDuration,FiniteDuration,ActorRef,Object,ExecutionContext) is not applicable 
[error]  (actual and formal argument lists differ in length) 

我嘗試了很多事情,我上網,但沒有上發現似乎工作。

在此先感謝!

編輯:我真的不喜歡當你不在最新版本的API文檔自動rediriged ...
我不得不在「打勾」後添加Akka.system()。dispatcher()。

回答

1

的錯誤是不言自明:

[error] method Scheduler.schedule(FiniteDuration,FiniteDuration,Runnable,ExecutionContext) is not applicable 
[error] (actual argument ActorRef cannot be converted to Runnable by method invocation conversion) 

所以,ActorRef不是Runnable

必須調用安排這種方式(當然,不完全是這樣,修改你的程序):

system.scheduler().schedule(Duration.create(50, TimeUnit.MILLISECONDS), 
new Runnable() { 
... 
} 
}, system.dispatcher()); 
+0

謝謝,其實,它缺少在最後一個system.dispatcher()時,錯誤不是不言自明的...謝謝! – Simon 2013-04-29 08:45:32

+0

@西蒙很高興聽到這個,現在感覺stoopid! – 2013-04-29 08:46:26

相關問題