2012-04-11 18 views
1

私はplay 2.0(javaを使用)のフレームワークアプリケーションでakkaのスケジューラを使用して、特定の日付と時刻の電子メールリマインダを送信したいと考えています。もし誰かが(詳細に)分かっていれば、プレイ2.0フレームワークでakkaスケジューラーを使用する手順を教えてください。 ありがとうございます。play 2.0アプリケーションでakkaのスケジューラを使用する方法は?

+0

あなたは文書を見ましたか? https://github.com/playframework/Play20/wiki/JavaAkka(「非同期タスクのスケジュール」セクション) –

+1

これは私がこの質問で答えたものと同じではありません - http://stackoverflow.com/questions/10085591/how- to-integrate-sms-email-reminder-in-my-play2-0-フレームワーク - ウェブアプリケーション – Codemwnci

答えて

0

モジュールクラス

import com.google.inject.AbstractModule 
import play.api.libs.concurrent.AkkaGuiceSupport 

class JobModule extends AbstractModule with AkkaGuiceSupport { 
    def configure() = { 
    bindActor[JobBucket]("job-bucket-actor") 
    bind(classOf[Scheduler]).asEagerSingleton() 
    } 
} 

スケジューラクラス

import javax.inject._ 
import akka.actor._ 
import scala.concurrent.ExecutionContext 
import scala.concurrent.duration._ 

class Scheduler @Inject()(val system: ActorSystem, @Named("job-bucket-actor") val jobBucketActor: ActorRef)(implicit ec: ExecutionContext) { 
    system.scheduler.schedule(0.microseconds, 1.day, jobBucketActor, "cleanBucket") 
} 

をJobBucket (このクラスで複数のジョブを作成し、異なるm受信方法にessages)またapllication.configファイルに行を追加する必要があります

import javax.inject._ 
import akka.actor.Actor 
import org.apache.commons.io.FileUtils 
import play.api.Logger 

// You can inject any service class or other class if it's required 
@Singleton 
class JobBucket extends Actor { 
    def receive = { 
    //You can place n number of cases. 
    case "cleanBucket" => clean() 
    } 

    def clean(): Unit = { 
    //Do whatever you want to do over here. 
    Logger.info("This task has been scheduled...!!!") 
    } 
} 

:。 play.modules.enabled + = "com.abc.xyz.JobModule"

関連する問題