Make an Akka-2 instance, send yourself a message every n TimeUnits without a mailbox overflow

The Akka-2 case should remain in an infinite loop and check every 10 minutes to process the data.

How to create a loop so that the instance invokes itself, checks the operation and then sleeps for an interval?

I also see that it is no longer possible to request a mailbox size. How do you make sure that messages are ignored while the work task is active (in this case, the send function)?

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       
  }
}
+5
source share
1 answer

I would suggest the following:

use: http://akka.io/docs/akka/2.0-RC2/scala/actors.html#initial-receive-timeout

, ReceiveTimeout, .

+3

All Articles