I have client A and server B and a class O. Client A would like to execute an instance of O remotely on server B. (Client A has access to an interface for O, of course). Therefore, server B created an RMI registry and binds address "//B:1009/O" to its instance of O so A can look it up and remotely use it.

Now, a person has told me that if there are multiple servers, there's no need to create more RMI registries. That is, if client A wants to execute another instance of O, which is on server C, then C does not have to create its own RMI registry. Instead, it can use B's RMI registry, and simply bind address "//B:1009/C" to its instance of O.

Well, it looks to me that C cannot borrow B's RMI registry. Here's a demo. Please let me know if that's just how it works or I'm doing something wrong:


the following code is executed on server B and it starts up RMI service just fine.

        try {              
            java.rmi.registry.LocateRegistry.createRegistry(8009);   
            Naming.rebind ("//<B's address>:8009/HelloB", new Hello ("Hello, world! from server B"));   
            System.out.println ("Hello Server B is ready.");   
        } catch (Exception e) {   
            e.printStackTrace();   
        }

the following code if executed on server C (note it tries to use server B's address to bind its own Hello instance) ...

        try{   
            // C doesn't create its own RMI registry   
            Naming.rebind ("//<B's address>:8009/HelloC", new Hello ("Hello, world! from server C"));   
            System.out.println ("Hello Server C is ready.");   
        } catch (Exception e) {   
            e.printStackTrace();   
        }

... will throw the following E:
java.rmi.AccessException: Registry.Registry.rebind disallowed; origin /<C's address> is non-local host