@NotThreadSafe public final class ProcessingMessage extends Object implements AsJson
Internally, a processing message has a Map whose keys are strings
and values are JsonNodes. Note that all methods altering the message
contents accept null: in this case, the value for that key will be a
NullNode.
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 |
message(String message)
Set the main message
|
<T> ProcessingMessage |
message(T value)
Set 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 |
setExceptionProvider(ExceptionProvider exceptionProvider)
Set the exception provider for that particular message
|
ProcessingMessage |
setLogLevel(LogLevel level)
Set the log level for this message
|
String |
toString() |
public ProcessingMessage()
By default, a message is generated with a log level of LogLevel.INFO.
public ProcessingMessage setExceptionProvider(ExceptionProvider exceptionProvider)
exceptionProvider - the exception providerProcessingError - exception provider is nullpublic ProcessingMessage setLogLevel(LogLevel level)
level - the log levelProcessingError - log level is nullpublic ProcessingMessage message(String message)
message - the message as a stringpublic <T> ProcessingMessage message(T value)
The value type can be anything. It is your responsibility to make sure
that Object.toString() is implemented correctly!
T - the type of the valuevalue - the valuepublic String getMessage()
public 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 JsonNodepublic ProcessingMessage put(String key, AsJson asJson)
key - the keyasJson - the value, which implements AsJsonpublic 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 <T> ProcessingMessage put(String key, T value)
As for message(Object), ensure that toString() is
correctly implemented.
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 LogLevel getLogLevel()
public JsonNode asJson()
AsJsonpublic ProcessingException asException()
This uses the ExceptionProvider built into the message and
invokes ExceptionProvider.doException(ProcessingMessage) with
this as an argument.
setExceptionProvider(ExceptionProvider)Copyright © 2013. All Rights Reserved.