|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 3 of 4
Hashtable instance): Hashtable hashtableEnvironment = new Hashtable();
hashtableEnvironment.put(
Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory"
);
// the service: ldap://localhost:389/
// the root context: dc=etcee,dc=com
hashtableEnvironment.put(
Context.PROVIDER_URL,
"ldap://localhost:389/dc=etcee,dc=com"
);
hashtableEnvironment.put(
Context.SECURITY_PRINCIPAL,
"name"
);
hashtableEnvironment.put(
Context.SECURITY_CREDENTIALS,
"password"
);
Context instance. If you intend to perform a directory operation as well, you'll need a DirContext instance instead. Not all providers supply both:Context context = new InitialContext(hashtableEnvironment);
Or:
DirContext dircontext = new InitialDirContext(hashtableEnvironment);
That's all there is to it. Now let's look at how applications store objects to and retrieve objects from JNDI.
The ability to store Java objects is useful: object storage provides persistence and allows objects to be shared between applications or between different executions of the same application.
From the standpoint of the code involved, object storage is surprisingly easy:
context.bind("name", object)
The bind() operation binds a name to a Java object. The syntax of the command is reminiscent of RMI, but the semantics are not as clearly
defined. It's permissible for the bind() operation to store either a snapshot of the object or a reference to a "live" object, for example.
Be aware that the bind() operation throws a NamingException if an exception occurs during the execution of the operation.
Now let's take a look at the bind() operation's complement -- lookup():
Object object = context.lookup("name")
The lookup() operation retrieves the object bound to the specified name. Once again, the syntax is reminiscent of RMI, but the method's
semantics are not as clearly defined.
Just as with bind(), the lookup() operation throws a NamingException if an exception occurs during the execution of the operation.
What does it mean to store an object in a JNDI naming and directory service? We've already mentioned that the exact semantics
of the bind() and lookup() operations aren't tightly defined; it's up to the JNDI service provider to define their semantics.
According to the JNDI specification, service providers are encouraged (but not required) to support object storage in one of the following formats:
If all JNDI service providers support these standard mechanisms, Java programmers are free to develop generic solutions that work even when the underlying service provider layer changes.