RMI Registry Service Provider for JNDI
by, 07-07-2012 at 04:23 PM (1619 Views)
Service providers like RMI registry permits the applications of JNDI so that remote objects could be accessed that are registered along with “RMI registry”. Once registry location is known, naming context is created by the provider for those objects that have been registered into registry. In some other JNDI namespace, like LDAP, it is possible to bind this context. Functionality that has been offered by class java.rmi.Naming gets subsumed by this new functionality.
Major benefit to use RMI is that it is no longer required by the clients to know port number and hostname where RMI registry runs; it is location independent.
How to use JNDI with RMI is given as following:
Java Code:// select the registry service provider as the initial context env.put(Context.INITIAL_CONTEXT_FACTORY, "RegistryContextFactory"); // specify where the registry is running env.put(Context.PROVIDER_URL, "rmi://server:1099"); // create an initial context that accesses the registry Context ctx = new InitialContext(env); // now, the names stored in registry can be listed NamingEnumeration enum = ctx.list(""); // bind the registry context into LDAP directory Context ldapctx = (Context)ctx.lookup("ldap://server:port/o=comp,c=ca"); ldapctx.bind("cn=rmi", ctx);