This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Out of 2 RMI registries on the same host, only one can be referenced remotely  RSS feed

 
Bill Jurgen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

What could you suggest?

Thank you in advance.


 
Bill Jurgen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Windows Firewall service is stopped on both the machines, and there is no other firewall between them. Each of the machines has the IP address and name of the other in its Windows hosts file.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bill Jurgen
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tim Holloway
Bartender
Posts: 18709
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!