有没有办法通过 RMI 对象发送事件?

发布于 2024-09-12 16:37:18 字数 186 浏览 6 评论 0原文

我有几个客户端都通过 RMI 引用同一个远程对象,我想知道当其中一个客户端在其上运行远程方法时,是否可以将事件发送到所有客户端中的存根对象。

例如,如果远程对象“obj”具有“updateValue()”方法,并且客户端 A 通过存根对象运行该方法,则具有真实“obj”的服务器是否可以发送事件告诉客户端 A、B、C 等。 ..该对象已更新?

I have several clients all referencing the same remote object through RMI, and I was wondering if it is possible to send an event to the stub object in all of the clients when one of them runs a remote method on it.

For example, if the remote object "obj" has an "updateValue()" method and client A is running it through the stub object, can the server with the real "obj" send an event telling clients A, B, C etc... that the object was updated?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

转身泪倾城 2024-09-19 16:37:18

RMI是一种客户端-服务器技术,RMI通道可用于与服务器上的远程对象进行通信,但服务器无法回调客户端。

但是,没有什么可以阻止您拥有两个 RMI 通道,以便双方都充当客户端服务器,如果您明白我的意思的话。

我们这样做是为了向连接到中央服务器的桌面应用程序发送通知,并且效果很好。桌面应用程序导出(用 RMI 术语)回调存根,连接到中央服务器,并在服务器上注册回调存根。然后,服务器可以向所有连接的桌面应用程序发送通知。当然,您需要设置网络基础设施(防火墙等)以便可以进行双向连接。所以,是的,我想说这是可能的,但比单个单向通道需要更多的努力。

我只快速浏览了这篇文章,但它似乎说明了想法(如果不是这种情况,请告诉我,我确信我可以找到此用例的代码片段)。

其他替代方案包括轮询或 JMS,如其他答案中所述。

RMI is a client-server technology, and a RMI channel can be used to communicate with the remote object(s) on the server, but the server can not call the client back.

Nothing stops you however to have two RMI channels so that both side act as client and server, if you see what I mean.

We did that to send notification to desktop application connected to a central server and it worked fine. The desktop application exports (in RMI parlance) a callback stub, connects to the central server, and register the callback stub on the server. The server can then send notifications to all connected desktop application. Of course, you need to set up the network infrastructure (firewall, etc.) so that bi-directional connections are possible. So yes, I would say it's possible, but requires a bit more effort than a single, uni-directional channel.

I had only a very quick look at this article, but it seems to illustrate the idea (if it's not the case, let me know, I'm sure I can find code snippet for this use case).

Other alternatives include polling or JMS, as mentionned in the other answer.

嗳卜坏 2024-09-19 16:37:18

您所描述的是“push”机制,它不是 RMI 的一部分。您可以轻松执行的是某种“”机制,其中对象 A、B、 C 等轮询服务器是否有任何新事件。但这实际上也不是 RMI 的一部分。您必须实现一个名为 getNewEvent() 的附加方法,该方法每 X 秒调用一次服务器以了解是否发生了新事件。

What you describe is a "push" mechanism, which is not part of RMI. What you can do easily is some sort of "pull" mechanism, where object A,B,C etc polls the server for any new event. But that also is not de-facto part of RMI. You would have to implement an additional method named getNewEvent() that calls the server every X seconds to know if a new event has occured.

怎樣才叫好 2024-09-19 16:37:18

您可能想研究一下事件通道/Java 消息服务 (JMS)——我认为这正是您所讨论的内容。它是 J2EE 的核心功能,但 JMS 解决方案可以在您的系统中使用,而无需 J2EE 的其余部分。

You might want to look into an event channel/java messaging service (JMS)--I think that's pretty much what you are talking about. It's a core feature of J2EE but a JMS solution can be used in your system without the rest of J2EE.

蓝海似她心 2024-09-19 16:37:18

JMX 有一个远程工作的事件 API —— 还没有直接使用过它。

如果您想要变得非常奇特,您可以在所有客户端计算机上启动 RMI 服务器,并让它们将存根传递到保存相关对象的“主”服务器。该主服务器可以使用标准侦听器/模型模式调用存根。

如果是我,我会使用动态主题进行 JMS。

JMX has an event API which works remotely -- haven't use it first hand.

If you want to get very fancy, you could startup RMI servers on all client machines and have them pass stubs to the "main" server holding the object in question. That main server can invoke the stubs using a standard listener/model pattern.

Were it me, I'd JMS with a dynamic topic.

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