简体   繁体   English

使用单个端口的RMI回调

[英]RMI Callbacks using a single port

How can I reduce the number of overall ports used by RMI from N (where N = number of RMI UnicastRemoteObjects) to 2 + N? 如何将RMI使用的总端口数从N(其中N = RMI UnicastRemoteObjects的数量)减少到2 + N?

Allow me to explain further. 请允许我进一步解释。 I have a system which is using RMI to perform client-server communication. 我有一个使用RMI执行客户端 - 服务器通信的系统。 There are two interfaces; 有两个接口; we shall call them Client and Server to keep things simple. 我们称它们为客户端和服务器以保持简单。 The RMI registry runs in the same JVM as Server, and is bound to some port (say 4000). RMI注册表在与服务器相同的JVM中运行,并绑定到某个端口(例如4000)。 Server is exported as a UnicastRemoteObject with no port number, and is bound to an anonymous port as per the no-args constructor. 服务器作为UnicastRemoteObject导出,没有端口号,并根据no-args构造函数绑定到匿名端口。

When a Client starts up, it calls a void hello(Client client) method on the Server implementation which it gets from a lookup on the registry. 当客户端启动时,它会调用Server实现上的void hello(客户端客户端)方法,该方法是从注册表中的查找获得的。 The Client implementation passed in is also a UnicastRemoteObject; 传入的客户端实现也是UnicastRemoteObject; giving us bi-directional communication between Client and Server over the two interfaces. 通过两个接口为客户端和服务器之间提供双向通信。 The problem is that the UnicastRemoteObject in the Client is also listening on its own anonymous port. 问题是客户端中的UnicastRemoteObject也在侦听自己的匿名端口。

That means that in order to have N clients, I need to have 1 + 1 + 3 * N ports availble; 这意味着为了拥有N个客户端,我需要有1 + 1 + 3 * N端口可用; 2 + N of which are listening, and 2 * N of which are ephemeral. 2 + N正在收听,其中2 * N是短暂的。 (Registry + Server Instance + One listening port per client, Ephemeral port per client, Ephemeral port per server). (注册表+服务器实例+每个客户端一个侦听端口,每个客户端的临时端口,每个服务器的临时端口)。 We usually have around 30 clients, giving 92 ports. 我们通常有大约30个客户端,提供92个端口。 I believe I can get this down to 32 ports (1 + 1 + the ephemeral port for each client), but I can't see how to do it with pure RMI. 我相信我可以将它降低到32个端口(1 + 1 +每个客户端的临时端口),但我看不出如何使用纯RMI。

I am willing to accept other solutions which do not require RMI, but also do not require that we re-write our interfaces. 我愿意接受其他不需要RMI的解决方案,但也不要求我们重新编写接口。

I'm not clear what the problem is here. 我不清楚这里的问题是什么。 Exported RMI objects will all share the same port number by default, unless you have written non-compliant server socket factories. 默认情况下,导出的RMI对象将共享相同的端口号,除非您编写了不兼容的服务器套接字工厂。 You can specify the port number to be used when constructing or exporting them as described in the Javadoc for UnicastRemoteObject . 您可以指定在构造或导出它们时使用的端口号,如Javadoc for UnicastRemoteObject You can use the same port for your objects and the Registry when starting the latter in your JVM. 在JVM中启动后者时,可以为对象和注册表使用相同的端口。 Your 92 ports don't make much sense as a resource count even if accurate, as they are distributed across all the server and client hosts. 您的92个端口作为资源计数没有多大意义,即使它们是准确的,因为它们分布在所有服务器和客户端主机上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM