com.netscape.jndi.ldap.common
Class ShareableEnv

java.lang.Object
  extended by com.netscape.jndi.ldap.common.ShareableEnv
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
ContextEnv

public class ShareableEnv
extends java.lang.Object
implements java.lang.Cloneable

ShareableEnv manages a set of environment properties. The class enables a memory efficient sharing of the environment between multiple contexts, while preserving the semantics that each context has its own environment. If the environment for a context is changed, the change is not visible to other contexts. The efficiency is achieved by implementing inheritance and override of environment properties ("subclass-on-write"). A read-only table of properties is shared among multiple contexts (_sharedEnv. If a context wants to modified a shared property, it will create a separate table (_privateEnv) to make the modifications. This table overrides the values in the shared table. Note1: The class is not thread safe, it requires external synchronization Note2: The class does not provide enumaration. Call getAllProperties() and then use the standard Hashtable enumaration techniques.


Field Summary
protected  ShareableEnv m_parentEnv
          Shared environment inherited from the parent context
protected  int m_parentSharedEnvIdx
          Index into parent _sharedEnv list.
protected  java.util.Hashtable m_privateEnv
          A table of most recent environment modifications.
protected  java.util.Vector m_sharedEnv
          A set of environment propeties that have been changed in this Context and are shared with one or more child contexts.
 
Constructor Summary
ShareableEnv(java.util.Hashtable initialEnv)
          Constructor for the root context
ShareableEnv(ShareableEnv parent, int parentSharedEnvIdx)
          Constructor for non root Contexts
 
Method Summary
 java.lang.Object clone()
          Clone ShareableEnv
protected  void freezeUpdates()
          Freeze all environment changes changes in the current context.
 java.util.Hashtable getAllProperties()
          Create a table of all properties.
 java.lang.Object getProperty(java.lang.String prop)
          Get the property value.
static void main(java.lang.String[] args)
          Test program
 java.lang.Object removeProperty(java.lang.String prop)
          Remove property
 java.lang.Object setProperty(java.lang.String prop, java.lang.Object val)
          Set the property value.
 java.lang.String toString()
          Return string representation of the object
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_privateEnv

protected java.util.Hashtable m_privateEnv
A table of most recent environment modifications. These modifications are not shared until the current context is cloned, which moves _privateEnv to _sharedEnv


m_sharedEnv

protected java.util.Vector m_sharedEnv
A set of environment propeties that have been changed in this Context and are shared with one or more child contexts. Read-only access.


m_parentEnv

protected ShareableEnv m_parentEnv
Shared environment inherited from the parent context


m_parentSharedEnvIdx

protected int m_parentSharedEnvIdx
Index into parent _sharedEnv list. Designates all environment chnages in the parent context that are visible to this child context

Constructor Detail

ShareableEnv

public ShareableEnv(ShareableEnv parent,
                    int parentSharedEnvIdx)
Constructor for non root Contexts

Parameters:
parent - A reference to the parent context environment
parentSharedEnvIdx - index into parent's shared environemnt list

ShareableEnv

public ShareableEnv(java.util.Hashtable initialEnv)
Constructor for the root context

Parameters:
initialEnv - a hashtable with environemnt properties
Method Detail

setProperty

public java.lang.Object setProperty(java.lang.String prop,
                                    java.lang.Object val)
Set the property value.

Parameters:
prop - property name
val - property value
Returns:
the previous value of the specified property, or null if it did not exist before.

getProperty

public java.lang.Object getProperty(java.lang.String prop)
Get the property value.

Parameters:
prop - property name
Returns:
the object associated with the property name or null if property is not found

removeProperty

public java.lang.Object removeProperty(java.lang.String prop)
Remove property

Parameters:
prop - property name
Returns:
the previous value of the specified property, or null if it did not exist before.

getAllProperties

public java.util.Hashtable getAllProperties()
Create a table of all properties. First read all properties from the parent env, then merge the local updates. Notice that the data is processed in reverse order than in the getProperty method.

Returns:
a hashtable containing all properties visible in this context

freezeUpdates

protected void freezeUpdates()
Freeze all environment changes changes in the current context. The "Freeze" is done by moving the _privateEnv table to _sharedEnv vector.


clone

public java.lang.Object clone()
Clone ShareableEnv

Overrides:
clone in class java.lang.Object
Returns:
A "clone" of the current context environment

toString

public java.lang.String toString()
Return string representation of the object

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object

main

public static void main(java.lang.String[] args)
Test program