JNDI Environment & Service Naming Contexts

Version:
$Revision: 1.2 $ $Date: 2001/06/04 10:23:21 $
Author:
Remus Pereni

This package was inspired by the tyrex.naming package from the Tyrex project. All credits for the good stuff should go to Assaf Arkin and the Exolab group, all the bad stuff blame it on me :).

An in-memory namespace is available through the {@link org.media.naming.MemoryContext} JNDI service provider. The in-memory namespace holds objects directly in memory including factories and services that cannot be held in a persistent namespace. It supports two modes of operation, a tree shared between all instances through a shared namespace, and trees created dynamically with access controlled by their creator. See In-Memory Context for more details.

The in-memory JNDI service provider has the following properties:

The caller must had adequate security permission to access the shared in-memory namespace (creating a private namespace requires no permission) and to set/unset the ENC for the current thread, see Access Permissions for more details.

In-Memory Context

{@link org.media.naming.MemoryContext} is an in-memory JNDI service provider. It binds objects into a namespace held entirely in memory, supporting serializable, remoteable and local objects. The in-memory service provider is particularly useful for holding resource factories (the JNDI ENC) and exposing run-time services and configuration objects.

An instance of {@link org.media.naming.MemoryContext} constructed with no environment attribute will use it's own tree of bindings. Such a tree is no accessible except through context created from the original context, and is garbage collected when all such contexts are no longer referenced. If necessary the root context can be duplicated using lookup( "" ).

If the environment attribute {@link javax.naming.Context#PROVIDER_URL PROVIDER_URL} is used, the context will reference a node in a tree shared by all such contexts. That tree is statically held in memory for the life time of the virtual machine.

{@link org.media.naming.MemoryContextFactory} implements a context factory for {@link org.media.naming.MemoryContext}. When set properly {@link javax.naming.InitialContext} will return a {@link org.media.naming.MemoryContext} referencing the named path in the memory model. Typically applications will use it to construct an in-memory namespace under the shared root, e.g.:

MemoryContextFactory factory;
Hashtable            env;

// Set up the path
env = new Hashtable();
env.put( Context.PROVIDER_URL, "services" );
// Obtain the context for services
factory = new MemoryContextFactory();
ctx = factory.getInitialContext( env );

// Alternatively, construct MemoryContext directly

env = new Hashtable();
env.put( Context.PROVIDER_URL, "services" );
ctx = new MemoryContext( env );