220 likes | 362 Views
Java Naming and Directory Interface. Contents. Naming and directory services JNDI RMI Conclusion. Naming and directory services. Naming service. M eans by which names are associated with objects Examples: Electronic mail system File system Domain name system. Some definitions.
E N D
Contents • Naming and directory services • JNDI • RMI • Conclusion
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
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, "http://jndiprovider-database" ); 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
References • http://en.wikipedia.org/wiki/Java_Naming_and_Directory_Interface • http://java.sun.com/docs/books/tutorial/jndi/index.html • http://en.wikipedia.org/wiki/Java_RMI • http://java.sun.com/docs/books/tutorial/rmi/index.html