Package jmri.jmrit.z21server
Class ClientManager
java.lang.Object
jmri.jmrit.z21server.ClientManager
- All Implemented Interfaces:
EventListener,ThrottleListener
Register and unregister clients, set loco throttle
-
Nested Class Summary
Nested classes/interfaces inherited from interface jmri.ThrottleListener
ThrottleListener.DecisionType -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic ClientManagerReturn the one running instance of the client manager.byte[]getLocoStatusMessage(InetAddress address, Integer locoAddress) Return a Z21 LAN_X_LOCO_INFO packet for a given client and loco addressGet a hash map of the registered clients, indexed by their InetAddressbyte[]getTurnoutStatusMessage(InetAddress address, Integer turnoutNumber) Get a Z21 LAN_X_TURNOUT_INFO packet to be sent to the client fpr a given turnout number.voidhandleExpiredClients(boolean removeAll) Check all clients if they have not sent anything for a time peroid (60 seconds).voidheartbeat(InetAddress clientAddress) Send a heartbeat() to the AppClient instance.voidnotifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question) Called from the throttle manager to ask if the throttle should be shared or the previous should be disconnected.voidnotifyFailedThrottleRequest(LocoAddress address, String reason) Called from the throttle manager when no throttle can be created for a loco address.voidCalled from the throttle manager when a requested throttle for a given loco address was found.voidregisterLocoIfNeeded(InetAddress clientAddress, int locoAddress) Register a client if not already registered and add a throttle for the given loco address to the clients list of throttles.voidsetChangeListener(PropertyChangeListener changeListener) Set the throttle change listener.voidsetClientListener(PropertyChangeListener clientListener) Set the client change listener.voidsetLocoFunction(InetAddress clientAddress, int locoAddress, int functionNumber, int functionState) Set a JMRI throttle to new function state.voidsetLocoSpeedAndDirection(InetAddress clientAddress, int locoAddress, int speed, boolean forward) Set a JMRI throttle to new speed and direction.voidsetTurnout(InetAddress clientAddress, int turnoutNumber, boolean state) Set a JMRI component to new state.voidunregisterClient(InetAddress clientAddress) Unregister a client.static bytexor(byte[] packet) Helper to construct the Z21 protocol XOR byte
-
Field Details
-
speedMultiplier
-
-
Method Details
-
getInstance
Return the one running instance of the client manager. If there is no instance, create it.- Returns:
- the client manager instance
-
setChangeListener
Set the throttle change listener.- Parameters:
changeListener- - the property change listener instance
-
setClientListener
Set the client change listener. The listener is called if a new is registered or a registered client is unregistered.- Parameters:
clientListener- - the property change listener instance
-
getRegisteredClients
Get a hash map of the registered clients, indexed by their InetAddress- Returns:
- the hash map of registered clients
-
registerLocoIfNeeded
Register a client if not already registered and add a throttle for the given loco address to the clients list of throttles.- Parameters:
clientAddress- - InetAddress of the clientlocoAddress- - address of a loco
-
setLocoSpeedAndDirection
public void setLocoSpeedAndDirection(InetAddress clientAddress, int locoAddress, int speed, boolean forward) Set a JMRI throttle to new speed and direction. Called when a Z21 client's user changes speed and/or direction.- Parameters:
clientAddress- - the client's InetAddresslocoAddress- - the loco addressspeed- - the speed to setforward- - true of forward, false if reverse
-
setLocoFunction
public void setLocoFunction(InetAddress clientAddress, int locoAddress, int functionNumber, int functionState) Set a JMRI throttle to new function state. Called when a Z21 client's user changes function status.- Parameters:
clientAddress- - the client's InetAddresslocoAddress- - the loco addressfunctionNumber- - the function number to setfunctionState- - the new state of the function
-
getLocoStatusMessage
Return a Z21 LAN_X_LOCO_INFO packet for a given client and loco address- Parameters:
address- - client InetAddresslocoAddress- - the loco address- Returns:
- Z21 LAN_X_LOCO_INFO packet
-
setTurnout
Set a JMRI component to new state. The component may be a JMRI turnout, light, route, signal mast, signal head or sensor, depending on a property entry for the component containing the Z21 turnout number. Called when a Z21 client's user changes state of a turnout.- Parameters:
clientAddress- - client's InetAddressturnoutNumber- - the Z21 turnout number, starting from 1 as seen on the WlanMaus display (in the Z21 protocol turnouts start with 0).state- - true if turnout should be THROWN, false if CLOSED.
-
getTurnoutStatusMessage
Get a Z21 LAN_X_TURNOUT_INFO packet to be sent to the client fpr a given turnout number.- Parameters:
address- - client's InetAdressturnoutNumber- - the Z21 Turnout Number- Returns:
- a Z21 LAN_X_TURNOUT_INFO packet
-
heartbeat
Send a heartbeat() to the AppClient instance.- Parameters:
clientAddress- - the client's InetAdress
-
handleExpiredClients
Check all clients if they have not sent anything for a time peroid (60 seconds). If the client has expired, remove it from the list.- Parameters:
removeAll- - if true, remove all clients regardless of their expiry time.
-
unregisterClient
Unregister a client. Clean up the AppClient instance to remove listeners from throttles, Remove client from hash map, Call client listener to inform about removing the client- Parameters:
clientAddress- - client's InetAddress
-
notifyThrottleFound
Called from the throttle manager when a requested throttle for a given loco address was found. The thottle is then added to the list of throttles in the AppClient instance.- Specified by:
notifyThrottleFoundin interfaceThrottleListener- Parameters:
t- - the (new) throttle bound to the loco.
-
notifyFailedThrottleRequest
Called from the throttle manager when no throttle can be created for a loco address.- Specified by:
notifyFailedThrottleRequestin interfaceThrottleListener- Parameters:
address- - loco addressreason- - a message from the throttle manager
-
notifyDecisionRequired
Called from the throttle manager to ask if the throttle should be shared or the previous should be disconnected. For now, we always use shared throttles.- Specified by:
notifyDecisionRequiredin interfaceThrottleListener- Parameters:
address- - loco addressquestion- - STEAL, SHARE or both
-
xor
Helper to construct the Z21 protocol XOR byte- Parameters:
packet- - Z21 packet- Returns:
- the XOR byte
-