Simple entry point for a single RMI service?

I have several services that export an RMI interface.

They suggested this by creating their own registry (with LocateRegistry.createRegistry ) and binding it there. However, this became impossible when the services were moved to run as separate applications in the same VM (Tomcat), because for some reason only one registry could be present there.

I worked on this using a central registry for all services. Even in this case, I am not interested in the role of the registry registry related to several objects, as well as its entry point. However, the central registry introduces a lot of complexity (for example, it must be started first, it must have the service interfaces that it registers).

Is there a way to return the situation where each service independently offers an entry point to its RMI interface, and when launched in the same virtual machine (which is part of the host, and not part of the design)?

+2
source share
3 answers

I forgot that I already asked a similar question (for another reason, cutting the code before I moved the services together to 1 VM), where the first answer offers a way to get around the registry:

Use UnicastRemoteObject, serialize the stub obtained by exporting the object and use a shared file, or socket, or sneakernet to make it accessible to clients.

0
source

You cannot have more than one registry for the JVM, because the registry has a fixed RMI object identifier. Just configure all your servers like this:

 static Registry registry; // ... try { registry = LocateRegistry.createRegistry(Registry.REGISTRY_PORT); } catch (...) // whatever the exception is, probably ExportException { registry = LocateRegistry.locateRegistry(Registry.REGISTRY_PORT); } registry.rebind(...); // etc 

Then, no matter which one of them starts, the registry starts first, and the rest will use it.

0
source

If you are still interested in this problem in a year ....

You can run multiple registries in the same JVM. Just call LocateRegistry.getRegistry with individual ports. You should have well-known ports for each service, but I think you already do this if you have implemented option 3 of this answer to another question .

For a long time, there was a bug that prevented multiple registries from coexisting in the same JVM, but this was fixed in JDK 5. There might be something in Tomcat that prevents multiple RMI registries from starting. Or maybe the version of Tomcat you used was on top of the very old JDK.

0
source

Source: https://habr.com/ru/post/1337959/


All Articles