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.String
CLIENTS
Used to notify clients of the number of clients controlling the same throttle.static java.lang.String
ESTOP
"eStop"static java.lang.String
IDLE
"idle"static java.lang.String
RELEASE
"release"static java.lang.String
SPEED_STEPS
"speedSteps"static java.lang.String
THROTTLE
Token for type for throttle status messages.
-
Constructor Summary
Constructors Modifier Constructor Description protected
JsonThrottle(DccLocoAddress address, JsonThrottleSocketService server)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close(JsonThrottleSocketService server, boolean notifyClient)
(package private) Throttle
getThrottle()
Get the Throttle this JsonThrottle is a proxy for.static JsonThrottle
getThrottle(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.void
notifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question)
No steal or share decisions made locallyvoid
notifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)
Get notification that an attempt to request a throttle has failed.void
notifyThrottleFound(DccThrottle throttle)
Get notification that a throttle has been found as requested.void
onMessage(java.util.Locale locale, com.fasterxml.jackson.databind.JsonNode data, JsonThrottleSocketService server)
void
propertyChange(java.beans.PropertyChangeEvent evt)
void
release(JsonThrottleSocketService server, boolean notifyClient)
void
sendMessage(com.fasterxml.jackson.databind.node.ObjectNode data)
void
sendMessage(com.fasterxml.jackson.databind.node.ObjectNode data, JsonThrottleSocketService server)
protected void
sendStatus(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.ID
node containing the ID of aRosterEntry
or an integerJSON.ADDRESS
node. If data contains an ADDRESS, the ID node is ignored. The ADDRESS may be accompanied by a booleanJSON.IS_LONG_ADDRESS
node 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:
propertyChange
in interfacejava.beans.PropertyChangeListener
-
notifyThrottleFound
public void notifyThrottleFound(DccThrottle throttle)
Description copied from interface:ThrottleListener
Get notification that a throttle has been found as requested.- Specified by:
notifyThrottleFound
in interfaceThrottleListener
- Parameters:
throttle
- the throttle with the requested address
-
notifyFailedThrottleRequest
public void notifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)
Description copied from interface:ThrottleListener
Get notification that an attempt to request a throttle has failed.- Specified by:
notifyFailedThrottleRequest
in 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:
notifyDecisionRequired
in 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
-
-