第104讲:通过案例解析Akka中的Actor的不同类型的Constructor学习笔记

来源:互联网 发布:mac日历广告如何禁止 编辑:程序博客网 时间:2024/05/25 08:14

104讲:通过案例解析Akka中的Actor的不同类型的Constructor学习笔记

 

actor的构造器有两种:

1默认:构造时把actor具体的类名称传入

2非:构造实例时传入参数,助于特殊初始化,

如可以在构造器中传入其他actoractorRef(引用),这样就可以在自己的receive

给其他actor发消息。

 

val aggregateActor:ActorRef = context.actorOf(Props[AggregateActor],name="aggregate")

构造默认构造器

 

val reduceActor:ActorRef = context.actorOf(Props(new ReduceActor(aggregateActor)),name="reduce")

构造非默认构造器

 

源码:

/**

 * Strores the context for this actor, including self , and sender.

 * It is implicit to support operations such as 'forward'.

 */

protected[akka] implicit val context:ActorContext = {

  val contextStack = ActorCell.contextStack.get

...

}

 

implicit final val self = context.self  //MUST BE A VAL, TRUST ME

 

使用context.actorOf可以构建具体的actor的实例并拿到实例的句柄

 

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

 

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

王家林老师QQ:1740415547 

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

 

第104讲视频网站地址:

56

http://www.56.com/u23/v_MTM4ODI3MDUy.html

0 0
原创粉丝点击