服务器上是否需要有远程 scala actor 的代码?
我想使用远程参与者,本质上,服务器在编译时并不知道,因此该参与者将仅在客户端定义。是否可以?
I would like to use remote actors, of a nature, not known to the server at it's compile time, so that this actors will be defined on the client side only. Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常情况下,不需要。
远程Actor是通过Actor代理访问的,这与具体的Actor实现无关。只要使用 Actor 的正确方法是发送消息(因此,避免直接调用 Actor 方法,不幸的是,这对于标准 Scala Actor 来说是可能的,但是,例如,在 Akka 中,演员和 Actor 引用分离,这是不可能的)代理将在大多数情况下为您工作。
但是,在某些情况下,其他节点上需要参与者的字节码。例如,当您想要序列化参与者及其邮箱,并将其发送到另一个节点以执行时。
引用自 Scala Actors API:
Normally, it's not needed.
Remote actors are accessed through actor proxy, which is irrelevant to specific actor implementation. As long as proper way of working with actors is sending messages (and, thus, avoid calling actor methods directly, which, unfortunately possible with standard Scala actors, but, e.g., impossible in Akka that has separation of actors and actor references) proxy will work for you in the most scenarios.
However, there're some cases, when byte code of the actor is required on the other node. E.g, when you want to serialize the actor with its mail box, and send it for execution to another node.
Quote from The Scala Actors API: