Top Description Inners Fields Constructors Methods
org.apache.logging.log4j

public final Class ThreadContext

extends Object
Class Inheritance
Imports
java.io.Serializable, java.util.AbstractCollection, .Collection, .Collections, .Iterator, .List, .Map, .NoSuchElementException, org.apache.logging.log4j.message.ParameterizedMessage, org.apache.logging.log4j.spi.CleanableThreadContextMap, .DefaultThreadContextMap, .DefaultThreadContextStack, .NoOpThreadContextMap, .ReadOnlyThreadContextMap, .ThreadContextMap, .ThreadContextMap2, .ThreadContextMapFactory, .ThreadContextStack, org.apache.logging.log4j.util.PropertiesUtil

The ThreadContext allows applications to store information either in a Map or a Stack.

The MDC is managed on a per thread basis. To enable automatic inheritance of copies of the MDC to newly created threads, enable the isThreadContextMapInheritable Log4j system property.

See Also
Thread Context Manual

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ThreadContext.ContextStack

The ThreadContext Stack interface.

private static class
ThreadContext.EmptyIterator<
the type of the empty iterator
E
>

An empty iterator.

private static class
ThreadContext.EmptyThreadContextStack

An empty read-only ThreadContextStack.

Field Summary

Modifier and TypeField and Description
private static ThreadContextMap
private static ThreadContextStack
private static final String
private static final String
private static final String
public static final Map<String, String>
EMPTY_MAP

Empty, immutable Map.

public static final ThreadContextStack
EMPTY_STACK

Empty, immutable ContextStack.

private static ReadOnlyThreadContextMap
private static boolean

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
clearAll()

Clears the context map and stack.

public static void
clearMap()

Clears the context map.

public static void
clearStack()

Clears the stack for this thread.

public static ThreadContext.ContextStack

Returns:

A copy of this thread's stack.
cloneStack
()

Returns a copy of this thread's stack.

public static boolean

Returns:

True if the key is in the context, false otherwise.
containsKey
(final String
The key to locate.
key
)

Determines if the key is in the context.

public static String

Returns:

The value associated with the key or null.
get
(final String
The key to locate.
key
)

Gets the context value identified by the key parameter.

public static Map<String, String>

Returns:

a mutable copy of the context.
getContext
()

Returns a mutable copy of current thread's context Map.

public static int

Returns:

the number of items in the stack.
getDepth
()

Gets the current nesting depth of this thread's stack.

public static Map<String, String>

Returns:

An immutable view of the ThreadContext Map.
getImmutableContext
()

Returns an immutable view of the current thread's context Map.

public static ThreadContext.ContextStack

Returns:

an immutable copy of the ThreadContext stack.
getImmutableStack
()

Gets an immutable copy of this current thread's context stack.

public static ReadOnlyThreadContextMap

Returns:

the internal data structure used to store thread context key-value pairs or null
getThreadContextMap
()

Returns a read-only view of the internal data structure used to store thread context key-value pairs, or null if the internal data structure does not implement the ReadOnlyThreadContextMap interface.

public static void
init()

Consider private, used for testing.

public static boolean

Returns:

true if the Map is empty, false otherwise.
isEmpty
()

Returns true if the Map is empty.

public static String

Returns:

String The innermost diagnostic context.
peek
()

Looks at the last diagnostic context at the top of this NDC without removing it.

public static String

Returns:

String The innermost diagnostic context.
pop
()

Returns the value of the last item placed on the stack.

public static void
push(final String
The new diagnostic context information.
message
)

Pushes new diagnostic context information for the current thread.

public static void
push(final String
The new diagnostic context information.
message
,
final Object...
Parameters for the message.
args
)

Pushes new diagnostic context information for the current thread.

public static void
put(final String
The key name.
key
,
final String
The key value.
value
)

Puts a context value (the value parameter) as identified with the key parameter into the current thread's context map.

public static void
putAll(final Map<String, String>
The map.
m
)

Puts all given context map entries into the current thread's context map.

public static void
putIfNull(final String
The key name.
key
,
final String
The key value.
value
)

Puts a context value (the value parameter) as identified with the key parameter into the current thread's context map if the key does not exist.

public static void
remove(final String
The key to remove.
key
)

Removes the context value identified by the key parameter.

public static void
removeAll(final Iterable<String>
The keys to remove.
keys
)

Removes the context values identified by the keys parameter.

public static void
removeStack()

Removes the diagnostic context for this thread.

