Server via RMI without registry

后端 未结 3 474
囚心锁ツ
囚心锁ツ 2021-02-06 15:49

I have a service object that can be connected to via RMI. Currently I\'m doing this:

Server

Registry r = LocateRegistry.createRegistry(1         


        
相关标签:
3条回答
  • 2021-02-06 16:08

    The RMI Registry exists to solve the RMI bootstrap problem, which is simply that you can only get a remote stub via a remote method call, and to perform a remote method call you need a remote stub. The Registry reference provided by LocateRegistry.getRegistry() solves this problem (and is used internally by Naming.lookup() if you are using that API). [Note that this stub isn't obtained via a remote method: it is synthethized locally using the host:port you provide. If they aren't correct you won't find out until you use the Registry stub.]

    You have several choices to solve the RMI bootstrap problem:

    1. Use the RMI Registry.

    2. Use an LDAP server via JNDI with the LDAP provider.

    3. Use UnicastRemoteObject, serialize the stub obtained when you export the object, and use a shared file, or a socket, or sneakernet, to make the stub available to clients.

    4. Use RMI Activation; serialize the stub obtained when you registered the activatable, and distribute to all clients in a file, along with the client application. From the point of view of stub distribution this is a lot simpler than (3) because the stub remains constant for the life of the application, whereas in (3) you have to redestribute the stub on every export.

    You can see that the Registry is certainly the simplest option. Note that you only have to use it to solve the bootstrap problem Once you have a stub, your own application remote methods can return further objects: you don't need more than one remote object in the Registry. You can consider that as a remote object factory.

    0 讨论(0)
  • 2021-02-06 16:08

    Client uses an rmi URL like rmi://localhost:2020/server

    see https://stackoverflow.com/a/61210297/503025

    0 讨论(0)
  • 2021-02-06 16:13

    Not impossible, but not terribly practical because the registry communicates the stub object of the exported object to the client (see http://www.developer.com/print.php/3455311). If you don't have another mechanism for that, you'll be stuck. Use of a registry in distributed systems has other benefits, so I'd actually recommend keeping it for other reasons (location transparency, etc).

    0 讨论(0)
提交回复
热议问题