Taking a complex problem and recursively splitting it into smaller sub-problems is a sound problem solving technique in general. This approach can be particularly beneficial in computer science (consistent with theSingle Responsibility Principle), as it tends to yield clean, modularized code, with little or no redundancy, that is relatively easy to maintain.
In an actor-based design, use of this technique facilitates the logical organization of actors into a hierarchical structure known as an Actor System. The actor system provides the infrastructure through which actors interact with one another.
In Akka, the only way to communicate with an actor is through an
ActorRef. An ActorRef represents a reference to an actor that precludes other objects from directly accessing or manipulating that actor’s internals and state. Messages may be sent to an actor via an ActorRef using one of the following syntax protocols:!(“tell”) – sends the message and returns immediately?(“ask”) – sends the message and returns a Future representing a possible reply
Each actor has a mailbox to which its incoming messages are delivered. There are multiple mailbox implementations from which to choose, with the default implementation being FIFO.
An actor contains many instance variables to maintain state while processing multiple messages. Akka ensures that each instance of an actor runs in its own lightweight thread and that messages are processed one at a time. In this way, each actor’s state can be reliably maintained without the developer needing to explicitly worry about synchronization or race conditions.
Each actor is provided with the following useful information for performing its tasks via the Akka Actor API:
sender: anActorRefto the sender of the message currently being processedcontext: information and methods relating to the context within which the actor is running (includes, for example, anactorOfmethod for instantiating a new actor)supervisionStrategy: defines the strategy to be used for recovering from errorsself: theActorReffor the actor itself