#What are actors
Actors are classes that process messages. Akka provides Actor
, that can be subclassed to create actors. All Actor
subclasses
must define a partial function named receive
(defined using the case construct).
Actor objects are containers for State, Behavior, MailBox, Child Actors and Supervisor Strategy. All actors must minimize unnecessary interaction via locks or shared mutable states.
##Actor reference An actor object is always to be referenced using an Actor Reference object. These references can be passed around with impunity.
##State An actor has a state that can be in the form of datastructures, variables or pending messages. The state of an actor is valuable and must be protected from corruption by other actors. The state in Akka Actor is automatically protected as each one of these runs on a separate lightweitght-thread(?) that are shielded from everything else.
##Behavior
The behavior is defined by the receive
method of the Akka Actor class. This method is a partial function that accepts messages. The behavior of an actor may change during its lifecycle. The actor resets to the initial behavior every time it is restarted.
##MailBox Every actor has one and only one mailbox. The actor keeps processing the next available message. The order in which messages arrive from different senders is random. The messages from the same sender always arrive in order of sending. The mailbox can be implemented as a FIFO stack or a priority queue among other things.
##Child Actors
An actor can create its own actors to delegate tasks. In Akka these are created and destoryed using context.actorOf()
and context.stop(actorReference)
. These are asynchronous operations (hence non-blocking).
##Supervisor Strategy The supervisor strategy of an actor provides the rule for handling failure in its children. Each actor can have at most one strategy and this cannot be changed at runtime.