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

10.4 Message handling

As you saw in the previous section, an Akka actor processes messages using a global message handler. Typically, this message handler is defined once and does not change over the lifetime of its actor. However, in some cases an actor handles different messages depending on its current state.

For example, consider a data processing framework where a master actor controls the processing steps. Before processing starts, the master actor receives the data to be processed (alternatively, it could receive information on how to obtain the data from disk or the network). Data processing should stop when a user-specified termination condition is satisfied. Thus, the master actor's message handler should look as follows:

  def receive = { ...

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