Akka子Actor用法示例

Akka提供了创建儿童演员的设施。你可以通过使用隐式上下文引用来创建子actor。 ActorSystem用于创建根级或顶级actor。 Akka为你提供上下文, 以便你也可以创建子演员。在以下示例中, 我们通过使用上下文引用创建了一个子actor。

import akka.actor._
class RootActor extends Actor{
  def receive = {
    case msg:String => println(msg+" "+self.path.name);
    var childActor =  context.actorOf(Props[Child], "Child");
    childActor ! "Hello"
  }
}
class Child extends Actor{
  def receive = {
    case msg:String => println(msg+" "+self.path.name);
  }
}
object ChildActorExample{
  def main(args:Array[String]){
    var actorSystem = ActorSystem();
    var actor = actorSystem.actorOf(Props[RootActor], "RootActor");
    actor ! "Hello"
  }
}

输出

Hello RootActor
Hello Child
微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_47781.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?