Chapter 11

  1. Name two ways in which an actor can change itself in response to the received message.

An actor can mutate its internal state using a var field. This is a classical object-oriented approach.

Another way is to use context and become close over some value which will become part of the new state. The context.become can also be used to change the behavior of the actor completely. This is a more functional approach because both state and behavior are in fact immutable.

  1. What is the purpose of ActorRef?

The ActorRef provides a means to address an actor via the actor path. It also encapsulates an actor's mailbox and a dispatcher. Actors in Akka communicate via ActorReference.

  1. Look up in the official documentation the description of the system guardian. What is the main purpose of it?

The main purpose of the system guardian is to supervise system level actors. It is also used to ensure a proper shutdown order so that system level actors are available for user-defined actors until the user guardian is terminated.

  1. Describe the advantages and disadvantages of using Akka FSM.

Akka FSM allows for the modeling of actor behavior as a state machine defining separate state transitions and data for these states.

Akka FSM couples business logic to the particular implementation and makes it hard to test and debug.

  1. In how many ways can an actor in another actor system be accessed? Describe them.

There are two ways to access an actor in a remote system – remote deployment and remote lookup. With remote deployment, a new actor is created in the remote system. The remote deployment can be done explicitly in the code or by providing a deployment configuration. Remote lookup allows for the selection of an existing actor in a remote system using the same approach as used for the lookup locally.

  1. Why does testing actors require a special toolkit?

Actors are highly non-deterministic. The state of the actor is inaccessible. The only way to properly test an actor is by sending messages to it and waiting for its responses. Sometimes a whole actor hierarchy needs to be created for this purpose. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.107.25