Package org.apache.log
Class ContextMap
- java.lang.Object
-
- org.apache.log.ContextMap
-
- All Implemented Interfaces:
java.io.Serializable
public final class ContextMap extends java.lang.Object implements java.io.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ThreadLocal
c_localContext
private java.util.Hashtable
m_map
private ContextMap
m_parent
private boolean
m_readOnly
-
Constructor Summary
Constructors Constructor Description ContextMap()
Default constructor.ContextMap(ContextMap parent)
Constructor that sets parent contextMap.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
bind(ContextMap context)
Bind a particular ContextMap to current thread.private void
checkReadable()
Utility method to verify that Context is read-only.void
clear()
Empty the context map.java.lang.Object
get(java.lang.String key)
Get an entry from the context.java.lang.Object
get(java.lang.String key, java.lang.Object defaultObject)
Get an entry from the context.static ContextMap
getCurrentContext()
Get the Current ContextMap.static ContextMap
getCurrentContext(boolean autocreate)
Get the Current ContextMap.int
getSize()
Get the number of contexts in map.boolean
isReadOnly()
Determine if context is read-only.void
makeReadOnly()
Make the context read-only.private java.lang.Object
readResolve()
Helper method that sets context to read-only after de-serialization.void
set(java.lang.String key, java.lang.Object value)
Set a value in context
-
-
-
Field Detail
-
c_localContext
private static final java.lang.ThreadLocal c_localContext
-
m_parent
private final ContextMap m_parent
-
m_map
private java.util.Hashtable m_map
-
m_readOnly
private transient boolean m_readOnly
-
-
Constructor Detail
-
ContextMap
public ContextMap()
Default constructor.
-
ContextMap
public ContextMap(ContextMap parent)
Constructor that sets parent contextMap.- Parameters:
parent
- the parent ContextMap
-
-
Method Detail
-
getCurrentContext
public static final 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 then a new ContextMap is created.- Returns:
- the current ContextMap
-
getCurrentContext
public static final ContextMap getCurrentContext(boolean autocreate)
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
public static final void bind(ContextMap context)
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
public java.lang.Object get(java.lang.String key, java.lang.Object defaultObject)
Get an entry from the context.- Parameters:
key
- the key to mapdefaultObject
- a default object to return if key does not exist- Returns:
- the object in context
-
get
public java.lang.Object get(java.lang.String key)
Get an entry from the context.- Parameters:
key
- the key to map- Returns:
- the object in context or null if none with specified key
-
set
public void set(java.lang.String key, java.lang.Object value)
Set a value in context- Parameters:
key
- the keyvalue
- the value (may be null)
-
getSize
public int getSize()
Get the number of contexts in map.- Returns:
- the number of contexts in map
-
readResolve
private java.lang.Object 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.
-
-