第108讲:Akka中的Actor消息的处理、消息回复、消息转发学习笔记
2015-09-26 21:33
483 查看
第108讲:Akka中的Actor消息的处理、消息回复、消息转发学习笔记
本讲主要讲解:
1.Actor消息的处理
2.Actor消息的回复
3.Actor消息的转发
处理消息一般通过复写receive方法,通过模式匹配的方式。
/**
* This defines the initial actor behavior, it must return a partial function
* with the actor logic.
*/
Protected def receive: Receive
如果要回复消息给发送者的话要获得发送者的actorRef,
就是说代理的句柄。Akka中提供了sender这个ActorRef指向当前收到的消息的发送者。但这有一个风险:消息到当前actor后,它的发送者已不存在了,这时给sender回复消息时,此时的消息就会变成deadLetters。
/**
* The reference sender Actor of the last received message.
* Is defined if the message was sent from another Actor,
* else ‘deadLetters’ in [[akka.actor.ActorSystem]].
*/
Final def sender: ActorRef = context.sender
消息的转发:
Forward的方式。
mapActor.forward(message)
Forward的源码:
/**
* Forwards the message and passer the original sender actor as the sender.
* Works with ! And ?/ask
Def forward(message: Any)(implicit context: ActorContext) = tell(message,context.sender)
以上内容是从王家林老师DT大数据课程第108讲的学习笔记。
DT大数据微信公众账号:DT_Spark
王家林老师QQ:1740415547
王家林老师微信号:18610086859
DT大数据梦工厂1至110集scala的所有视频、PPT和代码在百度云盘的链接:http://pan.baidu.com/share/home?uk=4013289088#category/type=0&qq-pf-to=pcqq.group
第108讲视频网站地址:
本讲主要讲解:
1.Actor消息的处理
2.Actor消息的回复
3.Actor消息的转发
处理消息一般通过复写receive方法,通过模式匹配的方式。
/**
* This defines the initial actor behavior, it must return a partial function
* with the actor logic.
*/
Protected def receive: Receive
如果要回复消息给发送者的话要获得发送者的actorRef,
就是说代理的句柄。Akka中提供了sender这个ActorRef指向当前收到的消息的发送者。但这有一个风险:消息到当前actor后,它的发送者已不存在了,这时给sender回复消息时,此时的消息就会变成deadLetters。
/**
* The reference sender Actor of the last received message.
* Is defined if the message was sent from another Actor,
* else ‘deadLetters’ in [[akka.actor.ActorSystem]].
*/
Final def sender: ActorRef = context.sender
消息的转发:
Forward的方式。
mapActor.forward(message)
Forward的源码:
/**
* Forwards the message and passer the original sender actor as the sender.
* Works with ! And ?/ask
Def forward(message: Any)(implicit context: ActorContext) = tell(message,context.sender)
以上内容是从王家林老师DT大数据课程第108讲的学习笔记。
DT大数据微信公众账号:DT_Spark
王家林老师QQ:1740415547
王家林老师微信号:18610086859
DT大数据梦工厂1至110集scala的所有视频、PPT和代码在百度云盘的链接:http://pan.baidu.com/share/home?uk=4013289088#category/type=0&qq-pf-to=pcqq.group
第108讲视频网站地址:
酷6网 | http://v.ku6.com/show/SIfOF_-ZPl3jdllLZy6fZg...html |
51CTO | http://edu.51cto.com/lesson/id-76214.html |
相关文章推荐
- 动画基础
- [C#]INI文件控制类
- C#接口的显示实现和隐式实现
- 第一天代码2015-09-26
- 谈面向对象编码的粒度
- 监督学习-变量类型和术语
- 浏览器兼容及css3属性基础
- 关于Increased rates of convergence through learning rate adaptation一文的理解
- 个人项目总结
- CentOS6.4下Mysql数据库的安装与配置
- Listview中几个注意
- No result defined for action com.xiao.action.Haha and result success
- 代理下载android4.4源代码
- 苹果试图做?XCode6 放弃prefix.pch档
- HDU5478 Can you find it
- hdu 5476 Explore Track of Point 2015上海网络赛 几何
- 骨骼动画原理和实例之MD5SkeletalAnimation
- 生成最长递增子序列
- 关于MFC监听器的相关了解
- Paths on a Grid(规律)