Project Wonder 5.0

er.extensions.foundation
Class ERXThreadStorage

java.lang.Object
  extended by er.extensions.foundation.ERXThreadStorage

public class ERXThreadStorage
extends java.lang.Object

ERXThreadStorage provides a way to store objects for a particular thread. This can be especially handy for storing objects like the current actor or the current form name within the scope of a thread handling a particular request.
The system property er.extensions.ERXThreadStorage.useInheritableThreadLocal defines if the thread storage can be either inherited by client threads (default) or get used only by the current thread. The usage of some types of objects inherited from the parent thread can cause problems. The system property er.extensions.ERXThreadStorage.logUsageOfProblematicInheritedValues defines, if potential problems should be logged. This defaults to true when running in development mode and to false when running a deployed app.


Nested Class Summary
protected static class ERXThreadStorage.ERXThreadStorageCloneableThreadLocal
           
 
Field Summary
static java.lang.String KEYS_ADDED_IN_CURRENT_THREAD_KEY
           
static java.lang.String WAS_CLONED_MARKER
           
 
Constructor Summary
ERXThreadStorage()
           
 
Method Summary
static java.util.Map map()
          Gets the storage map from the current thread.
static java.util.Set<java.lang.String> problematicKeys()
          Retrieve the Set of keys for which a warning is issued when the storageMap was inherited from another Thread and the key is accessed.
static java.util.Set<java.lang.Class<?>> problematicTypes()
          Retrieve the Set of classes for which a warning is issued when the storageMap was inherited from another Thread and the object retrieved from the map is a subclass of one of the classes in the set.
static java.lang.Object removeValueForKey(java.lang.String key)
          Removes the value in the map for a given key.
static void reset()
          Removes all of the keys from the current Map.
static void setProblematicKeys(java.util.Set<java.lang.String> problematicKeys)
          Set the Set of keys for which a warning is issued when the storageMap was inherited from another Thread and the key is accessed.
static void setProblematicTypes(com.webobjects.foundation.NSSet<java.lang.Class<?>> problematicTypes)
          Set the Set of classes for which a warning is issued when the storageMap was inherited from another Thread and the object retrieved from the map is a subclass of one of the classes in the set.
static void takeValueForKey(java.lang.Object object, java.lang.String key)
          Sets a value for a particular key for a particular thread.
static java.lang.Object valueForKey(com.webobjects.eocontrol.EOEditingContext ec, java.lang.String key)
          Gets the object associated with the key in the storage map off of the current thread in the given editing context.
static java.lang.Object valueForKey(java.lang.String key)
          Gets the object associated with the key in the storage map off of the current thread.
static java.lang.Object valueForKeyPath(java.lang.String keyPath)
          Gets the object associated with the keypath in the storage map off of the current thread.
static boolean wasInheritedFromParentThread()
          Checks if the storageMap was inherited from the parent thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEYS_ADDED_IN_CURRENT_THREAD_KEY

public static final java.lang.String KEYS_ADDED_IN_CURRENT_THREAD_KEY
See Also:
Constant Field Values

WAS_CLONED_MARKER

public static final java.lang.String WAS_CLONED_MARKER
See Also:
Constant Field Values
Constructor Detail

ERXThreadStorage

public ERXThreadStorage()
Method Detail

takeValueForKey

public static void takeValueForKey(java.lang.Object object,
                                   java.lang.String key)
Sets a value for a particular key for a particular thread.

Parameters:
object - value
key - key

removeValueForKey

public static java.lang.Object removeValueForKey(java.lang.String key)
Removes the value in the map for a given key.

Parameters:
key - key to be removed from the map.
Returns:
the object corresponding to the key that was removed, null if nothing is found.

valueForKeyPath

public static java.lang.Object valueForKeyPath(java.lang.String keyPath)
Gets the object associated with the keypath in the storage map off of the current thread.

Parameters:
keyPath - key path to be used to retrieve value from map.
Returns:
the value stored in the map for the given key.

valueForKey

public static java.lang.Object valueForKey(java.lang.String key)
Gets the object associated with the key in the storage map off of the current thread.

Parameters:
key - key to be used to retrieve value from map.
Returns:
the value stored in the map for the given key.

valueForKey

public static java.lang.Object valueForKey(com.webobjects.eocontrol.EOEditingContext ec,
                                           java.lang.String key)
Gets the object associated with the key in the storage map off of the current thread in the given editing context. Throws a ClassCastException when the value is not an EO.

Parameters:
ec - editing context to retrieve the value into
key - key to be used to retrieve value from map.
Returns:
the value stored in the map for the given key.

map

public static java.util.Map map()
Gets the storage map from the current thread. At the moment this Map is syncronized for thread safety. This might not be necessary in which case users of this method would need to make sure that they take the appropriate precautions.

Returns:
Map object associated with this particular thread.

reset

public static void reset()
Removes all of the keys from the current Map.


wasInheritedFromParentThread

public static boolean wasInheritedFromParentThread()
Checks if the storageMap was inherited from the parent thread.

Returns:
boolean indicating if the storageMap was inherited from another thread

setProblematicTypes

public static void setProblematicTypes(com.webobjects.foundation.NSSet<java.lang.Class<?>> problematicTypes)
Set the Set of classes for which a warning is issued when the storageMap was inherited from another Thread and the object retrieved from the map is a subclass of one of the classes in the set.

Parameters:
problematicTypes - a set of classes to check

problematicTypes

public static java.util.Set<java.lang.Class<?>> problematicTypes()
Retrieve the Set of classes for which a warning is issued when the storageMap was inherited from another Thread and the object retrieved from the map is a subclass of one of the classes in the set. Defaults to a Set containing WOSession.class, WOContext.class, EOEnterpriseObject.class and EOEditingContext.class

Returns:
the set of classes to check

setProblematicKeys

public static void setProblematicKeys(java.util.Set<java.lang.String> problematicKeys)
Set the Set of keys for which a warning is issued when the storageMap was inherited from another Thread and the key is accessed.

Parameters:
problematicKeys - a set of keys to check

problematicKeys

public static java.util.Set<java.lang.String> problematicKeys()
Retrieve the Set of keys for which a warning is issued when the storageMap was inherited from another Thread and the key is accessed. Defaults to a set containing ERXWOContext.CONTEXT_DICTIONARY_KEY

Returns:
the set of keys to check

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.