I\'d like to know if there are any mechanism in Akka that can have an actor executed periodically?
You don't really need an actor to do this in Akka 1.3.1 you can schedule a function to be called every 5 minutes like this:
Scheduler.schedule(() => println("Do something"), 0L, 5L, TimeUnit.MINUTES)
However, if you do want it to be an actor for other reasons you would call it like this
case class Message()
val actor = actorOf(new Actor {
def receive = {
case Message() => println("Do something in actor")
}
}).start()
Scheduler.schedule(actor, Message(), 0L, 5L, TimeUnit.MINUTES)
If you're using Akka 2.0 then it would be done like this
val system = ActorSystem("MySystem")
system.scheduler.schedule(0 seconds, 5 minutes)(println("do something"))
Or send a message to an actor every 5 minutes like this
case class Message()
class MyActor extends Actor {
def receive = { case Message() => println("Do something in actor") }
}
val system = ActorSystem("MySystem")
val actor = system.actorOf(Props(new MyActor), name = "actor")
system.scheduler.schedule(0 seconds, 5 minutes, actor, Message())