Class MapMessage<M extends MapMessage<M,V>,V>
- Type Parameters:
M
- Allow subclasses to use fluent APIs and override methods that return instances of subclasses.V
- The value type
- All Implemented Interfaces:
Serializable
,Message
,MultiformatMessage
,MultiFormatStringBuilderFormattable
,StringBuilderFormattable
- Direct Known Subclasses:
StringMapMessage
,StructuredDataMessage
Thread-safety note: the contents of this message can be modified after construction. When using asynchronous loggers and appenders it is not recommended to modify this message after the message is logged, because it is undefined whether the logged message string will contain the old values or the modified values.
This class was pulled up from StringMapMessage
to allow for Objects as values.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
When set as the format specifier causes the Map to be formatted as XML. -
Constructor Summary
ConstructorDescriptionConstructs a new instance.MapMessage
(int initialCapacity) Constructs a new instance.MapMessage
(Map<String, V> map) Constructs a new instance based on an existingMap
. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected void
asJava
(StringBuilder sb) protected void
protected void
asJson
(StringBuilder sb) asString()
Formats the Structured data as described in RFC 5424.Formats the Structured data as described in RFC 5424.void
asXml
(StringBuilder sb) Formats this message as an XML fragment String into the given builder.void
clear()
Clear the data.boolean
containsKey
(String key) Returnstrue
if this data structure contains the specified key,false
otherwise.boolean
<CV> void
forEach
(BiConsumer<String, ? super CV> action) Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.<CV,
S> void forEach
(TriConsumer<String, ? super CV, S> action, S state) Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.void
formatTo
(String[] formats, StringBuilder buffer) Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.void
formatTo
(StringBuilder buffer) Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.Retrieves the value of the element with the specified key or null if the key is not present.getData()
Returns the message data as an unmodifiable Map.Returns the message.String[]
Returns the supported formats.Formats the message and return it.getFormattedMessage
(String[] formats) Returns the Message formatted as a String.Returns a read-only view of the message data.Object[]
Returns the data elements as if they were parameters on the logging event.Always returns null.int
hashCode()
newInstance
(Map<String, V> map) Constructs a new instance based on an existing Map.void
Adds an item to the data Map.void
Adds all the elements from the specified Map.Removes the element with the specified name.protected String
Allows subclasses to change a candidate key to an actual key.toString()
protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.protected void
Default implementation does nothing.Adds an item to the data Map.Adds an item to the data Map.Adds an item to the data Map.Adds an item to the data Map.Adds an item to the data Map.Adds an item to the data Map.Adds an item to the data Map.Adds an item to the data Map.Adds an item to the data Map.Adds an item to the data Map in fluent style.
-
Constructor Details
-
MapMessage
public MapMessage()Constructs a new instance. -
MapMessage
public MapMessage(int initialCapacity) Constructs a new instance.- Parameters:
initialCapacity
- the initial capacity.- Since:
- 2.9.0
-
MapMessage
Constructs a new instance based on an existingMap
.- Parameters:
map
- The Map.
-
-
Method Details
-
getFormats
Description copied from interface:MultiformatMessage
Returns the supported formats.- Specified by:
getFormats
in interfaceMultiformatMessage
- Returns:
- The supported formats.
-
getParameters
Returns the data elements as if they were parameters on the logging event.- Specified by:
getParameters
in interfaceMessage
- Returns:
- the data elements.
-
getFormat
Returns the message. -
getData
Returns the message data as an unmodifiable Map.- Returns:
- the message data as an unmodifiable map.
-
getIndexedReadOnlyStringMap
Returns a read-only view of the message data.- Returns:
- the read-only message data.
-
clear
public void clear()Clear the data. -
containsKey
Returnstrue
if this data structure contains the specified key,false
otherwise.- Parameters:
key
- the key whose presence to check. May benull
.- Returns:
true
if this data structure contains the specified key,false
otherwise- Since:
- 2.9.0
-
put
Adds an item to the data Map.- Parameters:
candidateKey
- The name of the data item.value
- The value of the data item.
-
putAll
Adds all the elements from the specified Map.- Parameters:
map
- The Map to add.
-
get
Retrieves the value of the element with the specified key or null if the key is not present.- Parameters:
key
- The name of the element.- Returns:
- The value of the element or null if the key is not present.
-
remove
Removes the element with the specified name.- Parameters:
key
- The name of the element.- Returns:
- The previous value of the element.
-
asString
Formats the Structured data as described in RFC 5424.- Returns:
- The formatted String.
-
asString
Formats the Structured data as described in RFC 5424.- Parameters:
format
- The format identifier.- Returns:
- The formatted String.
-
forEach
Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.Some implementations may not support structural modifications (adding new elements or removing elements) while iterating over the contents. In such implementations, attempts to add or remove elements from the
BiConsumer
'sBiConsumer.accept(Object, Object)
accept} method may cause aConcurrentModificationException
to be thrown.- Type Parameters:
CV
- type of the consumer value- Parameters:
action
- The action to be performed for each key-value pair in this collection- Throws:
ConcurrentModificationException
- some implementations may not support structural modifications to this data structure while iterating over the contents.- Since:
- 2.9.0
- See Also:
-
forEach
Performs the given action for each key-value pair in this data structure until all entries have been processed or the action throws an exception.The third 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.
Some implementations may not support structural modifications (adding new elements or removing elements) while iterating over the contents. In such implementations, attempts to add or remove elements from the
TriConsumer
'saccept
method may cause aConcurrentModificationException
to be thrown.- Type Parameters:
CV
- type of the consumer valueS
- type of the third parameter- Parameters:
action
- The action to be performed for each key-value pair in this collectionstate
- the object to be passed as the third parameter to each invocation on the specified triconsumer- Throws:
ConcurrentModificationException
- some implementations may not support structural modifications to this data structure while iterating over the contents.- Since:
- 2.9.0
- See Also:
-
asXml
Formats this message as an XML fragment String into the given builder.- Parameters:
sb
- format into this builder.
-
getFormattedMessage
Formats the message and return it.- Specified by:
getFormattedMessage
in interfaceMessage
- Returns:
- the formatted message.
-
getFormattedMessage
Description copied from interface:MultiformatMessage
Returns the Message formatted as a String.- Specified by:
getFormattedMessage
in interfaceMultiformatMessage
- Parameters:
formats
- An array of Strings that provide extra information about how to format the message. MapMessage uses the first format specifier it recognizes. The supported formats are XML, JSON, and JAVA. The default format is key1="value1" key2="value2" as required by RFC 5424 messages.- Returns:
- The formatted message.
-
appendMap
-
asJson
-
asJavaUnquoted
- Since:
- 2.11.2
-
asJava
-
newInstance
Constructs a new instance based on an existing Map.- Parameters:
map
- The Map.- Returns:
- A new MapMessage
-
toString
-
formatTo
Description copied from interface:StringBuilderFormattable
Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.- Specified by:
formatTo
in interfaceStringBuilderFormattable
- Parameters:
buffer
- the StringBuilder to write into
-
formatTo
Description copied from interface:MultiFormatStringBuilderFormattable
Writes a text representation of this object into the specifiedStringBuilder
, ideally without allocating temporary objects.- Specified by:
formatTo
in interfaceMultiFormatStringBuilderFormattable
- Parameters:
formats
- An array of Strings that provide extra information about how to format the message. Each MultiFormatStringBuilderFormattable implementation is free to use the provided formats however they choose.buffer
- the StringBuilder to write into
-
equals
-
hashCode
public int hashCode() -
getThrowable
Always returns null.- Specified by:
getThrowable
in interfaceMessage
- Returns:
- null
-
validate
Default implementation does nothing.- Since:
- 2.9.0
-
validate
Default implementation does nothing.- Since:
- 2.9.0
-
validate
Default implementation does nothing.- Since:
- 2.9.0
-
validate
Default implementation does nothing.- Since:
- 2.9.0
-
validate
Default implementation does nothing.- Since:
- 2.9.0
-
validate
Default implementation does nothing.- Since:
- 2.9.0
-
validate
Default implementation does nothing.- Since:
- 2.9.0
-
validate
Default implementation does nothing.- Since:
- 2.9.0
-
validate
Default implementation does nothing.- Since:
- 2.9.0
-
validate
Default implementation does nothing.- Since:
- 2.9.0
-
toKey
Allows subclasses to change a candidate key to an actual key.- Parameters:
candidateKey
- The candidate key.- Returns:
- The candidate key.
- Since:
- 2.12.0
-
with
Adds an item to the data Map.- Parameters:
candidateKey
- The name of the data item.value
- The value of the data item.- Returns:
- this object
- Since:
- 2.9.0
-
with
Adds an item to the data Map.- Parameters:
candidateKey
- The name of the data item.value
- The value of the data item.- Returns:
- this object
- Since:
- 2.9.0
-
with
Adds an item to the data Map.- Parameters:
candidateKey
- The name of the data item.value
- The value of the data item.- Returns:
- this object
- Since:
- 2.9.0
-
with
Adds an item to the data Map.- Parameters:
candidateKey
- The name of the data item.value
- The value of the data item.- Returns:
- this object
- Since:
- 2.9.0
-
with
Adds an item to the data Map.- Parameters:
candidateKey
- The name of the data item.value
- The value of the data item.- Returns:
- this object
- Since:
- 2.9.0
-
with
Adds an item to the data Map.- Parameters:
candidateKey
- The name of the data item.value
- The value of the data item.- Returns:
- this object
- Since:
- 2.9.0
-
with
Adds an item to the data Map.- Parameters:
candidateKey
- The name of the data item.value
- The value of the data item.- Returns:
- this object
- Since:
- 2.9.0
-
with
Adds an item to the data Map.- Parameters:
candidateKey
- The name of the data item.value
- The value of the data item.- Returns:
- this object
- Since:
- 2.9.0
-
with
Adds an item to the data Map.- Parameters:
candidateKey
- The name of the data item.value
- The value of the data item.- Returns:
- this object
- Since:
- 2.9.0
-
with
Adds an item to the data Map in fluent style.- Parameters:
candidateKey
- The name of the data item.value
- The value of the data item.- Returns:
this
- Since:
- 2.5
-