Akka-2实例应该保持在无限循环中,并每10分钟检查一次要处理的数据。
如何设计循环,使实例调用自身,检查要做的工作,然后休眠一段时间?
我还发现不能再查询邮箱大小了。如何确保只要工作任务(在本例中是分派功能)处于活动状态,消息就会被忽略?
case class Dispatch()
// Automatical start? The start function has been removed since Akka 2 ?
val dispatcher = system.actorOf(Props[MailDispatcher])
class MailDispatcher extends Actor {
private val interval = Config.getLong("mail.check.interval")
context.setReceiveTimeout(Duration(interval, TimeUnit.SECONDS))
def receive = {
case ReceiveTimeout => {
self ! Dispatch
}
case Dispatch => dispatch()
case e: Exception => Logger.error("unexpected Error: " + e)
}
def dispatch() {
// trigger mail-dispatch
}
}发布于 2012-02-23 05:48:11
我会提出以下建议:
用法:http://akka.io/docs/akka/2.0-RC2/scala/actors.html#initial-receive-timeout
然后,当您收到ReceiveTimeout消息时,您将轮询工作,并将工作发送到您自己的邮箱。
https://stackoverflow.com/questions/9402811
复制相似问题