第103讲:通过案例解析Akka中的Actor的定义和创建学习笔记

103讲:通过案例解析Akka中的Actor的定义和创建学习笔记

 

actor的定义需要借助ActorSystem

val _system = ActorSystem("HelloAkka")

val master = _system.actorOf(Props[MasterActor],name = "master")

 

ActorSystem相当于一个容器,内部类似树状结构。

编写actor时要继承自actor:

class MasterActor extends Actor

 

receive方法是partial function

/**

 * This defines the initial actor behavior, it must return a partial function

 * with the actor logic.

 */

protected def receive: receive{}

 

/**

 * Factory for Props instances.

 * Props is a ActorRef configuation object, that is thread safe and fully sharable.

 *

 * Used when creating new actors through;<code>SctorSystem.actorOf</code> and <code>ActorContext

*/

def actorOf(props: Props, name:String): ActorRef

通过props创建的actorActorRef类型的。

ActorRef是访问具体actor的代理或远程代理,而且是共享的。

 

创建一个actor后就可以直接给它发消息了。

actor的创建是和启动同步完成的。

创建时已启动了actor

启动是actor creation的一部分。

 

也可以通过actor创建另一个actor,这时是有继承关系的,具体后面详解。

下一讲从actor的构造的角度讲解。

 

以上内容是从王家林老师DT大数据课程第103讲的学习笔记。
DT大数据微信公众账号:DT_Spark  

王家林老师QQ:1740415547 

王家林老师微信号:18610086859
DT大数据梦工厂1至103集scala的所有视频、PPT和代码在百度云盘的链接:http://pan.baidu.com/share/home?uk=4013289088#category/type=0&qq-pf-to=pcqq.group

 

第103讲视频网站地址:

6

http://v.ku6.com/show/sayviUnZQodFhABC6sKQfQ...html

51CTO

http://edu.51cto.com/lesson/id-75781.html

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值