java 使用单个 RMI 注册表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/820719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 13:55:50  来源:igfitidea点击:

Using single RMI Registry

javaexceptionnetworkingdistributedrmi

提问by Mark Davidson

I've been using RMI for a project I am currently working on and I want to bind from multiple hosts to a single RMI registry.

我一直在将 RMI 用于我目前正在处理的项目,我想从多个主机绑定到单个 RMI 注册表。

However when I attempt to do so I get an error saying

但是,当我尝试这样做时,我收到一条错误消息

java.rmi.AccessException: Registry.Registry.bind disallowed; origin / 192.168.0.9 is non-local host

java.rmi.AccessException: Registry.Registry.bind 不允许;origin / 192.168.0.9 是非本地主机

I did so googling and it seems that RMI stops remote hosts from binding by default, what I want to know is there some way of overriding or bypassing this?

我做了谷歌搜索,似乎 RMI 默认阻止远程主机绑定,我想知道有什么方法可以覆盖或绕过它?

If anyone any suggestions on how to get past this issue they would be highly appreciated, i've tried using different policy files and overriding the security manger but none seem to work.

如果有人对如何解决这个问题有任何建议,他们将不胜感激,我已经尝试使用不同的策略文件并覆盖安全管理器,但似乎都没有工作。

采纳答案by Mark Davidson

Thanks for everyones answers the solution I came up with in the end was to use the Cajo Frameworkthis gives a very flexible system for distribution and it allowed for me to handle the registry as I saw fit. It can also work behind NATs, firewalls, and HTTP proxies, which is very useful.

感谢大家的回答我最终想出的解决方案是使用Cajo 框架,这提供了一个非常灵活的分发系统,它允许我按照我认为合适的方式处理注册表。它还可以在 NAT、防火墙和 HTTP 代理后面工作,非常有用。

I believe that the method of proxying suggested by rndm.buoy will work in some cases but its may be troublesome on some system. RMI seems to have some issues with associating to the wrong Network Interface I particularly had this issue when running on Debian based Linux distributions.

我相信 rndm.buoy 建议的代理方法在某些情况下会起作用,但在某些系统上可能会很麻烦。RMI 似乎在关联到错误的网络接口方面存在一些问题 我在基于 Debian 的 Linux 发行版上运行时尤其遇到了这个问题。

回答by user40552

There's a way to get around the limitation but it is what it is: a work-around. Anyway, feel free to try it out. It works for us.

有一种方法可以绕过限制,但这就是它:一种变通方法。无论如何,请随意尝试一下。它对我们有用。

On the host that is running the central RMI registry run a small service which will bind a remote object with just one remote method: proxyRebind. The implementation of this method simply binds the object that is supplied to it in the central registry (this would not fail because the registry is on the same machine as this service).

在运行中央 RMI 注册表的主机上运行一个小服务,该服务将仅使用一个远程方法绑定远程对象:proxyRebind。此方法的实现只是将在中央注册表中提供给它的对象绑定(这不会失败,因为注册表与此服务在同一台机器上)。

All other hosts would simply lookup this remote object and invoke proxyRebind with their own remote objects.

所有其他主机将简单地查找这个远程对象并使用它们自己的远程对象调用 proxyRebind。

This works because look-up on remotely hosted registries is allowed. Your original attempt failed because binding on remotely hosted registries is not allowed.

这是有效的,因为允许在远程托管的注册表上查找。您最初的尝试失败,因为不允许绑定远程托管的注册表。

Let me know if you need any further clarity on this.

如果您需要进一步澄清这一点,请告诉我。

/RS

/RS

回答by user40552

2 There's a way to get around the limitation but it is what it is: a work-around. Anyway, feel free to try it out. It works for us.

On the host that is running the central RMI registry run a small service which will bind a remote object with just one remote method: proxyRebind. The implementation of this method simply binds the object that is supplied to it in the central registry (this would not fail because the registry is on the same machine as this service).

All other hosts would simply lookup this remote object and invoke proxyRebind with their own remote objects.

This works because look-up on remotely hosted registries is allowed. Your original attempt failed because binding on remotely hosted registries is not allowed.

Let me know if you need any further clarity on this.

2 有一种方法可以绕过限制,但这就是它:一种变通方法。无论如何,请随意尝试一下。它对我们有用。

在运行中央 RMI 注册表的主机上运行一个小服务,该服务将仅使用一个远程方法绑定远程对象:proxyRebind。此方法的实现只是将在中央注册表中提供给它的对象绑定(这不会失败,因为注册表与此服务在同一台机器上)。

所有其他主机将简单地查找这个远程对象并使用它们自己的远程对象调用 proxyRebind。

这是有效的,因为允许在远程托管的注册表上查找。您最初的尝试失败,因为不允许绑定远程托管的注册表。

如果您需要进一步澄清这一点,请告诉我。

This perfectly works. The only thing to take care is following should be always set correctly. -Djava.rmi.server.hostname="LOCAL HOST IP"

这非常有效。唯一需要注意的是以下应始终正确设置。-Djava.rmi.server.hostname="本地主机 IP"

回答by Aaron

I may be misunderstanding your question, if so please let me know.

我可能误解了你的问题,如果是这样,请告诉我。

I have limited experience with Java RMI, we used it in our Design Patterns class with the Proxy Pattern. (Textbook: Headfirst Design Patterns)

我对 Java RMI 的经验有限,我们在带有代理模式的设计模式类中使用了它。(教科书:Headfirst Design Patterns)

We were not able to get our projects working from outside the university network, but they worked perfectly when connected directly to the network. According to our professor, it wasn't possible to use RMI in our implementation over the internet or wan. A solution she suggested was that a VPN would be required. I believe Vladimir is correct in that it has to do with it being a local naming service.

我们无法从大学网络外部运行我们的项目,但是当直接连接到网络时,它们可以完美运行。根据我们的教授的说法,在我们通过 Internet 或 wan 的实现中不可能使用 RMI。她建议的解决方案是需要 VPN。我相信 Vladimir 是正确的,因为它与本地命名服务有关。

回答by Vladimir Dyuzhev

I may be wrong, but it looks like rmiregistry application is essentially a wrapper over local naming service. Which means there is no way to make it point to remote objects.

我可能错了,但看起来 rmiregistry 应用程序本质上是本地命名服务的包装器。这意味着没有办法让它指向远程对象。

What you need is a Naming implementation, and clustered at this. Consider to move into J2EE AS clustering solution. JNDI tree is shared within the cluster.

您需要的是一个命名实现,并在此进行集群。考虑迁移到 J2EE AS 集群解决方案。JNDI 树在集群内共享。