将方法中的远程对象传递给 RMI 服务器?
我有一个 RMI 客户端,它连接到某个 RMI 服务器,只是为了让它知道它可以使用这个新客户端。
我可以直接传递一些远程对象,以便:
serverRemoteObject.registerClient(theClientRemoteObjectTheServerShouldUse);
实际上给服务器一些他可以使用的对象,而无需连接到我的客户端吗? 以下问题表示这是可能的,但没有给出真实的示例:
Andrew
I have an RMI client that connects to some RMI server just to let it know it can use this new client.
Can I pass directly some Remote object so that:
serverRemoteObject.registerClient(theClientRemoteObjectTheServerShouldUse);
will actually give the server some object he can use without connecting to my client?
The following question says it is possible, but no real example was given:
Is it possible to use RMI bidirectional between two classes?
Andrew
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你可以。这就是 RMI 中回调的工作原理。您将一个对象发送到服务器,当服务器调用您的对象上的方法时,它将在“客户端”JVM 中执行,而不是在服务器上执行。查看 UnicastRemoteObject.export 方法,将实现 Remote 接口的任何对象导出为可以传递到服务器的远程对象。
Yes, you can. This is how exactly callbacks work in case of RMI. You send across an object to the server and when the server invokes a method on your object, it would be executed in the "client" JVM as opposed to on the server. Look into
UnicastRemoteObject.export
method for export any object which implements theRemote
interface as a remote object which can be passed to your server.