Package jmri.server.json.throttle
Class JsonThrottle
- java.lang.Object
-
- jmri.server.json.throttle.JsonThrottle
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener,java.util.EventListener,ThrottleListener
public class JsonThrottle extends java.lang.Object implements ThrottleListener, java.beans.PropertyChangeListener
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.ThrottleListener
ThrottleListener.DecisionType
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCLIENTSUsed to notify clients of the number of clients controlling the same throttle.static java.lang.StringESTOP"eStop"static java.lang.StringIDLE"idle"static java.lang.StringRELEASE"release"static java.lang.StringSPEED_STEPS"speedSteps"static java.lang.StringTHROTTLEToken for type for throttle status messages.
-
Constructor Summary
Constructors Modifier Constructor Description protectedJsonThrottle(DccLocoAddress address, JsonThrottleSocketService server)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose(JsonThrottleSocketService server, boolean notifyClient)(package private) ThrottlegetThrottle()Get the Throttle this JsonThrottle is a proxy for.static JsonThrottlegetThrottle(java.lang.String throttleId, com.fasterxml.jackson.databind.JsonNode data, JsonThrottleSocketService server, int id)Creates a new JsonThrottle or returns an existing one if the request is for an existing throttle.voidnotifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question)No steal or share decisions made locallyvoidnotifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)Get notification that an attempt to request a throttle has failed.voidnotifyThrottleFound(DccThrottle throttle)Get notification that a throttle has been found as requested.voidonMessage(java.util.Locale locale, com.fasterxml.jackson.databind.JsonNode data, JsonThrottleSocketService server)voidpropertyChange(java.beans.PropertyChangeEvent evt)voidrelease(JsonThrottleSocketService server, boolean notifyClient)voidsendMessage(com.fasterxml.jackson.databind.node.ObjectNode data)voidsendMessage(com.fasterxml.jackson.databind.node.ObjectNode data, JsonThrottleSocketService server)protected voidsendStatus(JsonThrottleSocketService server)
-
-
-
Field Detail
-
THROTTLE
public static final java.lang.String THROTTLE
Token for type for throttle status messages."throttle"
- See Also:
- Constant Field Values
-
RELEASE
public static final java.lang.String RELEASE
"release"- See Also:
- Constant Field Values
-
ESTOP
public static final java.lang.String ESTOP
"eStop"- See Also:
- Constant Field Values
-
IDLE
public static final java.lang.String IDLE
"idle"- See Also:
- Constant Field Values
-
SPEED_STEPS
public static final java.lang.String SPEED_STEPS
"speedSteps"- See Also:
- Constant Field Values
-
CLIENTS
public static final java.lang.String CLIENTS
Used to notify clients of the number of clients controlling the same throttle."clients"
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JsonThrottle
protected JsonThrottle(DccLocoAddress address, JsonThrottleSocketService server)
-
-
Method Detail
-
getThrottle
public static JsonThrottle getThrottle(java.lang.String throttleId, com.fasterxml.jackson.databind.JsonNode data, JsonThrottleSocketService server, int id) throws JsonException
Creates a new JsonThrottle or returns an existing one if the request is for an existing throttle.data can contain either a string
JSON.IDnode containing the ID of aRosterEntryor an integerJSON.ADDRESSnode. If data contains an ADDRESS, the ID node is ignored. The ADDRESS may be accompanied by a booleanJSON.IS_LONG_ADDRESSnode specifying the type of address, if IS_LONG_ADDRESS is not specified, the inverse ofThrottleManager.canBeShortAddress(int)is used as the "best guess" of the address length.- Parameters:
throttleId- The client's identity token for this throttledata- JSON object containing either an ADDRESS or an IDserver- The server requesting this throttle on behalf of a clientid- message id set by client- Returns:
- The throttle
- Throws:
JsonException- if unable to get the requestedThrottle
-
close
public void close(JsonThrottleSocketService server, boolean notifyClient)
-
release
public void release(JsonThrottleSocketService server, boolean notifyClient)
-
onMessage
public void onMessage(java.util.Locale locale, com.fasterxml.jackson.databind.JsonNode data, JsonThrottleSocketService server)
-
sendMessage
public void sendMessage(com.fasterxml.jackson.databind.node.ObjectNode data)
-
sendMessage
public void sendMessage(com.fasterxml.jackson.databind.node.ObjectNode data, JsonThrottleSocketService server)
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
-
notifyThrottleFound
public void notifyThrottleFound(DccThrottle throttle)
Description copied from interface:ThrottleListenerGet notification that a throttle has been found as requested.- Specified by:
notifyThrottleFoundin interfaceThrottleListener- Parameters:
throttle- the throttle with the requested address
-
notifyFailedThrottleRequest
public void notifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)
Description copied from interface:ThrottleListenerGet notification that an attempt to request a throttle has failed.- Specified by:
notifyFailedThrottleRequestin interfaceThrottleListener- Parameters:
address- address of the failed requestreason- failure cause
-
notifyDecisionRequired
public void notifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question)
No steal or share decisions made locallyGet notification that a throttle request is in use by another device, and a "steal", "share", or "steal/share" decision may be required.
- Specified by:
notifyDecisionRequiredin interfaceThrottleListener- Parameters:
address- The LocoAddress that needs the decision.question- The question being asked, steal / cancel, share / cancel, steal / share / cancel
-
sendStatus
protected void sendStatus(JsonThrottleSocketService server)
-
getThrottle
Throttle getThrottle()
Get the Throttle this JsonThrottle is a proxy for.- Returns:
- the throttle or null if no throttle is set
-
-