Class AppClient

  • All Implemented Interfaces:
    java.beans.PropertyChangeListener, java.util.EventListener

    public class AppClient
    extends java.lang.Object
    implements java.beans.PropertyChangeListener
    This class represents a connected and registered client, e.g. a Z21 app or a WlanMaus JMRI throttles a bound to this client.
    • Constructor Detail

      • AppClient

        public AppClient​(java.net.InetAddress address,
                         java.beans.PropertyChangeListener changeListener)
        Constructor.
        Parameters:
        address - of the connected client
        changeListener - to be called if one of the throttles has changed
    • Method Detail

      • addThrottle

        public void addThrottle​(int locoAddress,
                                DccThrottle throttle)
        Add a throttle to the clients list of throttles. The throttle instance is created by the caller.
        Parameters:
        locoAddress - - the loco address
        throttle - - the throttle to be added
      • getActiveRosterIdString

        public java.lang.String getActiveRosterIdString()
        Get the roster ID for the last used throttle
        Returns:
        roster ID as String
      • clear

        public void clear()
        Remove the listener from all throttles and clear the list of throttles.
      • getThrottleFromLocoAddress

        public DccThrottle getThrottleFromLocoAddress​(int locoAddress)
        Get a throttle by loco address
        Parameters:
        locoAddress - - the loco address
        Returns:
        the throttle
      • getAddress

        public java.net.InetAddress getAddress()
        Get clients IP address
        Returns:
        the InetAddress
      • heartbeat

        public void heartbeat()
        The heartbeat for client expire
      • isTimestampExpired

        public boolean isTimestampExpired()
        Check if the client has not been seen (see heartbeat()) for at least 60 seconds.
        Returns:
        true if not seen for more than 60 seconds
      • getLocoStatusMessage

        public byte[] getLocoStatusMessage​(java.lang.Integer locoAddress)
        Return a Z21 LAN_X_LOCO_INFO packet for a given loco address
        Parameters:
        locoAddress - - the loco address
        Returns:
        Z21 LAN_X_LOCO_INFO packet
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent pce)
        Listener for throttle events. Will call the changeListener (in MainServer) with the Z21 LAN_X_LOCO_INFO packet as new value.
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
        Parameters:
        pce - - throttle change event
      • findRosterEntry

        public static RosterEntry findRosterEntry​(DccThrottle t)
        Find the roster entry from a given throttle instance.
        Parameters:
        t - - the throttle instance
        Returns:
        the roster entry