Package jmri.jmrit.z21server
Class AppClient
- java.lang.Object
-
- jmri.jmrit.z21server.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 Summary
Constructors Constructor Description AppClient(java.net.InetAddress address, java.beans.PropertyChangeListener changeListener)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddThrottle(int locoAddress, DccThrottle throttle)Add a throttle to the clients list of throttles.voidclear()Remove the listener from all throttles and clear the list of throttles.static RosterEntryfindRosterEntry(DccThrottle t)Find the roster entry from a given throttle instance.java.lang.StringgetActiveRosterIdString()Get the roster ID for the last used throttleDccThrottlegetActiveThrottle()Get the last used throttlejava.net.InetAddressgetAddress()Get clients IP addressbyte[]getLocoStatusMessage(java.lang.Integer locoAddress)Return a Z21 LAN_X_LOCO_INFO packet for a given loco addressDccThrottlegetThrottleFromLocoAddress(int locoAddress)Get a throttle by loco addressvoidheartbeat()The heartbeat for client expirebooleanisTimestampExpired()Check if the client has not been seen (see heartbeat()) for at least 60 seconds.voidpropertyChange(java.beans.PropertyChangeEvent pce)Listener for throttle events.voidsetActiveThrottle(DccThrottle t)Set last used throttle
-
-
-
Constructor Detail
-
AppClient
public AppClient(java.net.InetAddress address, java.beans.PropertyChangeListener changeListener)
Constructor.- Parameters:
address- of the connected clientchangeListener- 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 addressthrottle- - the throttle to be added
-
getActiveThrottle
public DccThrottle getActiveThrottle()
Get the last used throttle- Returns:
- last used throttle
-
getActiveRosterIdString
public java.lang.String getActiveRosterIdString()
Get the roster ID for the last used throttle- Returns:
- roster ID as String
-
setActiveThrottle
public void setActiveThrottle(DccThrottle t)
Set last used throttle- Parameters:
t- is the throttle
-
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:
propertyChangein interfacejava.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
-
-