Package jmri.server.json.message
Class JsonMessage
- java.lang.Object
-
- jmri.server.json.message.JsonMessage
-
public class JsonMessage extends java.lang.Object
A message to be sent by the JMRI JSON message service.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJsonMessage.TYPE
-
Constructor Summary
Constructors Constructor Description JsonMessage(java.lang.String message, java.util.Locale locale)Create a message with anJsonMessage.TYPE.INFOtype to be sent to all JSON clients.JsonMessage(JsonMessage.TYPE type, java.lang.String message, java.lang.String client, com.fasterxml.jackson.databind.JsonNode context, java.util.Locale locale)Create a message to be sent to the specified JSON client with the specified context.JsonMessage(JsonMessage.TYPE type, java.lang.String message, java.lang.String client, java.util.Locale locale)Create a message to be sent to the specified JSON client.JsonMessage(JsonMessage.TYPE type, java.lang.String message, java.util.Locale locale)Create a message to be sent to all JSON clients.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetClient()com.fasterxml.jackson.databind.JsonNodegetContext()java.util.LocalegetLocale()java.lang.StringgetMessage()java.lang.StringgetType()Get the JSON token for each of the message types used in the constructors.voidsend()Send the message using the defaultJsonMessageClientManager.com.fasterxml.jackson.databind.JsonNodetoJSON(com.fasterxml.jackson.databind.ObjectMapper mapper)Create a JSON node from this message.
-
-
-
Field Detail
-
CLIENT
public static final java.lang.String CLIENT
"client"- See Also:
- Constant Field Values
-
MESSAGE
public static final java.lang.String MESSAGE
"message"- See Also:
- Constant Field Values
-
CONTEXT
public static final java.lang.String CONTEXT
"context"- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JsonMessage
public JsonMessage(@Nonnull java.lang.String message, @Nonnull java.util.Locale locale)
Create a message with anJsonMessage.TYPE.INFOtype to be sent to all JSON clients.- Parameters:
message- the message to sendlocale- the locale of the message
-
JsonMessage
public JsonMessage(JsonMessage.TYPE type, @Nonnull java.lang.String message, @Nonnull java.util.Locale locale)
Create a message to be sent to all JSON clients.- Parameters:
type- the message typemessage- the message to sendlocale- the locale of the message
-
JsonMessage
public JsonMessage(JsonMessage.TYPE type, @Nonnull java.lang.String message, @CheckForNull java.lang.String client, @Nonnull java.util.Locale locale)
Create a message to be sent to the specified JSON client.- Parameters:
type- the message typemessage- the message to sendclient- the client to send the message to; if null, the message is sent to all clientslocale- the locale of the message
-
JsonMessage
public JsonMessage(JsonMessage.TYPE type, @Nonnull java.lang.String message, @CheckForNull java.lang.String client, @CheckForNull com.fasterxml.jackson.databind.JsonNode context, @Nonnull java.util.Locale locale)
Create a message to be sent to the specified JSON client with the specified context.- Parameters:
type- the message typemessage- the message to sendclient- the client to send the message to; if null, the message is sent to all clientscontext- the context for the message; if null, no context is sentlocale- the locale of the message
-
-
Method Detail
-
send
public void send()
Send the message using the defaultJsonMessageClientManager.To send a message to an alternate JsonMessageClientManager, call that manager's
JsonMessageClientManager.send(jmri.server.json.message.JsonMessage)method.
-
getClient
public java.lang.String getClient()
-
getContext
public com.fasterxml.jackson.databind.JsonNode getContext()
-
getMessage
public java.lang.String getMessage()
-
getLocale
public java.util.Locale getLocale()
-
getType
public java.lang.String getType()
Get the JSON token for each of the message types used in the constructors.- Returns:
- the token value
-
toJSON
public com.fasterxml.jackson.databind.JsonNode toJSON(com.fasterxml.jackson.databind.ObjectMapper mapper)
Create a JSON node from this message.- Parameters:
mapper- the instance used to create raw JSON nodes- Returns:
- the JSON node
-
-