RMI 客户端如何查看并获取在注册表中注册的所有动态远程对象?
How can RMI client sees and get all dynamic remote objects registered in a registry?
我有一个要求,即 RMI 客户端需要获取在远程 RMI 注册表中注册的所有远程对象。
第一个问题,我知道有一个 registry.list() 方法可以 returns 所有对象的名称。但是,如果还注册了其他类型的对象,我该如何获得我想要的类型的对象(实现我想要的接口)。我应该遍历名称并使用 try/catch 语句,尝试实例化每个远程对象吗?
第二个问题,如果注册了一个新的对象,怎么才能让客户端注意到呢?在我的要求中,服务器会将新对象动态注册到注册表中,客户端需要尽快更新并访问新对象。难道我只用线程定期列出所有名称来找出新对象吗?
请注意,远程对象将从不同节点导出,而不是从同一节点导出。我知道它们是否来自同一个节点,可能我可以使用从实例化远程对象之一调用的回调功能。
How can RMI client sees and get all dynamic remote objects registered in a registry?
通过调用 Naming.list()
或 Registry.list().
I have a requirement that the RMI client needs to get all remote objects registered in a remote RMI registry.
见上文。
How do I get the objects of exactly the type I want (implementing the interface that I want), supposed that there are also other kinds of objects registered as well? Shall I traverse the names and use a try/catch statement, trying to instanced each remote objects?
遍历list()
返回的名字即可; lookup()
每一个;然后用instanceof
判断是否是你需要的类型。如果注册表包含存根,您在客户端没有所有必要的 类,则需要捕获 ClassNotFoundException
。通过 JNDI listBindings()
方法以更少的步骤完成所有这些操作的简单方法。
Second question, how can a client gets noticed if a new object is registered?
不能。没有为 RMI 注册表定义的侦听器系统。客户端将不得不轮询。
In my requirement, the servers will dynamicly registered new objects in to registry, and the client needs to get updated and access the new objects sooner. Shall I just use a thread to periodically list all names to find out new objects?
是的。
Please note that the remote objects are to be exported from different nodes, but not from a same node.
您会发现这很难安排,因为您只能从与注册表相同的主机调用 bind()
和朋友。您必须组织一些中间远程对象来为每个非本地节点进行注册。
I know if they are from the same node, possibly I can use the call-back feature called from one of the instanced remote-object.
来自同一个节点并不是这样做的先决条件。您可以在防火墙不妨碍的任何拓扑中执行 RMI 回调。
我有一个要求,即 RMI 客户端需要获取在远程 RMI 注册表中注册的所有远程对象。
第一个问题,我知道有一个 registry.list() 方法可以 returns 所有对象的名称。但是,如果还注册了其他类型的对象,我该如何获得我想要的类型的对象(实现我想要的接口)。我应该遍历名称并使用 try/catch 语句,尝试实例化每个远程对象吗?
第二个问题,如果注册了一个新的对象,怎么才能让客户端注意到呢?在我的要求中,服务器会将新对象动态注册到注册表中,客户端需要尽快更新并访问新对象。难道我只用线程定期列出所有名称来找出新对象吗?
请注意,远程对象将从不同节点导出,而不是从同一节点导出。我知道它们是否来自同一个节点,可能我可以使用从实例化远程对象之一调用的回调功能。
How can RMI client sees and get all dynamic remote objects registered in a registry?
通过调用 Naming.list()
或 Registry.list().
I have a requirement that the RMI client needs to get all remote objects registered in a remote RMI registry.
见上文。
How do I get the objects of exactly the type I want (implementing the interface that I want), supposed that there are also other kinds of objects registered as well? Shall I traverse the names and use a try/catch statement, trying to instanced each remote objects?
遍历list()
返回的名字即可; lookup()
每一个;然后用instanceof
判断是否是你需要的类型。如果注册表包含存根,您在客户端没有所有必要的 类,则需要捕获 ClassNotFoundException
。通过 JNDI listBindings()
方法以更少的步骤完成所有这些操作的简单方法。
Second question, how can a client gets noticed if a new object is registered?
不能。没有为 RMI 注册表定义的侦听器系统。客户端将不得不轮询。
In my requirement, the servers will dynamicly registered new objects in to registry, and the client needs to get updated and access the new objects sooner. Shall I just use a thread to periodically list all names to find out new objects?
是的。
Please note that the remote objects are to be exported from different nodes, but not from a same node.
您会发现这很难安排,因为您只能从与注册表相同的主机调用 bind()
和朋友。您必须组织一些中间远程对象来为每个非本地节点进行注册。
I know if they are from the same node, possibly I can use the call-back feature called from one of the instanced remote-object.
来自同一个节点并不是这样做的先决条件。您可以在防火墙不妨碍的任何拓扑中执行 RMI 回调。