Top Description Fields Constructors Methods
org.apache.log

public final Class ContextMap

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.util.Hashtable

The ContextMap contains non-hierarchical context information relevant to a particular LogEvent. It may include information such as; The context is bound to a thread (and inherited by sub-threads) but it can also be added to by LogTargets. Use removeCurrentContext to unbind context from the thread.
Authors
Avalon Development Team, Peter Donald

Field Summary

Modifier and TypeField and Description
private static final ThreadLocal<T>
private Hashtable<K, V>
private final ContextMap
private transient boolean

Constructor Summary

AccessConstructor and Description
public
ContextMap()

Default constructor.

public
ContextMap(final ContextMap
the parent ContextMap
parent
)

Constructor that sets parent contextMap.

Method Summary

Modifier and TypeMethod and Description
public static void
bind(final ContextMap
the context map (may be null)
context
)

Bind a particular ContextMap to current thread.

private void
checkReadable()

Utility method to verify that Context is read-only.

public void
clear()

Empty the context map.

public Object

Returns:

the object in context
get
(final String
the key to map
key
,
final Object
a default object to return if key does not exist
defaultObject
)

Get an entry from the context.

public Object

Returns:

the object in context or null if none with specified key
get
(final String
the key to map
key
)

Get an entry from the context.

public static ContextMap

Returns:

the current ContextMap
getCurrentContext
()

Get current ContextMap.

public static ContextMap

Returns:

the current ContextMap
getCurrentContext
(final boolean
true if a ContextMap is to be created if it doesn't exist
autocreate
)

Get current ContextMap.

public int

Returns:

the number of contexts in map
getSize
()

Get the number of contexts in map.

public boolean

Returns:

true if Context is read only, false otherwise
isReadOnly
()

Determine if context is read-only.

public void
makeReadOnly()

Make the context read-only.

private Object

Returns:

the corrected object version
readResolve
()

Helper method that sets context to read-only after de-serialization.

public static void
removeCurrentContext()

Remove current ContextMap.

public void
set(final String
the key
key
,
final Object
the value (may be null)
value
)

Set a value in context

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

c_localContextback to summary
private static final ThreadLocal<T> c_localContext
m_mapback to summary
private Hashtable<K, V> m_map
m_parentback to summary
private final ContextMap m_parent
m_readOnlyback to summary
private transient boolean m_readOnly

Constructor Detail

ContextMapback to summary
public ContextMap()

Default constructor.

ContextMapback to summary
public ContextMap(final ContextMap parent)

Constructor that sets parent contextMap.

Parameters
parent:ContextMap

the parent ContextMap

Method Detail

bindback to summary
public static void bind(final ContextMap context)

Bind a particular ContextMap to current thread.

Parameters
context:ContextMap

the context map (may be null)

checkReadableback to summary
private void checkReadable()

Utility method to verify that Context is read-only.

clearback to summary
public void clear()

Empty the context map.

getback to summary
public Object get(final String key, final Object defaultObject)

Get an entry from the context.

Parameters
key:String

the key to map

defaultObject:Object

a default object to return if key does not exist

Returns:Object

the object in context

getback to summary
public Object get(final String key)

Get an entry from the context.

Parameters
key:String

the key to map

Returns:Object

the object in context or null if none with specified key

getCurrentContextback to summary
public static ContextMap getCurrentContext()

Get 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:ContextMap

the current ContextMap

getCurrentContextback to summary
public static ContextMap getCurrentContext(final boolean autocreate)

Get 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:boolean

true if a ContextMap is to be created if it doesn't exist

Returns:ContextMap

the current ContextMap

getSizeback to summary
public int getSize()

Get the number of contexts in map.

Returns:int

the number of contexts in map

isReadOnlyback to summary
public boolean isReadOnly()

Determine if context is read-only.

Returns:boolean

true if Context is read only, false otherwise

makeReadOnlyback to summary
public void makeReadOnly()

Make the context read-only. This makes it safe to allow untrusted code reference to ContextMap.

readResolveback to summary
private Object readResolve()

Helper method that sets context to read-only after de-serialization.

Returns:Object

the corrected object version

removeCurrentContextback to summary
public static void removeCurrentContext()

Remove current ContextMap. This method removes a ContextMap associated with current thread, if there is any.

setback to summary
public void set(final String key, final Object value)

Set a value in context

Parameters
key:String

the key

value:Object

the value (may be null)