Package jmri.jmrix

Class ConnectionStatus


  • public class ConnectionStatus
    extends java.lang.Object
    Interface for classes that wish to get notification when the connection to the layout changes.

    Maintains a single instance, as there is only one set of connections for the running program.

    The "system name" referred to here is the human-readable name like "LocoNet 2" which can be obtained from i.e. SystemConnectionMemo.getUserName(). Not clear whether ConnectionConfig.getConnectionName() is correct. It's not intended to be the prefix from i.e. PortAdapter.getSystemPrefix(). Maybe the right thing is to pass in the SystemConnectionMemo?

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addConnection​(java.lang.String systemName, java.lang.String portName)
      Add a connection with a given name and port name to the portStatus set if not yet present in the set.
      void addPropertyChangeListener​(java.beans.PropertyChangeListener l)  
      protected void firePropertyChange​(java.lang.String p, java.lang.Object old, java.lang.Object n)  
      java.lang.String getConnectionState​(java.lang.String systemName, java.lang.String portName)
      Get the status of a communication port with a given name.
      java.lang.String getSystemState​(java.lang.String systemName)
      Get the status of a communication port, based on the system name only.
      static ConnectionStatus instance()  
      boolean isConnectionOk​(java.lang.String systemName, java.lang.String portName)
      Confirm status of a communication port is not down.
      boolean isSystemOk​(java.lang.String systemName)
      Confirm status of a communication port is not down, based on the system name.
      void removePropertyChangeListener​(java.beans.PropertyChangeListener l)  
      void setConnectionState​(java.lang.String systemName, java.lang.String portName, java.lang.String state)
      Set the connection state of a communication port.
      • Methods inherited from class java.lang.Object

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

      • addConnection

        public void addConnection​(java.lang.String systemName,
                                  @Nonnull
                                  java.lang.String portName)
        Add a connection with a given name and port name to the portStatus set if not yet present in the set.
        Parameters:
        systemName - human-readable name for system like "LocoNet 2" which can be obtained from i.e. SystemConnectionMemo.getUserName().
        portName - the port name
      • setConnectionState

        public void setConnectionState​(java.lang.String systemName,
                                       @Nonnull
                                       java.lang.String portName,
                                       @Nonnull
                                       java.lang.String state)
        Set the connection state of a communication port.
        Parameters:
        systemName - human-readable name for system like "LocoNet 2" which can be obtained from i.e. SystemConnectionMemo.getUserName().
        portName - the port name
        state - one of ConnectionStatus.UP, ConnectionStatus.DOWN, or ConnectionStatus.UNKNOWN.
      • getConnectionState

        public java.lang.String getConnectionState​(java.lang.String systemName,
                                                   @Nonnull
                                                   java.lang.String portName)
        Get the status of a communication port with a given name.
        Parameters:
        systemName - human-readable name for system like "LocoNet 2" which can be obtained from i.e. SystemConnectionMemo.getUserName().
        portName - the port name
        Returns:
        the status
      • getSystemState

        public java.lang.String getSystemState​(@Nonnull
                                               java.lang.String systemName)
        Get the status of a communication port, based on the system name only.
        Parameters:
        systemName - human-readable name for system like "LocoNet 2" which can be obtained from i.e. SystemConnectionMemo.getUserName().
        Returns:
        the status
      • isConnectionOk

        public boolean isConnectionOk​(java.lang.String systemName,
                                      @Nonnull
                                      java.lang.String portName)
        Confirm status of a communication port is not down.
        Parameters:
        systemName - human-readable name for system like "LocoNet 2" which can be obtained from i.e. SystemConnectionMemo.getUserName().
        portName - the port name
        Returns:
        true if port connection is operational or unknown, false if not
      • isSystemOk

        public boolean isSystemOk​(@Nonnull
                                  java.lang.String systemName)
        Confirm status of a communication port is not down, based on the system name.
        Parameters:
        systemName - human-readable name for system like "LocoNet 2" which can be obtained from i.e. SystemConnectionMemo.getUserName().
        Returns:
        true if port connection is operational or unknown, false if not. This includes returning true if the connection is not recognized.
      • firePropertyChange

        protected void firePropertyChange​(@Nonnull
                                          java.lang.String p,
                                          java.lang.Object old,
                                          java.lang.Object n)