Package jmri.jmris

Class JmriConnection

  • Direct Known Subclasses:
    JsonConnection

    public class JmriConnection
    extends java.lang.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 Summary

      Constructors 
      Constructor Description
      JmriConnection​(java.io.DataOutputStream output)
      Create a JmriConnection that sends output to a DataOutputStream.
      JmriConnection​(org.eclipse.jetty.websocket.api.Session connection)
      Create a JmriConnection that sends output to a WebSocket.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close the connection.
      java.io.DataOutputStream getDataOutputStream()  
      java.util.Locale getLocale()  
      org.eclipse.jetty.websocket.api.Session getSession()
      Get the WebSocket session.
      void sendMessage​(java.lang.String message)
      Send a String to the instantiated connection.
      void setLocale​(java.util.Locale locale)  
      • Methods inherited from class java.lang.Object

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

      • 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​(java.io.DataOutputStream output)
        Create a JmriConnection that sends output to a DataOutputStream.
        Parameters:
        output - DataOutputStream to use
    • Method Detail

      • getSession

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

        public void sendMessage​(java.lang.String message)
                         throws java.io.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:
        java.io.IOException - if problem sending message
      • close

        public void close()
                   throws java.io.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:
        java.io.IOException - if problem closing connection
      • getLocale

        public java.util.Locale getLocale()
        Returns:
        the locale
      • setLocale

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