Java Naming and Directory Interface
Contents Naming and directory services JNDI RMI Conclusion
Naming and directory services
Naming service Means by which names are associated with objects Examples: Electronic mail system File system Domain name system
Some definitions Binding – the association of a name with an object Reference – represents information about how to access an object Context – set of name-to-object bindings has an associated naming convention name in one context object can be bound to another context object (subcontext)
Directory service Associates names with objects and also associates such objects with attributes Directory service = naming service + objects containing attributes (directories)
Some more definitions Directory object – object with attributes Directory – connected set of directory objects
JNDI
JNDI API – provides naming and directory functionality to Java applications Independent of any specific directory service implementation JNDI Server provider interface (SPI) – enables a variety of naming and directory services to be plugged in transparently
JNDI architecture
Context javax.naming.Context – the core interface looking up list bindings binding/unbinding renaming objects creating subcontexts destroying subcontexts
Initial context Hashtable args = new Hashtable(); args.put( Context.INITIAL_CONTEXT_FACTORY, "com.jndiprovider.TheirContextFactory"); args.put( Context.PROVIDER_URL, " ); myCurrentContext = new InitialContext(args);
Directory context javax.naming.directory.DirContext – interface represents a directory context getAttributes() modifyAttributes()
Event package javax.naming.event – contains classes and interfaces for supporting event notification in naming and directory services NamingEvent – an event that is generated by a naming/directory service NamingListener – an object that listens for NamingEvents
Service provider package javax.naming.spi – provides the means by which naming/directory service providers can be hooked up The corresponding services are accessible from applications that use the JNDI
RMI
Often comprise two separate programs, a server and a client The mechanism by which the server and the client communicate and pass information back and forth
Server & client Typical server Creates some remote objects Makes references to these objects accessible Waits for clients to invoke methods on these objects Typical client Obtains a remote references to some remote objects on a server Invokes methods on them
Remote objects An object becomes remote by implementing a remote interface A remote interface extends the interface java.rmi.Remote Each method of the interface declares java.rmi.RemoteException in its throws clause java.rmi.registry.Registry – API for binding (or registering) and looking up remote objects in the registry
Conclusion
References d_Directory_Interface d_Directory_Interface dex.html dex.html dex.html dex.html
Questions