public static void
setStack(final Collection<String>
The stack to use.
stack
)

Sets this thread's stack.

public static void
trim(final int
The number of elements to keep.
depth
)

Trims elements from this diagnostic context.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

contextMapback to summary
private static ThreadContextMap contextMap
contextStackback to summary
private static ThreadContextStack contextStack
DISABLE_ALLback to summary
private static final String DISABLE_ALL
DISABLE_MAPback to summary
private static final String DISABLE_MAP
DISABLE_STACKback to summary
private static final String DISABLE_STACK
EMPTY_MAPback to summary
public static final Map<String, String> EMPTY_MAP

Empty, immutable Map.

Annotations
@SuppressWarnings:PublicStaticCollectionField
EMPTY_STACKback to summary
public static final ThreadContextStack EMPTY_STACK

Empty, immutable ContextStack.

Annotations
@SuppressWarnings:PublicStaticCollectionField
readOnlyContextMapback to summary
private static ReadOnlyThreadContextMap readOnlyContextMap
useStackback to summary
private static boolean useStack

Constructor Detail

ThreadContextback to summary
private ThreadContext()

Method Detail

clearAllback to summary
public static void clearAll()

Clears the context map and stack.

clearMapback to summary
public static void clearMap()

Clears the context map.

clearStackback to summary
public static void clearStack()

Clears the stack for this thread.

cloneStackback to summary
public static ThreadContext.ContextStack cloneStack()

Returns a copy of this thread's stack.

Returns:ThreadContext.ContextStack

A copy of this thread's stack.

containsKeyback to summary
public static boolean containsKey(final String key)

Determines if the key is in the context.

Parameters
key:String

The key to locate.

Returns:boolean

True if the key is in the context, false otherwise.

getback to summary
public static String get(final String key)

Gets the context value identified by the key parameter.

This method has no side effects.

Parameters
key:String

The key to locate.

Returns:String

The value associated with the key or null.

getContextback to summary
public static Map<String, String> getContext()

Returns a mutable copy of current thread's context Map.

Returns:Map<String, String>

a mutable copy of the context.

getDepthback to summary
public static int getDepth()

Gets the current nesting depth of this thread's stack.

Returns:int

the number of items in the stack.

See Also
trim
getImmutableContextback to summary
public static Map<String, String> getImmutableContext()

Returns an immutable view of the current thread's context Map.

Returns:Map<String, String>

An immutable view of the ThreadContext Map.

getImmutableStackback to summary
public static ThreadContext.ContextStack getImmutableStack()

Gets an immutable copy of this current thread's context stack.

Returns:ThreadContext.ContextStack

an immutable copy of the ThreadContext stack.

getThreadContextMapback to summary
public static ReadOnlyThreadContextMap getThreadContextMap()

Returns a read-only view of the internal data structure used to store thread context key-value pairs, or null if the internal data structure does not implement the ReadOnlyThreadContextMap interface.

The DefaultThreadContextMap implementation does not implement ReadOnlyThreadContextMap, so by default this method returns null.

Returns:ReadOnlyThreadContextMap

the internal data structure used to store thread context key-value pairs or null

Since
2.8
See Also
ThreadContextMapFactory, DefaultThreadContextMap, org.apache.logging.log4j.spi.CopyOnWriteSortedArrayThreadContextMap, org.apache.logging.log4j.spi.GarbageFreeSortedArrayThreadContextMap
initback to summary
public static void init()

Consider private, used for testing.

isEmptyback to summary
public static boolean isEmpty()

Returns true if the Map is empty.

Returns:boolean

true if the Map is empty, false otherwise.

peekback to summary
public static String peek()

Looks at the last diagnostic context at the top of this NDC without removing it.

The returned value is the value that was pushed last. If no context is available, then the empty string "" is returned.

Returns:String

String The innermost diagnostic context.

popback to summary
public static String pop()

Returns the value of the last item placed on the stack.

The returned value is the value that was pushed last. If no context is available, then the empty string "" is returned.

Returns:String

String The innermost diagnostic context.

pushback to summary
public static void push(final String message)

Pushes new diagnostic context information for the current thread.

The contents of the message parameter is determined solely by the client.

Parameters
message:String

The new diagnostic context information.

pushback to summary
public static void push(final String message, final Object... args)

Pushes new diagnostic context information for the current thread.

The contents of the message and args parameters are determined solely by the client. The message will be treated as a format String and tokens will be replaced with the String value of the arguments in accordance with ParameterizedMessage.

