Class ContextMap
-
- All Implemented Interfaces:
-
java.io.Serializable
@Deprecated() public final class ContextMap implements 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
Peter Donald
-
-
Constructor Summary
Constructors Constructor Description ContextMap()Default constructor. ContextMap(ContextMap parent)Constructor that sets parent contextMap.
-
Method Summary
Modifier and Type Method Description final static ContextMapgetCurrentContext()Get the Current ContextMap. final static ContextMapgetCurrentContext(boolean autocreate)Get the Current ContextMap. final static voidbind(ContextMap context)Bind a particular ContextMap to current thread. voidmakeReadOnly()Make the context read-only. booleanisReadOnly()Determine if context is read-only. voidclear()Empty the context map. Objectget(String key, Object defaultObject)Get an entry from the context. Objectget(String key)Get an entry from the context. voidset(String key, Object value)Set a value in context intgetSize()Get the number of contexts in map. -
-
Constructor Detail
-
ContextMap
ContextMap()
Default constructor.
-
ContextMap
ContextMap(ContextMap parent)
Constructor that sets parent contextMap.- Parameters:
parent- the parent ContextMap
-
-
Method Detail
-
getCurrentContext
final static 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
final static 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
final static void bind(ContextMap context)
Bind a particular ContextMap to current thread.
- Parameters:
context- the context map (may be null)
-
makeReadOnly
void makeReadOnly()
Make the context read-only. This makes it safe to allow untrusted code reference to ContextMap.
-
isReadOnly
boolean isReadOnly()
Determine if context is read-only.
- Returns:
true if Context is read only, false otherwise
-
clear
void clear()
Empty the context map.
-
get
Object get(String key, 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
Object get(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
void set(String key, Object value)
Set a value in context
- Parameters:
key- the keyvalue- the value (may be null)
-
getSize
int getSize()
Get the number of contexts in map.
- Returns:
the number of contexts in map
-
-
-
-