服务器上是否需要有远程 scala actor 的代码?

发布于 2024-10-07 15:04:45 字数 53 浏览 2 评论 0原文

我想使用远程参与者,本质上,服务器在编译时并不知道,因此该参与者将仅在客户端定义。是否可以?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弱骨蛰伏 2024-10-14 15:04:45

通常情况下,不需要。

远程Actor是通过Actor代理访问的,这与具体的Actor实现无关。只要使用 Actor 的正确方法是发送消息(因此,避免直接调用 Actor 方法,不幸的是,这对于标准 Scala Actor 来说是可能的,但是,例如,在 Akka 中,演员和 Actor 引用分离,这是不可能的)代理将在大多数情况下为您工作。

但是,在某些情况下,其他节点上需要参与者的字节码。例如,当您想要序列化参与者及其邮箱,并将其发送到另一个节点以执行时。


引用自 Scala Actors API

获取对某个对象的远程引用
在机器上运行的远程参与者
myMachine,端口 8000,带有名称
'anActor,在下面使用select
方式:

val myRemoteActor =
选择(节点(“myMachine”,8000),'anActor)

从 select 返回的 actor 有
类型 AbstractActor 提供
本质上与
常规演员,因此支持
常用的消息发送操作

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:

To obtain a remote reference to a
remote actor running on machine
myMachine, on port 8000, with name
'anActor, use select in the following
manner:

val myRemoteActor =
select(Node("myMachine", 8000),'anActor)

The actor returned from select has
type AbstractActor which provides
essentially the same interface as a
regular actor, and thus supports the
usual message send operations

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文