2

I'm having a little trouble with Java RMI.

Am I able to check if a registry exists? This line of code is supposed to give me the registry.

LocateRegistry.getRegistry(ip, Registry.REGISTRY_PORT);

But when I call it with a wrong IP address or an IP address where no registry can be found, the method gets stuck.

So my question is, can i somehow check if there is a registry at a certain IP address BEFORE calling getRegistry()?

Bhavik Ambani
  • 6,557
  • 14
  • 55
  • 86
X.X_Mass_Developer
  • 717
  • 1
  • 8
  • 23

1 Answers1

2

No. In any case the best way to test the availability of any resource is to try to use it. In this case, call lookup() and catch the exception. You have to do that anyway, so doing it twice is pretty pointless.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • I see. Thats exactly how i did it. The problem is, that the method getRegistry() blocks the program. I was able to check that after a few minutes the method returns and then lookup throws the exception. In my usecase this is unfortunately too slow. – X.X_Mass_Developer Dec 09 '12 at 09:20
  • @X.X_Mass_Developer The method getRegistry() shouldn't block the program. It doesn't do any network operations. I can imagine lookup() blocking: not getRegistry(). – user207421 Dec 09 '12 at 09:34
  • Certainly you are right! It's lookup that is blocking. So can I somehow check if the Registry returned by getRegistry() is valid? If I call list() to check wheter the server I'm locking for is there, it also blocks. – X.X_Mass_Developer Dec 09 '12 at 10:35
  • @X.X_Mass_Developer As I said, the best way is to try to use it. You should look at the RMI system properties pages for ways to tune the various timeouts. – user207421 Dec 09 '12 at 19:43
  • Thanks, but I couldn't find anything helpful in the properties pages. – X.X_Mass_Developer Dec 10 '12 at 10:53
  • @X.X_Mass_Developer You couldn't find the connect timeout property? – user207421 Dec 10 '12 at 11:03
  • No because I didn't found a property page for the registry or the lookup method. Have you found one? – X.X_Mass_Developer Dec 10 '12 at 11:13
  • @X_X_Mass_Developer There are two properties pages for the whole of RMI. I am not able to believe you couldn't find those. – user207421 Mar 01 '14 at 10:59
  • 1
    This question was asked a long time ago, but as far as I can remember I was not able to find those pages. Just for curiosity, can you provide the link? – X.X_Mass_Developer Mar 02 '14 at 14:10
  • @X.X_Mass_Developer http://docs.oracle.com/javase/8/docs/technotes/guides/rmi/javarmiproperties.html and https://docs.oracle.com/javase/8/docs/technotes/guides/rmi/sunrmiproperties.html. – user1803551 Sep 13 '16 at 01:44