Class ShareableEnv

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

public class ShareableEnv extends Object implements 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 Details

    • REMOVED_PROPERTY

      private static final Object REMOVED_PROPERTY
      A special value that denotes a removed propety. Because shared property tables are read-only, a shared property is deleted in the curent context by assigning the REMOVED_PROPERTY value in the _modEnv table.
    • m_privateEnv

      protected Hashtable<Object,Object> 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 Vector<Hashtable<Object,Object>> 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 Details

    • ShareableEnv

      private ShareableEnv()
      No-arg constructor is private
    • 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(Hashtable<Object,Object> initialEnv)
      Constructor for the root context
      Parameters:
      initialEnv - a hashtable with environemnt properties
  • Method Details

    • setProperty

      public Object setProperty(String prop, 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 Object getProperty(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
    • getSharedProperty

      private Object getSharedProperty(int envIdx, String prop)
      Get the property value for the specified _sharedEnv index
      Parameters:
      envIdx - start index in the shared environment list
      prop - property name
      Returns:
      the object associated with the property name
    • removeProperty

      public Object removeProperty(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 Hashtable<Object,Object> 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
    • getAllSharedProperties

      private Hashtable<Object,Object> getAllSharedProperties(int envIdx)
      Create a table of all shared properties for the given envIdx. First read all properties from the parent env, then merge the local environment.
      Parameters:
      envIdx - start index in the shared environment list
      Returns:
      a hashtable containing all properties visible for the shared environment index
    • 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 Object clone()
      Clone ShareableEnv
      Overrides:
      clone in class Object
      Returns:
      A "clone" of the current context environment
    • toString

      public String toString()
      Return string representation of the object
      Overrides:
      toString in class Object
      Returns:
      a string representation of the object
    • main

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