• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

rmiregistry - LocalRegistry.getRegistry()

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am at the beginning of getting RMI implemented on my server and ran into the following problem. I use LocalRegistry.getRegistry(Registry.REGISTRY_PORT) to check if rmiregistry is already running assuming I will get a RemoteExecption() if it is not (unable to create a reference to it). If I get a RemoteException() I then do LocateRegistry.createRegistry(Registry.REGISTRY_PORT) to start rmiregistry.

So far it seems getRegistry() is "successful" if rmiregistry is running or not. If I manually start rmiregistry then start the server, getRegistry() does invoke an exception and my later Naming.rebind() method fails. If rmiregistry is not running getRegistry() still does not fail and of course my rebind() fails. However, if rmiregistry is not running and I do a createRegistry(), the creatRegistry() is "successful" and my rebind() works. However, if I start rmiregistry manually then invoke createRegistry(), it gets the expected RemoteException.

I am a bit confused by this. I could just do createRegistry() and if I get a RemoteException assume that rmiregistry is already running. This does not seem to be a very clean approach assuming that there are other reasons that createRegistry() can invoke RemoteException.

Any ideas? Thanks!
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
This is from javadoc spec of java.rmi.registry.LocateRegistry

<p> Note that a <code>getRegistry</code> call does not actually make a
* connection to the remote host. It simply creates a local reference to
* the remote registry and will succeed even if no registry is running on
* the remote host. Therefore, a subsequent method invocation to a remote
* registry returned as a result of this method may fail.



I'm doing like this : to be sure that a rmi registry runs on a host , on the registry obtained by the call , I call a convenience method, for example .
If I have no exception, I assume that the registry is running. If there is no registry running, invoking this method will throw an exception.

I'm not very happy with this solution. Does anybody has some better idea ?
 
John Deal
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Liviu. I implemented your suggestion of using list() to test the registry stub but now I am having some rmic and ClassNotFound issues with my stub that maybe influencing this problem. After I solve that I will try to resolve this! Thanks.
 
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Deal:
Hello Liviu. I implemented your suggestion of using list() to test the registry stub but now I am having some rmic and ClassNotFound issues with my stub that maybe influencing this problem. After I solve that I will try to resolve this! Thanks.






This is the code I used createRegistry to programatically start the rmi registry as this was a requirement of my project. There is no need to call UnicastRemoteObject.exportObject when you call this method.

I don't bother to verify that it starts because if it doesn't then the getRegistry will throw an exception, give an error message to the client and then exit the application.

Mark.
 
Liviu Carausu
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



I don't bother to verify that it starts because if it doesn't then the getRegistry will throw an exception, give an error message to the client and then exit the application.



If the rmi registry already runs at the specified port, I think it must be used. Or ? Should we just fail because we cannot start our own ?
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Liviu Carausu:


If the rmi registry already runs at the specified port, I think it must be used. Or ? Should we just fail because we cannot start our own ?



Well I don't think that you can rely on the examiner starting the registry for the purposes of this exam although the instructions are not clear in this regard, it is probably best to start it yourself. If the port is already in use we can always select another one to try!

Mark.
reply
    Bookmark Topic Watch Topic
  • New Topic