Akka (5) – Scheduler

The default implementation of Scheduler used by Akka is based on job buckets which are emptied according to a fixed schedule. The scheduler method returns an instance of akka.actor.Scheduler which is unique per ActorSystem and is used internally for scheduling things to happen at specific points in time.

Scheduler implementation are loaded reflectively at ActorSystem start-up with the following constructor arguments:

  • the system’s com.typesafe.config.Config (from system.settings.config)
  •  a akka.ever.LoggingAdapter
  • a java.util.concurrent.ThreadFactory

You can schedule sending of message to actors and execution of tasks (functions or Runnable). You will get a Cancellable back that you can call cancel on to cancel the execution of the scheduled operation. Cancels this Cancellable and returns true if that was successful. If this cancellable was (concurrently) cancelled already, then this method will return false though isCancelled will return true.

Cancellation flow:

  • a cancellation signal set by a consumer is propagated to its producer.
  • the producer uses onCancellation on Promise to listen to this signal and act accordingly.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s