O'Reilly logo

Actors in Scala by Frank Sommers, Philipp Haller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

9.2 Reliable broadcast

When building a distributed application, it is often necessary that more than two actors operate in a coordinated manner. For example, you may want to ensure that all or none of your remote actors carry out some action while providing a way to handle the error case. If a set of remote actors should save their internal state to a database, for instance, then typically you want all or none of them to do it so that there is always a consistent view persisted to the database.

    abstract class BroadcastActor extends Actor {
      // can be set by external actor, therefore @volatile
      @volatile var isBroken = false
      private var canRun = true
      private var counter = 0L
        protected def broadcast(m: BSend) = if (!isBroken) { ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required