Parameters
message:String

The new diagnostic context information.

args:Object[]

Parameters for the message.

putback to summary
public static void put(final String key, final String value)

Puts a context value (the value parameter) as identified with the key parameter into the current thread's context map.

If the current thread does not have a context map it is created as a side effect.

Parameters
key:String

The key name.

value:String

The key value.

putAllback to summary
public static void putAll(final Map<String, String> m)

Puts all given context map entries into the current thread's context map.

If the current thread does not have a context map it is created as a side effect.

Parameters
m:Map<String, String>

The map.

Since
2.7
putIfNullback to summary
public static void putIfNull(final String key, final String value)

Puts a context value (the value parameter) as identified with the key parameter into the current thread's context map if the key does not exist.

If the current thread does not have a context map it is created as a side effect.

Parameters
key:String

The key name.

value:String

The key value.

Since
2.13.0
removeback to summary
public static void remove(final String key)

Removes the context value identified by the key parameter.

Parameters
key:String

The key to remove.

removeAllback to summary
public static void removeAll(final Iterable<String> keys)

Removes the context values identified by the keys parameter.

Parameters
keys:Iterable<String>

The keys to remove.

Since
2.8
removeStackback to summary
public static void removeStack()

Removes the diagnostic context for this thread.

Each thread that created a diagnostic context by calling push should call this method before exiting. Otherwise, the memory used by the thread cannot be reclaimed by the VM.

As this is such an important problem in heavy duty systems and because it is difficult to always guarantee that the remove method is called before exiting a thread, this method has been augmented to lazily remove references to dead threads. In practice, this means that you can be a little sloppy and occasionally forget to call remove before exiting a thread. However, you must call remove sometime. If you never call it, then your application is sure to run out of memory.

setStackback to summary
public static void setStack(final Collection<String> stack)

Sets this thread's stack.

Parameters
stack:Collection<String>

The stack to use.

trimback to summary
public static void trim(final int depth)

Trims elements from this diagnostic context. If the current depth is smaller or equal to maxDepth, then no action is taken. If the current depth is larger than newDepth then all elements at maxDepth or higher are discarded.

This method is a convenient alternative to multiple pop calls. Moreover, it is often the case that at the end of complex call sequences, the depth of the ThreadContext is unpredictable. The trim method circumvents this problem.

For example, the combination

void foo() {
    final int depth = ThreadContext.getDepth();

    // ... complex sequence of calls

    ThreadContext.trim(depth);
}

ensures that between the entry and exit of foo the depth of the diagnostic stack is conserved.

Parameters
depth:int

The number of elements to keep.

See Also
getDepth
org.apache.logging.log4j back to summary

public Interface ThreadContext.ContextStack

extends Serializable, Collection<String>
Known Direct Subinterfaces
org.apache.logging.log4j.spi.ThreadContextStack

The ThreadContext Stack interface.

Method Summary

Modifier and TypeMethod and Description
public List<String>

Returns:

all the elements in the stack in a List.
asList
()

Returns all the elements in the stack in a List.

public ThreadContext.ContextStack

Returns:

a copy of the ContextStack.
copy
()

Returns a copy of the ContextStack.

public int

Returns:

the number of elements in the stack.
getDepth
()

Returns the number of elements in the stack.

public ThreadContext.ContextStack

Returns:

a ContextStack with the same contents as this ContextStack or null.
getImmutableStackOrNull
()

Returns a ContextStack with the same contents as this ContextStack or null.

public String

Returns:

the element at the top of the stack or null if the stack is empty.
peek
()

Returns the element at the top of the stack without removing it or null if the stack is empty.

public String

Returns:

The element at the top of the stack.
pop
()

Returns the element at the top of the stack.

public void
push(String
The element to add.
message
)

Pushes an element onto the stack.

public void
trim(int
The maximum number of items in the stack to keep.
depth
)

Trims elements from the end of the stack.

Inherited from java.util.Collection:
addaddAllclearcontainscontainsAllequalshashCodeisEmptyiteratorparallelStreamremoveremoveAllremoveIfretainAllsizespliteratorstreamtoArraytoArraytoArray

Method Detail

asListback to summary
public List<String> asList()

Returns all the elements in the stack in a List.

Returns:List<String>

all the elements in the stack in a List.

copyback to summary
public ThreadContext.ContextStack copy()

Returns a copy of the ContextStack.

Returns:ThreadContext.ContextStack

