@NotThreadSafe public final class ProcessingMessage extends Object implements AsJson
Internally, a processing message has a Map
whose keys are strings
and values are JsonNode
s. Note that all methods altering the message
contents accept null
: in this case, the value for that key will be a
NullNode
. If you submit null keys, the whole value will be
ignored.
Some methods to append contents to a message accept arbitrary inputs: in
this case, it is your responsibility to ensure that these inputs have a
correct implementation of Object.toString()
.
You can use formatted strings as messages using the capabilities of Formatter
; in order to pass arguments to the different placeholders, you
will then use the .putArgument()
methods instead of .put()
.
Arguments will appear in the order you submit them.
Please note that if you do:
message.setMessage("foo %s").putArgument("something", "here") .setMessage("another %s message")
then the argument list is cleared.
You can alter the behaviour of a processing message in two ways: its log
level and its ExceptionProvider
(used in asException()
.
All mutation methods of a message return this
.
Constructor and Description |
---|
ProcessingMessage()
Constructor
|
Modifier and Type | Method and Description |
---|---|
ProcessingException |
asException()
Build an exception out of this message
|
JsonNode |
asJson()
Return a JSON representation of this object
|
LogLevel |
getLogLevel()
Get the log level for this message
|
String |
getMessage()
Get the main message
|
ProcessingMessage |
put(String key,
AsJson asJson)
Add a key/value pair to this message
|
ProcessingMessage |
put(String key,
int value)
Add a key/value pair to this message
|
<T> ProcessingMessage |
put(String key,
Iterable<T> values)
Add a key/value pair to this message, where the value is a collection of
items
|
ProcessingMessage |
put(String key,
JsonNode value)
Add a key/value pair to this message
|
ProcessingMessage |
put(String key,
String value)
Add a key/value pair to this message
|
<T> ProcessingMessage |
put(String key,
T value)
Add a key/value pair to this message
|
ProcessingMessage |
putArgument(String key,
AsJson asJson)
Add a key/value pair to this message, which is also a formatter argument
|
ProcessingMessage |
putArgument(String key,
int value)
Add a key/value pair to this message, which is also a formatter argument
|
<T> ProcessingMessage |
putArgument(String key,
Iterable<T> values)
Add a key/value pair to this message, which is also a formatter argument
|
ProcessingMessage |
putArgument(String key,
JsonNode value)
Add a key/value pair to this message, which is also a formatter argument
|
<T> ProcessingMessage |
putArgument(String key,
T value)
Add a key/value pair to this message, which is also a formatter argument
|
ProcessingMessage |
setExceptionProvider(ExceptionProvider exceptionProvider)
Set the exception provider for that particular message
|
ProcessingMessage |
setLogLevel(LogLevel level)
Set the log level for this message
|
ProcessingMessage |
setMessage(String message)
Set the main message
|
String |
toString() |
public ProcessingMessage()
By default, a message is generated with a log level of LogLevel.INFO
.
public String getMessage()
public LogLevel getLogLevel()
public ProcessingMessage setMessage(String message)
message
- the message as a stringpublic ProcessingMessage setLogLevel(LogLevel level)
level
- the log levelNullPointerException
- log level is nullpublic ProcessingMessage setExceptionProvider(ExceptionProvider exceptionProvider)
exceptionProvider
- the exception providerNullPointerException
- exception provider is nullpublic ProcessingMessage put(String key, JsonNode value)
This is the main method. All other put methods call this one.
Note that if the key is null
, the content is ignored.
key
- the keyvalue
- the value as a JsonNode
public ProcessingMessage putArgument(String key, JsonNode value)
key
- the keyvalue
- the valuepublic ProcessingMessage put(String key, AsJson asJson)
key
- the keyasJson
- the value, which implements AsJson
public ProcessingMessage putArgument(String key, AsJson asJson)
key
- the keyasJson
- the valuepublic ProcessingMessage put(String key, String value)
key
- the keyvalue
- the valuepublic ProcessingMessage put(String key, int value)
key
- the keyvalue
- the value as an integerpublic ProcessingMessage putArgument(String key, int value)
key
- the keyvalue
- the valuepublic <T> ProcessingMessage put(String key, T value)
Ensure that toString()
is correctly implemented.
T
- the type of the valuekey
- the keyvalue
- the valuepublic <T> ProcessingMessage putArgument(String key, T value)
T
- the type of the valuekey
- the keyvalue
- the valuepublic <T> ProcessingMessage put(String key, Iterable<T> values)
This will put all values (again, using toString()
of the
collection into an array.
T
- the element type of the collectionkey
- the keyvalues
- the collection of valuespublic <T> ProcessingMessage putArgument(String key, Iterable<T> values)
Note that the collection will not be "exploded" into its individual arguments.
T
- type of valueskey
- the keyvalues
- the collection of valuespublic JsonNode asJson()
AsJson
public ProcessingException asException()
This uses the ExceptionProvider
built into the message and
invokes ExceptionProvider.doException(ProcessingMessage)
with
this
as an argument.
setExceptionProvider(ExceptionProvider)