javarmirmiregistry

How can RMI client sees and get all dynamic remote objects registered in a registry?


I have a requirement that the RMI client needs to get all remote objects registered in a remote RMI registry.

First question, I know there is a method of registry.list() that returns all names of the objects. However 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?

Second question, how can a client gets noticed if a new object is registered? 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. 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.


Solution

  • How can RMI client sees and get all dynamic remote objects registered in a registry?

    By calling Naming.list() or Registry.list().

    I have a requirement that the RMI client needs to get all remote objects registered in a remote RMI registry.

    See above.

    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?

    Just traverse the names returned by list(); lookup() each one; and use instanceof to determine whether it is of a type you need. If the Registry contains stubs you don't have all the necessary classes for at the client, you'll need to catch ClassNotFoundException. An easy way to do all this in fewer steps is via the JNDI listBindings() method.

    Second question, how can a client gets noticed if a new object is registered?

    It can't. There is no listener system defined for the RMI Registry. The client will have to poll.

    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?

    Yes.

    Please note that the remote objects are to be exported from different nodes, but not from a same node.

    You'll find that difficult to arrange, as you can only call bind() and friends from the same host as the Registry. You'll have to organize some intermediate remote objects to do the registering for each non-local node.

    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.

    Being from the same node isn't a precondition for that. You can do RMI callbacks in any topology where firewalls don't get in the way.