设为首页 加入收藏

TOP

Akka(8): 分布式运算:Remoting-远程查找式(三)
2017-10-09 14:06:30 】 浏览:9461
Tags:Akka 分布式 运算 Remoting- 远程 查找
sult of calculation
is: 113.0

结果正确。supervisorActor的SupervisorStrategy起到了应有的作用。

remote项目输出显示也能证明:

[INFO] [06/20/2017 21:24:37.955] [main] [akka.remote.Remoting] Starting remoting
[INFO] [06/20/2017 21:24:38.091] [main] [akka.remote.Remoting] Remoting started; listening on addresses :[akka.tcp://remoteSystem@127.0.0.1:2552]
[INFO] [06/20/2017 21:24:38.092] [main] [akka.remote.Remoting] Remoting now listens on addresses: [akka.tcp://remoteSystem@127.0.0.1:2552]
[WARN] [06/20/2017 21:27:06.330] [remoteSystem-akka.actor.default-dispatcher-4] [akka://remoteSystem/user/supervisorActor/calculator] / by zero
[ERROR] [06/20/2017 21:27:34.176] [remoteSystem-akka.remote.default-remote-dispatcher-5] [akka.tcp://remoteSystem@127.0.0.1:2552/system/endpointManager/reliableEndpointWriter-akka.tcp%3A%2F%2FlocalSystem%40127.0.0.1%3A60601-0/endpointWriter] AssociationError [akka.tcp://remoteSystem@127.0.0.1:2552] <- [akka.tcp://localSystem@127.0.0.1:60601]: Error [Shut down address: akka.tcp://localSystem@127.0.0.1:60601] [
akka.remote.ShutDownAssociation: Shut down address: akka.tcp://localSystem@127.0.0.1:60601
Caused by: akka.remote.transport.Transport$InvalidAssociationException: The remote system terminated the association because it is shutting down.
] 

 下面我们试着用Identify消息确认方式来复演上述例子。Akka是如下这样定义有关Identify消息确认的:

/** * A message all Actors will understand, that when processed will reply with * [[akka.actor.ActorIdentity]] containing the `ActorRef`. The `messageId` * is returned in the `ActorIdentity` message as `correlationId`. */ @SerialVersionUID(1L) final case class Identify(messageId: Any) extends AutoReceivedMessage with NotInfluenceReceiveTimeout /** * Reply to [[akka.actor.Identify]]. Contains * `Some(ref)` with the `ActorRef` of the actor replying to the request or * `None` if no actor matched the request. * The `correlationId` is taken from the `messageId` in * the `Identify` message. */ @SerialVersionUID(1L) final case class ActorIdentity(correlationId: Any, ref: Option[ActorRef]) { if (ref.isDefined && ref.get == null) { throw new IllegalArgumentException("ActorIdentity created with ref = Some(null) is not allowed, " +
      "this could happen when serializing with Scala 2.12 and deserializing with Scala 2.11 which is not supported.") } /** * Java API: `ActorRef` of the actor replying to the request or * null if no actor matched the request. */ @deprecated("Use getActorRef instead", "2.5.0") def getRef: ActorRef = ref.orNull /** * Java API: `ActorRef` of the actor replying to the request or * not defined if no actor matched the request. */ def getActorRef: Optional[ActorRef] = { import scala.compat.java8.OptionConverters._ ref.asJava } }

如果拿上面的例子,我们就会向远程机上的Calculator地址发送Identify(path),而Calculator返回ActorIdentity消息,参数包括correlationId = path, ref = Calculator的ActorRef。 下面是使用示范代码:

object LocalIdentifyDemo extends App { class RemoteCalc extends Actor with ActorLogging { val path = "akka.tcp://remoteSystem@127.0.0.1:2552/user/supervisorActor/calculator" context.actorSelection(path) ! Identify(path)  //send req for ActorRef
 import context.dispatcher implicit val timeout = Timeout(5 seconds) override def receive: Receive = { case ActorIdentity(p,someRef) if p.equals(path) => someRef foreach
首页 上一页 1 2 3 4 5 6 下一页 尾页 3/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇spark获取时间 下一篇sbt 学习笔记(1)sbt安装和交互..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目