zoukankan      html  css  js  c++  java
  • actor中!(tell)与forward的差别

    ! 的源代码:

    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)

  • 相关阅读:
    huffman压缩解压文件
    C++ fstream 详解
    huffman编码
    ios cocoapods
    POI2Vec: Geographical Latent Representation for Predicting Future Visitors
    latex生成pdf 出现missing$ inserted
    矩阵、向量求导法则

    矩阵范数求导
    hive
  • 原文地址:https://www.cnblogs.com/cxchanpin/p/6781427.html
Copyright © 2011-2022 走看看