您的位置:首页 > 其它

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

2015-09-16 21:45 357 查看
第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创建的actor是ActorRef类型的。

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: