public final class Message
extends java.lang.Object
implements java.lang.Cloneable
A message may have a null payload; many plug-ins will silently pass through messages with null payloads, but plug-ins may treat them as special messages depending on the metadata.
Metadata is information that would not be thought of as part of the message payload, but data about the message. This may correspond to headers for a transport, or information deciding how to route the message. If required, the host's type will be specified in the metadata.
Messages passed between codec and transport plug-ins are not copied and Messages are mutable: plug-ins should send copies of Messages if they need to keep pristine copies of messages for future use, as other plug-ins may modify a Message.
This class is not thread-safe, so users are required to ensure that each instance of Message is only accessed by the codec or transport plug-in that currently owns it, and that only one thread from each plug-in is accessing it at any one time.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
CHANNEL
The metadata key for the channel name.
|
static java.lang.String |
HOST_MESSAGE_TYPE
The metadata key for the type of message; its meaning is host-specific.
|
Constructor and Description |
---|
Message(java.lang.Object payload)
Create a message with the given payload.
|
Message(java.lang.Object payload,
java.util.Map<java.lang.String,java.lang.String> metadata)
Create a message with the given payload and metadata
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Create a copy of this Message.
|
Message |
copy()
Create a copy of this Message.
|
java.util.Map<java.lang.String,java.lang.String> |
getMetadata()
Get the metadata for this message.
|
java.lang.Object |
getPayload()
Get the payload object.
|
Message |
putMetadataValue(java.lang.String key,
java.lang.String value)
Put the specified key,value pair into the metadata for this message.
|
Message |
setPayload(java.lang.Object e)
Set the payload object.
|
java.lang.String |
toString()
Return a string representation of the message metadata and payload.
|
java.lang.String |
toString(boolean noTruncate)
Return a string representation of the message metadata and payload.
|
public static final java.lang.String CHANNEL
public static final java.lang.String HOST_MESSAGE_TYPE
public Message(java.lang.Object payload, java.util.Map<java.lang.String,java.lang.String> metadata)
public Message(java.lang.Object payload)
public java.lang.Object getPayload()
The contents of the payload may be mutated (for example if it is a map) by subsequent codecs - if a sender requires a pristine copy, it will need to take a copy before sending the message.
The contents of the payload should not contain cycles - that is, a Map cannot contain a value that can reach the map.
MapHelper can be used to extract the content of payload.
May be null.
setPayload(java.lang.Object)
,
MapHelper
public Message setPayload(java.lang.Object e)
e
- May be null.getPayload()
,
MapHelper
public java.util.Map<java.lang.String,java.lang.String> getMetadata()
public Message putMetadataValue(java.lang.String key, java.lang.String value)
public Message copy() throws java.lang.CloneNotSupportedException
Requires that the payload be and contain only objects of String, Map, List, Boolean, Double, Long or byte[].
java.lang.CloneNotSupportedException
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public java.lang.String toString(boolean noTruncate)
noTruncate
- Set to true to disable truncation of long payload strings.public java.lang.String toString()
toString
in class java.lang.Object
Submit a bug or feature
Copyright (c) 2013-2016 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors. Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG.