Class JsonSocketService<H extends JsonHttpService>

java.lang.Object
jmri.server.json.JsonSocketService<H>
Type Parameters:
H - The supporting JsonHttpService implementing class
Direct Known Subclasses:
JsonConsistSocketService, JsonLayoutBlockSocketService, JsonMessageSocketService, JsonNamedBeanSocketService, JsonOperationsSocketService, JsonPowerSocketService, JsonRosterSocketService, JsonSchemaSocketService, JsonSignalHeadSocketService, JsonThrottleSocketService, JsonTimeSocketService, JsonUtilSocketService

public abstract class JsonSocketService<H extends JsonHttpService>
extends Object
Interface for JSON Services provided over TCP Sockets or WebSockets.
  • Field Details

  • Constructor Details

  • Method Details

    • onMessage

      public abstract void onMessage​(@Nonnull String type, @Nonnull com.fasterxml.jackson.databind.JsonNode data, @Nonnull JsonRequest request) throws IOException, JmriException, JsonException
      Handle an inbound message.
      Parameters:
      type - The service type; if the implementing service responds to multiple types, it will need to use this to handle data correctly
      data - JSON data; the contents of this will depend on the implementing service
      request - The JSON request
      Throws:
      IOException - Thrown if the service cannot send a response; this will cause the JSON Server to close its connection to the client if open
      JmriException - Thrown if the request cannot be handled; throwing this will cause the JSON Server to pass a 500 UnsupportedOperation message to the client
      JsonException - Thrown if the service needs to pass an error message back to the client
    • onMessage

      @Deprecated public void onMessage​(@Nonnull String type, @Nonnull com.fasterxml.jackson.databind.JsonNode data, @Nonnull String method, @Nonnull Locale locale, int id) throws IOException, JmriException, JsonException
      Deprecated.
      Handle an inbound message.
      Parameters:
      type - The service type. If the implementing service responds to multiple types, it will need to use this to handle data correctly.
      data - JSON data. The contents of this will depend on the implementing service.
      method - The HTTP method to handle in this message.
      locale - The locale of the client, which may be different than the locale of the JMRI server.
      id - the message id set by the client
      Throws:
      IOException - Thrown if the service cannot send a response. This will cause the JSON Server to close its connection to the client if open.
      JmriException - Thrown if the request cannot be handled. Throwing this will cause the JSON Server to pass a 500 UnsupportedOperation message to the client.
      JsonException - Thrown if the service needs to pass an error message back to the client.
    • onList

      public abstract void onList​(@Nonnull String type, @Nonnull com.fasterxml.jackson.databind.JsonNode data, @Nonnull JsonRequest request) throws IOException, JmriException, JsonException
      Handle a request for a list of objects. Note that this should not create listeners for items in the list, but should only create listeners for the object providing the list, if applicable.
      Parameters:
      type - The service type; if the implementing service responds to multiple types, it will need to use this to handle data correctly
      data - JSON data; the contents of this will depend on the implementing service
      request - The JSON request
      Throws:
      IOException - Thrown if the service cannot send a response; this will cause the JSON Server to close its connection to the client if open
      JmriException - Thrown if the request cannot be handled; throwing this will cause the JSON Server to pass a 500 UnsupportedOperation message to the client
      JsonException - If the service needs to pass an error message back to the client; implementing services may throw a JsonException with code 400 and the localized message "UnlistableService" to indicate that type should not be listed
    • onList

      @Deprecated public void onList​(@Nonnull String type, @Nonnull com.fasterxml.jackson.databind.JsonNode data, @Nonnull Locale locale, int id) throws IOException, JmriException, JsonException
      Deprecated.
      since 4.19.2; use onList(String, JsonNode, JsonRequest) instead
      Handle a request for a list of objects. Note that this should not create listeners for items in the list, but should only create listeners for the object providing the list, if applicable.
      Parameters:
      type - The service type; if the implementing service responds to multiple types, it will need to use this to handle data correctly
      data - JSON data; the contents of this will depend on the implementing service
      locale - The locale of the client, which may be different than the locale of the JMRI server
      id - the message id set by the client
      Throws:
      IOException - Thrown if the service cannot send a response; this will cause the JSON Server to close its connection to the client if open
      JmriException - Thrown if the request cannot be handled; throwing this will cause the JSON Server to pass a 500 UnsupportedOperation message to the client
      JsonException - If the service needs to pass an error message back to the client; implementing services may throw a JsonException with code 400 and the localized message "UnlistableService" to indicate that type should not be listed
    • onClose

      public abstract void onClose()
      Perform any teardown required when closing a connection.
    • getConnection

      Get the connection to the client.
      Returns:
      the connection
    • getHttpService

      @Nonnull public final H getHttpService()
      Get the supporting JsonHttpService.
      Returns:
      the supporting service
    • getLocale

      @Nonnull protected final Locale getLocale()
      Get the in-use locale
      Returns:
      the locale
    • setLocale

      @Deprecated protected final void setLocale​(@Nonnull Locale locale)
      Deprecated.
      since 4.19.2 without direct replacement; rely on JsonClientHandler.onMessage(JsonNode) to ensure this is correct
      Set the in-use locale
      Parameters:
      locale - the new locale
    • getVersion

      protected final String getVersion()
      Get the JSON protocol version
      Returns:
      the version