Class 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 class  JsonMessage.TYPE  
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CLIENT
      "client"
      static java.lang.String CONTEXT
      "context"
      static java.lang.String MESSAGE
      "message"
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonMessage​(java.lang.String message, java.util.Locale locale)
      Create a message with an JsonMessage.TYPE.INFO type 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.String getClient()  
      com.fasterxml.jackson.databind.JsonNode getContext()  
      java.util.Locale getLocale()  
      java.lang.String getMessage()  
      java.lang.String getType()
      Get the JSON token for each of the message types used in the constructors.
      void send()
      Send the message using the default JsonMessageClientManager.
      com.fasterxml.jackson.databind.JsonNode toJSON​(com.fasterxml.jackson.databind.ObjectMapper mapper)
      Create a JSON node from this message.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JsonMessage

        public JsonMessage​(@Nonnull
                           java.lang.String message,
                           @Nonnull
                           java.util.Locale locale)
        Create a message with an JsonMessage.TYPE.INFO type to be sent to all JSON clients.
        Parameters:
        message - the message to send
        locale - 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 type
        message - the message to send
        locale - 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 type
        message - the message to send
        client - the client to send the message to; if null, the message is sent to all clients
        locale - 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 type
        message - the message to send
        client - the client to send the message to; if null, the message is sent to all clients
        context - the context for the message; if null, no context is sent
        locale - the locale of the message
    • Method Detail

      • 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