a copy of the ContextStack.

getDepthback to summary
public int getDepth()

Returns the number of elements in the stack.

Returns:int

the number of elements in the stack.

getImmutableStackOrNullback to summary
public ThreadContext.ContextStack getImmutableStackOrNull()

Returns a ContextStack with the same contents as this ContextStack or null. Attempts to modify the returned stack may or may not throw an exception, but will not affect the contents of this ContextStack.

Returns:ThreadContext.ContextStack

a ContextStack with the same contents as this ContextStack or null.

peekback to summary
public String peek()

Returns the element at the top of the stack without removing it or null if the stack is empty.

Returns:String

the element at the top of the stack or null if the stack is empty.

popback to summary
public String pop()

Returns the element at the top of the stack.

Returns:String

The element at the top of the stack.

Exceptions
NoSuchElementException:
if the stack is empty.
pushback to summary
public void push(String message)

Pushes an element onto the stack.

Parameters
message:String

The element to add.

trimback to summary
public void trim(int depth)

Trims elements from the end of the stack.

Parameters
depth:int

The maximum number of items in the stack to keep.

org.apache.logging.log4j back to summary

private Class ThreadContext.EmptyIterator<E>

extends Object
implements Iterator<E>
Class Inheritance
All Implemented Interfaces
java.util.Iterator
Type Parameters
<E>
the type of the empty iterator

An empty iterator. Since Java 1.7 added the Collections.emptyIterator() method, we have to make do.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
hasNext()

Implements java.util.Iterator.hasNext.

Returns true if the iteration has more elements.

public E
next()

Implements java.util.Iterator.next.

Returns the next element in the iteration.

public void
remove()

Overrides default java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EmptyIteratorback to summary
private EmptyIterator()

Method Detail

hasNextback to summary
public boolean hasNext()

Implements java.util.Iterator.hasNext.

Doc from java.util.Iterator.hasNext.

Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:boolean

true if the iteration has more elements

Annotations
@Override
nextback to summary
public E next()

Implements java.util.Iterator.next.

Doc from java.util.Iterator.next.

Returns the next element in the iteration.

Returns:E

the next element in the iteration

Annotations
@Override
removeback to summary
public void remove()

Overrides default java.util.Iterator.remove.

Doc from java.util.Iterator.remove.

Removes from the underlying collection the last element returned by this iterator (optional operation). This method can be called only once per call to next.

The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method, unless an overriding class has specified a concurrent modification policy.

The behavior of an iterator is unspecified if this method is called after a call to the forEachRemaining method.

Annotations
@Override
org.apache.logging.log4j back to summary

private Class ThreadContext.EmptyThreadContextStack

extends AbstractCollection<String>
implements ThreadContextStack
Class Inheritance
All Implemented Interfaces
org.apache.logging.log4j.spi.ThreadContextStack, org.apache.logging.log4j.ThreadContext.ContextStack, java.util.Collection, java.lang.Iterable, java.io.Serializable

An empty read-only ThreadContextStack.

Field Summary

Modifier and TypeField and Description
private static final Iterator<String>
private static final long

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public boolean
add(final String
element whose presence in this collection is to be ensured
e
)

Overrides java.util.AbstractCollection.add.

Implements java.util.Collection.add.

Ensures that this collection contains the specified element (optional operation).

public boolean
addAll(final Collection<? extends String>
collection containing elements to be added to this collection
c
)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation).

public List<String>
asList()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.asList.

Returns all the elements in the stack in a List.

public boolean
containsAll(final Collection<?>
collection to be checked for containment in this collection
c
)

Overrides java.util.AbstractCollection.containsAll.

Implements java.util.Collection.containsAll.

Returns true if this collection contains all of the elements in the specified collection.

public ThreadContext.ContextStack
copy()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.copy.

Returns a copy of the ContextStack.

public boolean
equals(final Object
object to be compared for equality with this collection
o
)

Overrides java.lang.Object.equals.

Implements java.util.Collection.equals.

Compares the specified object with this collection for equality.

public int
getDepth()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.getDepth.

Returns the number of elements in the stack.

public ThreadContext.ContextStack
getImmutableStackOrNull()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.getImmutableStackOrNull.

Returns a ContextStack with the same contents as this ContextStack or null.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Collection.hashCode.

Returns the hash code value for this collection.

public Iterator<String>
iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Collection.iterator.

Returns an iterator over the elements in this collection.

public String
peek()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.peek.

