Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

RMI: LocateRegistry.getRegistry(int port)

Thread view: 
Mike - 01 Nov 2005 00:38 GMT
Hi,

I wonder why the method "LocateRegistry.getRegistry(int port)" doesn't throw
an exception if no registry is available?

This seems a really bad design to me. I allways get a registry with this
method (even if no registry has been created) but when I try to bind some
object I get an exception, no wonder, there is no registry, so why is this
not notified by  the getRegistry method???

See the code bellow for details (I'm using j2sdk1.4.2_02 / Windows XP):

[BEGIN CODE]

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;

public class StupidRegistry extends UnicastRemoteObject implements
DummyRemoteInterface {

   protected StupidRegistry() throws RemoteException {
       super();
   }

   public static void main(String[] args) {
       Registry reg = null;
       try {
           reg = LocateRegistry.getRegistry(12321);
       } catch (RemoteException e) {
           System.out.println("couldn't get the registry, nice to be
notified of this!");
       }
       // well, it seems we got the registry, let's bind something...
       StupidRegistry sr = null;
       try {
           sr = new StupidRegistry();
       } catch (RemoteException e) { }
       try {
           reg.bind("I guess I won't be bound", sr);
       } catch (AccessException e) {
       } catch (RemoteException e) {
           System.out.println("Well, I guess there is no registry...");
           System.exit(-1);
       } catch (AlreadyBoundException e) {
       }
   }
}

interface DummyRemoteInterface extends Remote { }

class StupidRegistry_Stub extends RemoteStub implements
DummyRemoteInterface, Remote {
   public StupidRegistry_Stub() {
       super();
   }
   public StupidRegistry_Stub(RemoteRef ref) {
       super(ref);
   }
}

[END CODE]

This will allways prints "Well, I guess there is no registry...". (Unless
you've got a registry allready running and listening to the used
port...)

I really don't see why the getRegistry method doesn't throw any exception. I
do
actually expect that exception. Why do I get a non usable registry? What
is this good for?

Is there any way to check that the registry returned by the getRegistry
method is usable before trying to bind anything to it ?

Greetings,

Mike
E.J. Pitt - 14 Nov 2005 08:19 GMT
> I wonder why the method "LocateRegistry.getRegistry(int port)" doesn't throw
> an exception if no registry is available?

The reason is the bootstrap problem. A remote reference can only be
acquired as the result of a remote method, and a remot method can only
be called via a remote reference.

The Registry is only there to provide the necessary bootstrap to get out
of this loop, otherwise it wouldn't really be necessary.

This means that the stub returned by LocateRegistry.getRegistry() is
*not* the result of a remote method, it is synthesized locally using the
materials you provided: the host and the port. It is not guaranteed to
represent any real existing Registry, you have to suck it and see.

> Is there any way to check that the registry returned by the getRegistry
> method is usable before trying to bind anything to it ?

If you don't like bind(), you could try to list() it, but there's no
real point, you're better off just catching the exception from bind()
and saving the extra (RMI) call.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.