9 Replies Latest reply: Jan 21, 2011 11:44 PM by EJP RSS

    Running one rmiregistry for multiple remote object servers

    831202
      Hi,
      I don't find any clear answer for this situation. I want that multiple objet servers (running in separated JVMs) share one rmiregistry placed on a dedicated server. Servers stays in a same network (no firewall at all). If this feature is covered, could you give me any example or link that describe the source code ?

      Thanks very well for yours answers.

      Manuel
        • 1. Re: Running one rmiregistry for multiple remote object servers
          800330
          Recently this forum taught me that running a single registry is not a problem at all , see the [url http://forums.oracle.com/forums/thread.jspa?threadID=2148248&tstart=0]answers to my question here.
          • 2. Re: Running one rmiregistry for multiple remote object servers
            831202
            Thanks for your answer.
            After reading your thread, it's still not clear for me. I suppose it would works (with configuration like java.security.policy and java.rmi.serve. codebase correctly setted) but I don't find any source code example or tutorial about that.
            The main problem seems to bind remote objects from a server directly in the registry. I've already tried it, but without result ...

            Edited by: user2728349 on 14 janv. 2011 07:11
            • 3. Re: Running one rmiregistry for multiple remote object servers
              800330
              From:
              user2728349 wrote:
              The main problem seems to bind remote objects from a server directly in the registry. I've already tried it, but without result ...
              I do not understand what it is that does not work, nor what directly means here.

              In "my" code, I have this line in the application that hosts an object that is to be accessed remotely by a client app:
              reg = LocateRegistry.getRegistry(port);
              and that would let my app register the exported object with whatever process is actually "running" that registry.

              The [url http://download.oracle.com/javase/6/docs/api/java/rmi/registry/LocateRegistry.html]LocateRegistry API allows you to look for a registry at any host or port, suggesting that would work for you, right?

              Edited by: isocdev_mb on 14-Jan-2011 07:45, looked up getRegistry(String host, int port), seems to apply...
              • 4. Re: Running one rmiregistry for multiple remote object servers
                EJP
                The main problem seems to bind remote objects from a server directly in the registry. I've already tried it, but without result ...
                Without result? You mean nothing happened?

                You can bind as many remote objects as you like into a single Registry, from as many JVMs as you like. But they must all be running on the same host as the Registry.
                • 5. Re: Running one rmiregistry for multiple remote object servers
                  831202
                  Thanks again for your help, and sorry for my weak usage of english language.
                  I've tried to bind some remote objects from distinct 'physical' hosts (or computers) to a dedicated registry located on another host.
                  To resume: I want to use one unique registry for multiple remote objects hosts.

                  EJP you have posted : But they must all be running on the same host as the Registry.

                  After reading again the official rmi tutorial, I found :
                  For security reasons, an application can only bind, unbind, or rebind remote object references with a registry running on the same host. This restriction prevents a remote client from removing or overwriting any of the entries in a server's registry. A lookup, however, can be requested from any host, local or remote.

                  This confirm that I wanted to do was not possible.

                  To override this limitation, do you think it's possible to write a remote object located on the registry host, that propose a method used from other hosts to register their remote objects ? Something like that:
                  // Interface
                  public interface recordFromHost extends Remote {
                      int recordObject(String name, Remote obj) throws RemoteException;
                  }
                  
                  // Implementation of interface
                  public class recordFromHostImpl extends UnicastRemoteObject implements recordFromHost {
                  
                      public recordFromHostImpl () throws RemoteException {
                          super();
                      }
                  
                      public int recordObject(String name, Remote obj) {
                         int ret=0;
                          try {
                              Registry registry = LocateRegistry.getRegistry();
                              registry.bind(name, obj);
                          } catch (Exception e) {
                              System.err.println("recordObject exception:");
                              e.printStackTrace();
                              ret = -1;
                          }
                      return ret;
                      }
                  
                  // Server code on registry host
                  public class Serveur {
                  
                  public static void main(String args[]) {
                          // Security manager
                          if (System.getSecurityManager() == null) {
                              System.setSecurityManager(new SecurityManager());
                          }
                          // Start of registry 
                          try{
                              LocateRegistry.createRegistry(1099);
                          }catch(RemoteException e){
                              ...
                              System.exit(1);
                          }
                  
                          try {
                              String name = "recordFromHost";
                              recordFromHost myObj = new recordFromHostImpl ();
                              Registry registry = LocateRegistry.getRegistry();
                              registry.bind(name, myObj);
                          } catch (Exception e) {
                              System.err.println("bind exception:");
                              e.printStackTrace();
                          }
                      }
                  }
                  
                  // Code used from a server host to register his remote object in the distant registry
                  ....
                   Registry registry = LocateRegistry.getRegistry(registry host adress);
                   recordFromHost  myRecord  = (recordFromHost) registry.lookup("recordFromHost");
                  ....
                  Create local remote object to register (remoteObject : interface, remoteObjectImpl : implementation)
                  remoteObject myRemoteObject = new remoteObjectImpl();
                  ...
                  // register myRemoteObject
                  myRecord.recordObject("myRemoteObject", myRemoteObject );
                  ...
                  Finally, a client who want to use myRemoteObject ask the registry for this object, and use it without limitation : the remote object host will not be the registry host.
                  I hope that you understand what I mean :-)

                  Manuel
                  • 6. Re: Running one rmiregistry for multiple remote object servers
                    800330
                    I am wondering: can a reference to a remote object be bound to a second registry? If you can, you'd have each server export the objects to the host registry. Then you have your registry-server obtain all remote object references for each of the servers and add them to its local registry. Clients then contact the registry server and effectively get dispatched to the particular server that provides the service.
                    • 7. Re: Running one rmiregistry for multiple remote object servers
                      831202
                      Hi,

                      I have implemented and tested solution I've proposed in my third post.
                      It works well :-) !

                      I have 3 hosts :

                      The first one (win XP) start a registry and bind a remote method that propose to bind remote objects from remote hosts,
                      The second one (linux) create a local 'remote object', lookup the writed method to bind from the first host and use it to register his remote object,
                      The third (linux) ask the first one for the remote objetc (offered by the second host) and use a method of this object. The method is well executed on the second one.

                      I have used the same java.rmi.server.codebase property with an URL for each host, pointing in a directory with all classes on the first host.
                      Then, In this solution, I provide n servers, each providing remote objects, ans any client could retrieve them with the unique RMI registry.

                      Thanks for your help.
                      Manuel
                      • 8. Re: Running one rmiregistry for multiple remote object servers
                        800330
                        Hi Manuel,

                        Great! And very kind of you, to not leave the issue dangling on the forum while you got 'round it.

                        mb
                        • 9. Re: Running one rmiregistry for multiple remote object servers
                          EJP
                          I am wondering: can a reference to a remote object be bound to a second registry?
                          Sure, as many as you like.