如何以编程方式停止 RMI 服务器并通知所有客户端
我开发了一个 RMI 应用程序,其中 RMI 服务器必须启动多次,也必须停止多次。
- 如何在不关闭应用程序的情况下停止 RMI 服务器?
- 如何向所有客户端发送服务器将要停止的通知?
I have developed an RMI application where the RMI server has to be started several times and also has to stop several times.
- How can I stop the RMI server without closing the application?
- How do I send notifications to all clients that the server is going to stop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您所说的“RMI 服务器”是什么意思,即您无法以编程方式停止的 RMI 注册表。但您可以停止您的服务(绑定到 RMI 注册表)。您应该调用自定义方法来彻底关闭您的服务,然后将其从注册表中
取消绑定
。在关闭和解除绑定之前,您应该通知所有连接的客户端该服务将被关闭。该通知可以通过回调来完成。搜索
RMI回调
会给你很多例子和教程。I'm not sure what you mean with the "RMI server", the RMI registry you cannot stop programmatically. But you can stop your service (bound to the RMI registry). You should invoke a custom method to cleanly shutdown your service and then
unbind
it from the registry.Before this shutdown and unbinding you should inform all connected clients that the service will be shut down. This notification can be done by callback. Searching for
RMI callback
will give you a lot of examples and tutorials.您实际上不需要发送通知。未导出的远程对象的客户端下次对其进行远程方法调用时将获得 NoSuchObjectEzception。他们只需要认清形势即可。
You don't really need to send a notification. Clients of an unexported remote object will get a NoSuchObjectEzception next time they do a remote method invocation on it. They just need to recognize the situation.