Akka(4)Chapter 2 General - Actor System

摇摆少年梦的技术 2014-08-02

Akka(4)Chapter 2 General - Actor System

Chapter 2 General
2.1 Actor Systems
Hierarchical Structure
One actor might want to split up its task into smaller, more manageable pieces, for this purpose it starts child actors which it supervises.
Supervisor Details http://doc.akka.io/docs/akka/2.1.0/general/supervision.html#supervision

Each actor has exactly one supervisor, which is the actor that created it.

Configuration Container
The actor system as a collaborating ensemble of actors, it is the natural unit for managing shared facilities like scheduling services, configuration, logging, etc.

Several actor systems with different configuration may co-exist within the same JVM without problems.

Actor Best Practices
1. Actor should not block
2. Do not pass mutable objects between actors
…snip…

Blocking Needs Careful Management

2.2 What is an Actor
An actor is a container for State, Behavior, a Mailbox, Children and a Supervisor Strategy. All of this is encapsulated behind an Actor Reference.

Actor Reference
An actor object needs to be shielded from the outside in order to benefit from the actor model. Actors are represented to the outside using actor references.
The most important aspect is that it is not possible to look inside an actor and get hold of its state from the outside.

State
FSM module in details
http://doc.akka.io/docs/akka/2.1.0/scala/fsm.html#fsm-scala

Behavior
Every time a message is processed, it is matched against the current behavior of the actor.

Mailbox
The piece which connects sender and receiver is the actor's mailbox: each actor has exactly one mailbox to which all senders enqueue their messages.

There are different mailbox implementations to choose from, the default being a FIFO.

Children
Each actor is potentially a supervisor, it creates children for delegating sub-tasks, it will automatically supervise them.

All the children is maintained in the context of the actor, we can change that by creating content.actorOf(…) or stopping

Supervisor Strategy
The final piece of an actor is its strategy for handling faults of its children.
http://doc.akka.io/docs/akka/2.1.0/general/supervision.html#supervision

When an Actor Terminates
…go on…


References:
http://doc.akka.io/docs/akka/2.1.0/
http://doc.akka.io/docs/akka/2.1.0/general/index.html

AKKA 1~3
http://sillycat.iteye.com/blog/1767866
http://sillycat.iteye.com/blog/1768625
http://sillycat.iteye.com/blog/1768626

相关推荐