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

public Class ReusableParameterizedMessage

extends Object
implements ReusableMessage, ParameterVisitable, Clearable
Class Inheritance
All Implemented Interfaces
org.apache.logging.log4j.message.Clearable, org.apache.logging.log4j.message.ParameterVisitable, org.apache.logging.log4j.message.ReusableMessage, org.apache.logging.log4j.util.StringBuilderFormattable, org.apache.logging.log4j.message.Message, java.io.Serializable
Annotations
@PerformanceSensitive:allocation
Imports
java.util.Arrays, org.apache.logging.log4j.message.ParameterFormatter.MessagePatternAnalysis, org.apache.logging.log4j.util.Constants, .PerformanceSensitive, .StringBuilders

Reusable parameterized message. This message is mutable and is not safe to be accessed or modified by multiple threads concurrently.
Since
2.6
See Also
ParameterizedMessage

Field Summary

Modifier and TypeField and Description
private int
private transient ThreadLocal<StringBuilder>
private static final int
private String
private static final int
private transient Object[]
private final ParameterFormatter.MessagePatternAnalysis
pack-priv transient boolean
private static final long
private transient Throwable
private transient Object[]

Constructor Summary

AccessConstructor and Description
public
ReusableParameterizedMessage()

Creates a reusable message.

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements org.apache.logging.log4j.message.Clearable.clear.

Resets the object to a clean state.

private static Throwable
determineThrowable(final Object[] args, final int argCount, final int placeholderCount)

public <S> void
forEachParameter(final ParameterConsumer<S>
The action to be performed for each key-value pair in this collection
action
,
final S
the object to be passed as the third parameter to each invocation on the specified ParameterConsumer.
state
)

Implements org.apache.logging.log4j.message.ParameterVisitable.forEachParameter.

Performs the given action for each parameter until all values have been processed or the action throws an exception.

public void
formatTo(final StringBuilder
the StringBuilder to write into
builder
)

Implements org.apache.logging.log4j.util.StringBuilderFormattable.formatTo.

Writes a text representation of this object into the specified StringBuilder, ideally without allocating temporary objects.

private StringBuilder
public String

Returns:

the message pattern.
getFormat
()

Implements org.apache.logging.log4j.message.Message.getFormat.

Returns the message pattern.

public String

Returns:

the formatted message.
getFormattedMessage
()

Implements org.apache.logging.log4j.message.Message.getFormattedMessage.

Returns the formatted message.

public short
getParameterCount()

Implements org.apache.logging.log4j.message.ReusableMessage.getParameterCount.

Returns the number of parameters that was used to initialize this reusable message for the current content.

public Object[]

Returns:

the message parameters.
getParameters
()

Implements org.apache.logging.log4j.message.Message.getParameters.

Returns the message parameters.

private Object[]
public Throwable

Returns:

the Throwable, if any.
getThrowable
()

Implements org.apache.logging.log4j.message.Message.getThrowable.

Returns the Throwable that was given as the last argument, if any.

private Object[]
private void
init(final String messagePattern, final int argCount, final Object[] args)

public Message
memento()

Implements org.apache.logging.log4j.message.ReusableMessage.memento.

Returns an immutable snapshot of the current internal state of this reusable message.

pack-priv ReusableParameterizedMessage

Returns:

this object
reserve
()

Sets the reserved flag to true and returns this object.

pack-priv ReusableParameterizedMessage
set(final String messagePattern, final Object... arguments)

pack-priv ReusableParameterizedMessage
set(final String messagePattern, final Object p0)

pack-priv ReusableParameterizedMessage
set(final String messagePattern, final Object p0, final Object p1)

pack-priv ReusableParameterizedMessage
set(final String messagePattern, final Object p0, final Object p1, final Object p2)

pack-priv ReusableParameterizedMessage
set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3)

pack-priv ReusableParameterizedMessage
set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4)

pack-priv ReusableParameterizedMessage
set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5)

pack-priv ReusableParameterizedMessage
set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, final Object p6)

pack-priv ReusableParameterizedMessage
set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, final Object p6, final Object p7)

pack-priv ReusableParameterizedMessage
set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, final Object p6, final Object p7, final Object p8)

pack-priv ReusableParameterizedMessage
set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, final Object p6, final Object p7, final Object p8, final Object p9)

public Object[]
swapParameters(final Object[]
the parameter array that can be used for subsequent uses of this reusable message. This replacement array must have at least 10 elements (the number of varargs supported by the Logger API).
emptyReplacement
)

Implements org.apache.logging.log4j.message.ReusableMessage.swapParameters.

Returns the parameter array that was used to initialize this reusable message and replaces it with the specified array.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

argCountback to summary
private int argCount
bufferback to summary
private transient ThreadLocal<StringBuilder> buffer
MAX_PARAMSback to summary
private static final int MAX_PARAMS
messagePatternback to summary
private String messagePattern
MIN_BUILDER_SIZEback to summary
private static final int MIN_BUILDER_SIZE
paramsback to summary
private transient Object[] params
patternAnalysisback to summary
private final ParameterFormatter.MessagePatternAnalysis patternAnalysis
reservedback to summary
pack-priv transient boolean reserved
serialVersionUIDback to summary
private static final long serialVersionUID
throwableback to summary
private transient Throwable throwable
varargsback to summary
private transient Object[] varargs

Constructor Detail

ReusableParameterizedMessageback to summary
public ReusableParameterizedMessage()

Creates a reusable message.

Method Detail

clearback to summary
public void clear()

Implements org.apache.logging.log4j.message.Clearable.clear.

Doc from org.apache.logging.log4j.message.Clearable.clear.

Resets the object to a clean state.

