Package jmri.jmris

Class JmriConnection

java.lang.Object
jmri.jmris.JmriConnection
Direct Known Subclasses:
JsonConnection

public class JmriConnection
extends Object
Abstraction of DataOutputStream and WebSocket.Connection classes.

Used so that that server objects need only to use a single object/method to send data to any supported object type.

  • Constructor Details

    • JmriConnection

      public JmriConnection​(org.eclipse.jetty.websocket.api.Session connection)
      Create a JmriConnection that sends output to a WebSocket.
      Parameters:
      connection - WebSocket Session to use.
    • JmriConnection

      public JmriConnection​(DataOutputStream output)
      Create a JmriConnection that sends output to a DataOutputStream.
      Parameters:
      output - DataOutputStream to use
  • Method Details

    • getSession

      public org.eclipse.jetty.websocket.api.Session getSession()
      Get the WebSocket session.
      Returns:
      the WebSocket session
    • getDataOutputStream

    • sendMessage

      public void sendMessage​(String message) throws IOException
      Send a String to the instantiated connection.

      This method throws an IOException so the server or servlet holding the connection open can respond to the exception if there is an immediate failure. If there is an asynchronous failure, the connection is closed.

      Parameters:
      message - message to send
      Throws:
      IOException - if problem sending message
    • close

      public void close() throws IOException
      Close the connection.

      Note: Objects using JmriConnection with a Session may prefer to use getSession().close() since Session.close() does not throw an IOException.

      Throws:
      IOException - if problem closing connection
    • getLocale

      public Locale getLocale()
      Returns:
      the locale
    • setLocale

      public void setLocale​(Locale locale)
      Parameters:
      locale - the locale to set