Returns the element at the top of the stack without removing it or null if the stack is empty.

public String
pop()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.pop.

Returns the element at the top of the stack.

public void
push(final String
The element to add.
message
)

Implements org.apache.logging.log4j.ThreadContext.ContextStack.push.

Pushes an element onto the stack.

public boolean
removeAll(final Collection<?>
collection containing elements to be removed from this collection
c
)

Overrides java.util.AbstractCollection.removeAll.

Implements java.util.Collection.removeAll.

Removes all of this collection's elements that are also contained in the specified collection (optional operation).

public boolean
retainAll(final Collection<?>
collection containing elements to be retained in this collection
c
)

Overrides java.util.AbstractCollection.retainAll.

Implements java.util.Collection.retainAll.

Retains only the elements in this collection that are contained in the specified collection (optional operation).

public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size.

Returns the number of elements in this collection.

public <T> T[]
toArray(final T[]
the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
a
)

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Collection.toArray.

Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array.

public void
trim(final int
The maximum number of items in the stack to keep.
depth
)

Implements org.apache.logging.log4j.ThreadContext.ContextStack.trim.

Trims elements from the end of the stack.

Inherited from java.util.AbstractCollection:
clearcontainsisEmptyremovetoArraytoString

Field Detail

EMPTY_ITERATORback to summary
private static final Iterator<String> EMPTY_ITERATOR
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

EmptyThreadContextStackback to summary
private EmptyThreadContextStack()

Method Detail

addback to summary
public boolean add(final String e)

Overrides java.util.AbstractCollection.add.

Implements java.util.Collection.add.

Doc from java.util.Collection.add.

Ensures that this collection contains the specified element (optional operation). Returns true if this collection changed as a result of the call. (Returns false if this collection does not permit duplicates and already contains the specified element.)

Collections that support this operation may place limitations on what elements may be added to this collection. In particular, some collections will refuse to add null elements, and others will impose restrictions on the type of elements that may be added. Collection classes should clearly specify in their documentation any restrictions on what elements may be added.

If a collection refuses to add a particular element for any reason other than that it already contains the element, it must throw an exception (rather than returning false). This preserves the invariant that a collection always contains the specified element after this call returns.

Parameters
e:String

element whose presence in this collection is to be ensured

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
addAllback to summary
public boolean addAll(final Collection<? extends String> c)

Overrides java.util.AbstractCollection.addAll.

Implements java.util.Collection.addAll.

Doc from java.util.Collection.addAll.

Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.) If the specified collection has a defined encounter order, processing of its elements generally occurs in that order.

Parameters
c:Collection<? extends String>

collection containing elements to be added to this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
asListback to summary
public List<String> asList()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.asList.

Doc from org.apache.logging.log4j.ThreadContext.ContextStack.asList.

Returns all the elements in the stack in a List.

Returns:List<String>

all the elements in the stack in a List.

Annotations
@Override
containsAllback to summary
public boolean containsAll(final Collection<?> c)

Overrides java.util.AbstractCollection.containsAll.

Implements java.util.Collection.containsAll.

Doc from java.util.Collection.containsAll.

Returns true if this collection contains all of the elements in the specified collection.

Parameters
c:Collection<?>

collection to be checked for containment in this collection

Returns:boolean

true if this collection contains all of the elements in the specified collection

Annotations
@Override
copyback to summary
public ThreadContext.ContextStack copy()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.copy.

Doc from org.apache.logging.log4j.ThreadContext.ContextStack.copy.

Returns a copy of the ContextStack.

Returns:ThreadContext.ContextStack

a copy of the ContextStack.

Annotations
@Override
equalsback to summary
public boolean equals(final Object o)

Overrides java.lang.Object.equals.

Implements java.util.Collection.equals.

Doc from java.util.Collection.equals.

Compares the specified object with this collection for equality.

While the Collection interface adds no stipulations to the general contract for the Object.equals, programmers who implement the Collection interface "directly" (in other words, create a class that is a Collection but is not a Set or a List) must exercise care if they choose to override the Object.equals. It is not necessary to do so, and the simplest course of action is to rely on Object's implementation, but the implementor may wish to implement a "value comparison" in place of the default "reference comparison." (The List and Set interfaces mandate such value comparisons.)

The general contract for the Object.equals method states that equals must be symmetric (in other words, a.equals(b) if and only if b.equals(a)). The contracts for List.equals and Set.equals state that lists are only equal to other lists, and sets to other sets. Thus, a custom equals method for a collection class that implements neither the List nor Set interface must return false when this collection is compared to any list or set. (By the same logic, it is not possible to write a class that correctly implements both the Set and List interfaces.)

