Java RMI - Making the client a server

南笙酒味 提交于 2019-11-30 22:28:58
biziclop

You're right in all your assumptions.

You don't have to add your remotely callable client classes to the rmi registry but you still have to export them.

The only caveat with the compilation is that they have to be done with the same version of java with the same compiler settings (at least those affecting RMI stub generation).

If you have any requirements that the client or server will be behind a firewall in the future deployments, stay away from RMI. You are asking for trouble. Especially if you want the server to call the client.

Here are two alternative solutions that worked well for us:

  • have the client call the server with the server blocking the call until data is available for the client. This uses up a thread per client (if you don't use NIO), but is easy to implement. Return null once in a while to prevent a long running call from the client to be closed by the firewall (depending on the firewall config, of course)

  • if you want nice java interfaces to play with, consider Hessian which is very light-weight, runs on top of HTTP and does not bother with an RMI registry or similar stuff

  • if you intend to open up the server side to other clients, Hessian is still a good choice, but if scaling out is a concern, look into a RESTful architectur style.

Re your final question, the remote interface classes and all classes they depend on and so on recursively until closure must be present on both hosts.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!