Akka(4)Chapter 2 General - Actor System

本文详细阐述了Akka Actor系统的层级结构、监督机制、配置容器等核心概念,并介绍了Actor的最佳实践,包括如何避免阻塞、传递不可变对象等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值