Parameters
o:Object

object to be compared for equality with this collection

Returns:boolean

true if the specified object is equal to this collection

Annotations
@Override
getDepthback to summary
public int getDepth()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.getDepth.

Doc from org.apache.logging.log4j.ThreadContext.ContextStack.getDepth.

Returns the number of elements in the stack.

Returns:int

the number of elements in the stack.

Annotations
@Override
getImmutableStackOrNullback to summary
public ThreadContext.ContextStack getImmutableStackOrNull()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.getImmutableStackOrNull.

Doc from org.apache.logging.log4j.ThreadContext.ContextStack.getImmutableStackOrNull.

Returns a ContextStack with the same contents as this ContextStack or null. Attempts to modify the returned stack may or may not throw an exception, but will not affect the contents of this ContextStack.

Returns:ThreadContext.ContextStack

a ContextStack with the same contents as this ContextStack or null.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.util.Collection.hashCode.

Doc from java.util.Collection.hashCode.

Returns the hash code value for this collection. While the Collection interface adds no stipulations to the general contract for the Object.hashCode method, programmers should take note that any class that overrides the Object.equals method must also override the Object.hashCode method in order to satisfy the general contract for the Object.hashCode method. In particular, c1.equals(c2) implies that c1.hashCode()==c2.hashCode().

Returns:int

the hash code value for this collection

Annotations
@Override
iteratorback to summary
public Iterator<String> iterator()

Implements abstract java.util.AbstractCollection.iterator.

Implements java.util.Collection.iterator.

Doc from java.util.Collection.iterator.

Returns an iterator over the elements in this collection. There are no guarantees concerning the order in which the elements are returned (unless this collection is an instance of some class that provides a guarantee).

Returns:Iterator<String>

an Iterator over the elements in this collection

Annotations
@Override
peekback to summary
public String peek()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.peek.

Doc from org.apache.logging.log4j.ThreadContext.ContextStack.peek.

Returns the element at the top of the stack without removing it or null if the stack is empty.

Returns:String

the element at the top of the stack or null if the stack is empty.

Annotations
@Override
popback to summary
public String pop()

Implements org.apache.logging.log4j.ThreadContext.ContextStack.pop.

Doc from org.apache.logging.log4j.ThreadContext.ContextStack.pop.

Returns the element at the top of the stack.

Returns:String

The element at the top of the stack.

Annotations
@Override
pushback to summary
public void push(final String message)

Implements org.apache.logging.log4j.ThreadContext.ContextStack.push.

Doc from org.apache.logging.log4j.ThreadContext.ContextStack.push.

Pushes an element onto the stack.

Parameters
message:String

The element to add.

Annotations
@Override
removeAllback to summary
public boolean removeAll(final Collection<?> c)

Overrides java.util.AbstractCollection.removeAll.

Implements java.util.Collection.removeAll.

Doc from java.util.Collection.removeAll.

Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection.

Parameters
c:Collection<?>

collection containing elements to be removed from this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
retainAllback to summary
public boolean retainAll(final Collection<?> c)

Overrides java.util.AbstractCollection.retainAll.

Implements java.util.Collection.retainAll.

Doc from java.util.Collection.retainAll.

Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection.

Parameters
c:Collection<?>

collection containing elements to be retained in this collection

Returns:boolean

true if this collection changed as a result of the call

Annotations
@Override
sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size.

Doc from java.util.Collection.size.

Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this collection

Annotations
@Override
toArrayback to summary
public <T> T[] toArray(final T[] a)

Overrides java.util.AbstractCollection.toArray.

Implements java.util.Collection.toArray.

Doc from java.util.Collection.toArray.

Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.

If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to null. (This is useful in determining the length of this collection only if the caller knows that this collection does not contain any null elements.)

If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.

Parameters
<T>
the component type of the array to contain the collection
a:T[]

the array into which the elements of this collection are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.

Returns:T[]

an array containing all of the elements in this collection

Annotations
@Override
trimback to summary
public void trim(final int depth)

Implements org.apache.logging.log4j.ThreadContext.ContextStack.trim.

Doc from org.apache.logging.log4j.ThreadContext.ContextStack.trim.

Trims elements from the end of the stack.

Parameters
depth:int

The maximum number of items in the stack to keep.

Annotations
@Override