public class PubSubMessage extends Object implements Serializable, JSONFormatter
| Modifier and Type | Field and Description |
|---|---|
static Charset |
CHARSET |
protected Object |
content |
protected String |
id |
protected Metadata |
metadata |
GSON, INVALID_DOUBLES| Constructor and Description |
|---|
PubSubMessage()
Constructor for a message having no information.
|
PubSubMessage(String id,
Metadata.Signal signal)
Constructor for a message having only a
Metadata.Signal. |
PubSubMessage(String id,
Serializable content)
Constructor for a message having only content.
|
PubSubMessage(String id,
Serializable content,
Metadata.Signal signal)
Constructor for a message having content and a
Metadata.Signal. |
PubSubMessage(String id,
Serializable content,
Metadata metadata)
Constructor for a message having content and
Metadata. |
| Modifier and Type | Method and Description |
|---|---|
String |
asJSON()
Convert this object to a JSON string.
|
boolean |
equals(Object other) |
static PubSubMessage |
fromJSON(String json)
Converts a json representation back to an instance.
|
static PubSubMessage |
fromJSON(String json,
com.google.gson.Gson gson)
Converts a JSON representation back to an instance using a specific
Gson converter. |
Serializable |
getContent()
Returns the
Serializable content stored in the message. |
byte[] |
getContentAsByteArray()
Returns the content stored in the message as a byte[].
|
Query |
getContentAsQuery()
Returns the content stored in the message as a
Query. |
String |
getContentAsString()
Returns the content stored in the message as a String.
|
boolean |
hasContent()
Check if message has content.
|
int |
hashCode() |
boolean |
hasMetadata()
Check if message has
Metadata. |
boolean |
hasSignal()
Check if the message has a
Metadata.Signal. |
boolean |
hasSignal(Metadata.Signal signal)
Check if message has a given
Metadata.Signal. |
void |
setContent(Serializable content)
Set a
Serializable content for this message. |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitasJSON, fromJSONpublic static final Charset CHARSET
protected String id
protected Object content
protected Metadata metadata
public PubSubMessage()
public PubSubMessage(String id, Metadata.Signal signal)
Metadata.Signal.id - The ID associated with the message.signal - The signal only for the Metadata.public PubSubMessage(String id, Serializable content)
id - The ID associated with the message.content - The content of the message.public PubSubMessage(String id, Serializable content, Metadata.Signal signal)
Metadata.Signal.id - The ID associated with the message.content - The content of the message.signal - The Signal to be sent with the message.public PubSubMessage(String id, Serializable content, Metadata metadata)
Metadata.id - The ID associated with the message.content - The content of the message.metadata - The Metadata associated with the message.public boolean hasContent()
public boolean hasMetadata()
Metadata.public boolean hasSignal(Metadata.Signal signal)
Metadata.Signal.signal - The signal to check for.public boolean hasSignal()
Metadata.Signal.public Serializable getContent()
Serializable content stored in the message.public byte[] getContentAsByteArray()
public String getContentAsString()
public Query getContentAsQuery()
Query. You should use this to read the Query back
if you originally provided to the message as a Serializable.Query.public void setContent(Serializable content)
Serializable content for this message.content - The content for this message.public String asJSON()
JSONFormatterasJSON in interface JSONFormatterpublic static PubSubMessage fromJSON(String json)
asJSON().json - The string representation of the JSON.public static PubSubMessage fromJSON(String json, com.google.gson.Gson gson)
Gson converter.
Is the inverse of asJSON().json - The string representation of the JSON.gson - The Gson converter to use.Copyright © 2021. All rights reserved.