I have 2 processes (let’s name them A and B) in different JVMs, but on the same host. Each of these processes creates an RMI registry (let's call them RegistryA and RegistryB) using LocateRegistry.createRegistry( int port ). RegistryA listens on the default 1099 port, and RegistryB listens on a different port.
When I try to get a reference to RegistryB from a remote host using LocateRegistry.getRegistry( String host, int port ) , I always get a reference to RegistryA instead, regardless of the port number I make RegistryB listen on. When I try to get a reference to RegistryB from the same host where it is located, I have to specify as the first argument either the fully qualified domain name of the host or null. If I put the word “localhost” as the first argument, I again get a reference to RegistryA regardless of what I specify as the second argument.
After a few hours of googling, I found only an advice to use just one RMI registry. But I would like to avoid it to keep process A and process B more isolated from each other.
Bill Jurgen wrote: I have to specify as the first argument either the fully qualified domain name of the host or null. If I put the word “localhost” as the first argument, I again get a reference to RegistryA regardless of what I specify as the second argument.
If you are calling getRegistry from a remote host, why would you use "localhost"?
localhost is a loopback interface for the same machine.
If you do not specify a host i.e. pass null, then also it takes the host as "locahost", so technically specifying localhost OR null should have the same effect, unless you have groovy host name settings.
You can have as many number of RMIRegistries on a single box as you want as long as they use different ports.
Excuse me for ambiguity. When I noticed the problem with calling getRegistry(String, int) from a remote host, I decided to call it from the same host where the registry is and use "localhost" as the first argument. I did it just for testing purposes.
I agree that null or "localhost" should yield the same results, and it puzzles me why they don't.
Most of the time, it's cleaner just to run one master registry on one port (1099 for example) and let the various services register themselves with it. That means that the registry server should be running stand-alone (or as part of an independent service such as a webapp container), and not as a dependent component of an application. Two servers are more for things like where one is for testing and one is for production or you're a service bureau and each server is for a separate client.
If you absolutely must run 2 servers and there are no distinctions such as the above, you might consider proxying them with a third server so that external requesters see them as a single server. Offhand, I don't know of an app that does that, unless maybe the Apache directory server can. But there probably are some.
"localhost" is a very problematic name to use in Java due to forward/reverse lookup issues. Usually you get happier results if you supply the server's actual name, even though that's less portable.
Bjoke: A "Bully Joke". A Statement or action made with malicious intent - unless challenged. At which point it magically transforms into "I was just funnin'" or "What's the matter, can't take a joke?"
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop