Package com.netscape.jndi.ldap.common
Class ShareableEnv
java.lang.Object
com.netscape.jndi.ldap.common.ShareableEnv
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
ContextEnv
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
FieldsModifier and TypeFieldDescriptionprotected ShareableEnv
Shared environment inherited from the parent contextprotected int
Index into parent _sharedEnv list.A table of most recent environment modifications.A set of environment propeties that have been changed in this Context and are shared with one or more child contexts.private static final Object
A special value that denotes a removed propety. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
No-arg constructor is privateShareableEnv
(ShareableEnv parent, int parentSharedEnvIdx) Constructor for non root ContextsShareableEnv
(Hashtable<Object, Object> initialEnv) Constructor for the root context -
Method Summary
Modifier and TypeMethodDescriptionclone()
Clone ShareableEnvprotected void
Freeze all environment changes changes in the current context.Create a table of all properties.getAllSharedProperties
(int envIdx) Create a table of all shared properties for the given envIdx.getProperty
(String prop) Get the property value.private Object
getSharedProperty
(int envIdx, String prop) Get the property value for the specified _sharedEnv indexstatic void
Test programremoveProperty
(String prop) Remove propertysetProperty
(String prop, Object val) Set the property value.toString()
Return string representation of the object
-
Field Details
-
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
A table of most recent environment modifications. These modifications are not shared until the current context is cloned, which moves _privateEnv to _sharedEnv -
m_parentEnv
Shared environment inherited from the parent context
-
-
Constructor Details
-
ShareableEnv
private ShareableEnv()No-arg constructor is private -
ShareableEnv
Constructor for the root context- Parameters:
initialEnv
- a hashtable with environemnt properties
-
-
Method Details
-
setProperty
Set the property value.- Parameters:
prop
- property nameval
- property value- Returns:
- the previous value of the specified property,
or
null
if it did not exist before.
-
getProperty
Get the property value.- Parameters:
prop
- property name- Returns:
- the object associated with the property name
or
null
if property is not found
-
removeProperty
Remove property- Parameters:
prop
- property name- Returns:
- the previous value of the specified property,
or
null
if it did not exist before.
-
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
Clone ShareableEnv -
toString
Return string representation of the object -
main
Test program
-