Class ContextMap
java.lang.Object
org.apache.log.ContextMap
- All Implemented Interfaces:
Serializable
The ContextMap contains non-hierarchical context information
relevant to a particular LogEvent. It may include information
such as;
- user ->fred
- hostname ->helm.realityforge.org
- ipaddress ->1.2.3.4
- interface ->127.0.0.1
- caller ->com.biz.MyCaller.method(MyCaller.java:18)
- source ->1.6.3.2:33
- Author:
- Avalon Development Team, Peter Donald
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ThreadLocalThread local for holding instance of map associated with current threadprivate HashtableContainer to hold map of elementsprivate final ContextMapprivate booleanFlag indicating whether this map should be readonly -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.ContextMap(ContextMap parent) Constructor that sets parent contextMap. -
Method Summary
Modifier and TypeMethodDescriptionstatic final voidbind(ContextMap context) Bind a particular ContextMap to current thread.private voidUtility method to verify that Context is read-only.voidclear()Empty the context map.Get an entry from the context.Get an entry from the context.static final ContextMapGet the Current ContextMap.static final ContextMapgetCurrentContext(boolean autocreate) Get the Current ContextMap.intgetSize()Get the number of contexts in map.booleanDetermine if context is read-only.voidMake the context read-only.private ObjectHelper method that sets context to read-only after de-serialization.voidSet a value in context
-
Field Details
-
c_localContext
Thread local for holding instance of map associated with current thread -
m_parent
-
m_map
Container to hold map of elements -
m_readOnly
private transient boolean m_readOnlyFlag indicating whether this map should be readonly
-
-
Constructor Details
-
ContextMap
public ContextMap()Default constructor. -
ContextMap
Constructor that sets parent contextMap.- Parameters:
parent- the parent ContextMap
-
-
Method Details
-
getCurrentContext
Get the Current ContextMap. This method returns a ContextMap associated with current thread. If the thread doesn't have a ContextMap associated with it then a new ContextMap is created.- Returns:
- the current ContextMap
-
getCurrentContext
Get the Current ContextMap. This method returns a ContextMap associated with current thread. If the thread doesn't have a ContextMap associated with it and autocreate is true then a new ContextMap is created.- Parameters:
autocreate- true if a ContextMap is to be created if it doesn't exist- Returns:
- the current ContextMap
-
bind
Bind a particular ContextMap to current thread.- Parameters:
context- the context map (may be null)
-
makeReadOnly
public void makeReadOnly()Make the context read-only. This makes it safe to allow untrusted code reference to ContextMap. -
isReadOnly
public boolean isReadOnly()Determine if context is read-only.- Returns:
- true if Context is read only, false otherwise
-
clear
public void clear()Empty the context map. -
get
-
get
-
set
-
getSize
public int getSize()Get the number of contexts in map.- Returns:
- the number of contexts in map
-
readResolve
Helper method that sets context to read-only after de-serialization.- Returns:
- the corrected object version
-
checkReadable
private void checkReadable()Utility method to verify that Context is read-only.
-