actor中!(tell)与forward的差别
差别 forward Actor
2023-09-11 14:14:10 时间
! 的源代码:
def !(message: Any)(implicit sender: ActorRef = Actor.noSender): Unit
tell 的源代码:
final def tell(msg: Any, sender: ActorRef): Unit = this.!(msg)(sender)
forward 的源代码:
def forward(message: Any)(implicit context: ActorContext) = tell(message, context.sender())
通过源代码。我们能够轻而易举的知道 :
! 发送的消息的发送者通过一个隐式转换,把一个ActorRef转换成sender,假设找不到ActorRef的话。那个发送者就是noSender。
forward 发送消息的发送者是当前消息的上一个发送者。
即:
A To B, B To C
假设通过!
的方式发送消息,则C接收到的消息的发送者是B.
假设通过 forward 的方式发送消息。则C接收到的消息的发送者是A.
假设希望 !的方式发送消息的同一时候携带发送者消息,则能够使用 .!(msg)(sender)
假设希望关掉actor,直接shutdown或者使用父亲actor的stop。在actor内部还能够使用context.stop(self)
相关文章
- 王立平--Http中Get() 与 Post()的差别?
- Linux—su命令和su -命令的差别(切换登录账号)
- Python与Perl的相似与差别
- 配置管理系统和总体变更系统有什么差别与联系
- MyISAM和InnoDB存储引擎的差别
- android中Invalidate和postInvalidate的差别
- Timer与AlarmManager的差别
- scrollTop clientTop offsetTop scrollHeight clientHeight clientWidth的差别及使用方法
- AfxMessageBox和MessageBox差别
- android:layout_gravity和android:gravity属性的差别
- ios 获取button所在的cell对象, 注意:ios7 =< System Version < ios8 获取cell对象的差别
- /dev/shm和swap差别与联系
- 秒杀多线程第二篇 多线程第一次亲热接触 CreateThread与_beginthreadex本质差别