Annotations
@Override
determineThrowableback to summary
private static Throwable determineThrowable(final Object[] args, final int argCount, final int placeholderCount)
forEachParameterback to summary
public <S> void forEachParameter(final ParameterConsumer<S> action, final S state)

Implements org.apache.logging.log4j.message.ParameterVisitable.forEachParameter.

Doc from org.apache.logging.log4j.message.ParameterVisitable.forEachParameter.

Performs the given action for each parameter until all values have been processed or the action throws an exception.

The second parameter lets callers pass in a stateful object to be modified with the key-value pairs, so the TriConsumer implementation itself can be stateless and potentially reusable.

Parameters
<S>
type of the third parameter
action:ParameterConsumer<S>

The action to be performed for each key-value pair in this collection

state:S

the object to be passed as the third parameter to each invocation on the specified ParameterConsumer.

Annotations
@Override
formatToback to summary
public void formatTo(final StringBuilder builder)

Implements org.apache.logging.log4j.util.StringBuilderFormattable.formatTo.

Doc from org.apache.logging.log4j.util.StringBuilderFormattable.formatTo.

Writes a text representation of this object into the specified StringBuilder, ideally without allocating temporary objects.

Parameters
builder:StringBuilder

the StringBuilder to write into

Annotations
@Override
getBufferback to summary
private StringBuilder getBuffer()
getFormatback to summary
public String getFormat()

Implements org.apache.logging.log4j.message.Message.getFormat.

Returns the message pattern.

Returns:String

the message pattern.

Annotations
@Override
getFormattedMessageback to summary
public String getFormattedMessage()

Implements org.apache.logging.log4j.message.Message.getFormattedMessage.

Returns the formatted message.

Returns:String

the formatted message.

Annotations
@Override
getParameterCountback to summary
public short getParameterCount()

Implements org.apache.logging.log4j.message.ReusableMessage.getParameterCount.

Doc from org.apache.logging.log4j.message.ReusableMessage.getParameterCount.

Returns the number of parameters that was used to initialize this reusable message for the current content.

The parameter array returned by swapParameters(Object[]) may be larger than the actual number of parameters. Callers should use this method to determine how many elements the array contains.

Returns:short

the current number of parameters

Annotations
@Override
getParametersback to summary
public Object[] getParameters()

Implements org.apache.logging.log4j.message.Message.getParameters.

Returns the message parameters.

Returns:Object[]

the message parameters.

Annotations
@Override
getParamsback to summary
private Object[] getParams()
getThrowableback to summary
public Throwable getThrowable()

Implements org.apache.logging.log4j.message.Message.getThrowable.

Returns the Throwable that was given as the last argument, if any. It will not survive serialization. The Throwable exists as part of the message primarily so that it can be extracted from the end of the list of parameters and then be added to the LogEvent. As such, the Throwable in the event should not be used once the LogEvent has been constructed.

Returns:Throwable

the Throwable, if any.

Annotations
@Override
getTrimmedParamsback to summary
private Object[] getTrimmedParams()
initback to summary
private void init(final String messagePattern, final int argCount, final Object[] args)
mementoback to summary
public Message memento()

Implements org.apache.logging.log4j.message.ReusableMessage.memento.

Doc from org.apache.logging.log4j.message.ReusableMessage.memento.

Returns an immutable snapshot of the current internal state of this reusable message. The returned snapshot will not be affected by subsequent modifications of this reusable message.

Returns:Message

an immutable snapshot of this message

Annotations
@Override
reserveback to summary
pack-priv ReusableParameterizedMessage reserve()

Sets the reserved flag to true and returns this object.

Returns:ReusableParameterizedMessage

this object

Since
2.7
setback to summary
pack-priv ReusableParameterizedMessage set(final String messagePattern, final Object... arguments)
setback to summary
pack-priv ReusableParameterizedMessage set(final String messagePattern, final Object p0)
setback to summary
pack-priv ReusableParameterizedMessage set(final String messagePattern, final Object p0, final Object p1)
setback to summary
pack-priv ReusableParameterizedMessage set(final String messagePattern, final Object p0, final Object p1, final Object p2)
setback to summary
pack-priv ReusableParameterizedMessage set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3)
setback to summary
pack-priv ReusableParameterizedMessage set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4)
setback to summary
pack-priv ReusableParameterizedMessage set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5)
setback to summary
pack-priv ReusableParameterizedMessage set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, final Object p6)
setback to summary
pack-priv ReusableParameterizedMessage set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, final Object p6, final Object p7)
setback to summary
pack-priv ReusableParameterizedMessage set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, final Object p6, final Object p7, final Object p8)
setback to summary
pack-priv ReusableParameterizedMessage set(final String messagePattern, final Object p0, final Object p1, final Object p2, final Object p3, final Object p4, final Object p5, final Object p6, final Object p7, final Object p8, final Object p9)
swapParametersback to summary
public Object[] swapParameters(final Object[] emptyReplacement)

Implements org.apache.logging.log4j.message.ReusableMessage.swapParameters.

Doc from org.apache.logging.log4j.message.ReusableMessage.swapParameters.

Returns the parameter array that was used to initialize this reusable message and replaces it with the specified array. The returned parameter array will no longer be modified by this reusable message. The specified array is now "owned" by this reusable message and can be modified if necessary for the next log event.

ReusableMessages that have no parameters return the specified array.

This method is used by asynchronous loggers to pass the parameter array to a background thread without allocating new objects. The actual number of parameters in the returned array can be determined with getParameterCount().

Parameters
emptyReplacement:Object[]

the parameter array that can be used for subsequent uses of this reusable message. This replacement array must have at least 10 elements (the number of varargs supported by the Logger API).

Returns:Object[]

the parameter array for the current message content. This may be a vararg array of any length, or it may be a reusable array of 10 elements used to hold the unrolled vararg parameters.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
writeReplaceback to summary
private Object writeReplace()