Thursday, June 5, 2008

Is RMIRegistry a JNDI service provider?


The JNDI architecture consists of an API and a service provider interface (SPI). Java applications use the JNDI API to access a variety of naming and directory services. The SPI enables a variety of naming and directory services to be plugged in transparently.RMIRegistry is also one type of JNDI provider besides Ldap, File System.


envs.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.rmi.registry.RegistryContextFactory");
envs.put(Context.PROVIDER_URL, "rmi://localhost:1099");

RegistryContextFactory implements getInitialContext() method.JNDI provides a naming context, which is a a set of name-to-object bindings. All naming operations are relative to a context.A name that is bound within a context is the JNDI name of the object. A Context object provides the methods for binding names to objects, unbinding names from objects, renaming objects, and listing the bindings.

File System: file name -> file (accessed via file handler)
DNS: machine name -> IP
LDAP: Ldap name -> Ldap entry

The Initial Context
In the JNDI, all naming and directory operations are performed relative to a context. There are no absolute roots. Therefore the JNDI defines an initial context, InitialContext(in the API reference documentation), which provides a starting point for naming and directory operations. Once you have an initial context, you can use it to look up other contexts and objects.When the initial context is constructed, its environment is initialized with properties defined in the environment parameter passed to the constructor, and in any application resource files.

JNDI determines each property's value by merging the values from the following two sources, in order:

1. The first occurrence of the property from the constructor's environment parameter and (for appropriate properties) the applet parameters and system properties.
2. The application resource files (jndi.properties).

No comments: