Class LnThrottleManager
- java.lang.Object
-
- jmri.jmrix.AbstractThrottleManager
-
- jmri.jmrix.loconet.LnThrottleManager
-
- All Implemented Interfaces:
java.util.EventListener
,SlotListener
,ThrottleManager
- Direct Known Subclasses:
Ib1ThrottleManager
,Ib2ThrottleManager
,UhlenbrockLnThrottleManager
public class LnThrottleManager extends AbstractThrottleManager implements SlotListener
LocoNet implementation of a ThrottleManager.Works in cooperation with the SlotManager, which actually handles the communications.
- See Also:
SlotManager
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
LnThrottleManager.ThrottleRequest
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractThrottleManager
AbstractThrottleManager.Addresses
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.concurrent.LinkedBlockingQueue<LnThrottleManager.ThrottleRequest>
requestList
(package private) boolean
requestOutstanding
(package private) java.lang.Thread
retrySetupThread
(package private) java.util.Hashtable<java.lang.Integer,LocoNetSlot>
slotForAddress
protected SlotManager
slotManager
protected LnTrafficController
tc
protected int
throttleID
(package private) java.util.Hashtable<java.lang.Integer,java.lang.Thread>
waitingForNotification
-
Fields inherited from class jmri.jmrix.AbstractThrottleManager
adapterMemo, userName
-
-
Constructor Summary
Constructors Constructor Description LnThrottleManager(LocoNetSystemConnectionMemo memo)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addressTypeUnique()
Reports whether all loco addresses are uniquely long or short, without any ambiguity for any address.boolean
canBeLongAddress(int address)
Determines if the loco address is a long address.boolean
canBeShortAddress(int address)
Determines if the loco address is a short address.void
cancelThrottleRequest(LocoAddress address, ThrottleListener l)
Cancel a request for a throttle.(package private) DccThrottle
createThrottle(LocoNetSystemConnectionMemo memo, LocoNetSlot s)
Create a LocoNet Throttle to control a loco.void
dispatchThrottle(DccThrottle t, ThrottleListener l)
Dispatches a loco from a LnThrottle object.void
dispose()
Allow to cleanly release the traffic controller in ThrottleManager Tests remove listeners, if any stop timers, is anyboolean
disposeThrottle(DccThrottle t, ThrottleListener l)
Disposes a LnThrottle object.boolean
enablePrefSilentStealOption()
Display the Silent Stealing checkbox option in Throttles Preferencesvoid
failedThrottleRequest(LocoAddress address, java.lang.String reason)
Cancels the loco acquisition process when throttle acquisition of a loco fails.int
getThrottleID()
Get the ThrottleID value for this throttle.boolean
hasDispatchFunction()
LocoNet does have a Dispatch function.protected static boolean
isLongAddress(int num)
Local method for deciding short/long address.void
notifyChangedSlot(LocoNetSlot s)
Get notification that an address has changed slot.protected void
notifyComplete(DccThrottle t, LocoNetSlot s)
Called from the throttle slot when the final write of throttle id has been completed, and the slot is set as initialized, or called directly for our own shared throttles.void
notifyRefused(int address, java.lang.String cause)
Loco acquisition failed.void
notifyStealRequest(int locoAddr)
Inform the requesting throttle object (not the connection-specific throttle implementation!)protected void
processQueuedThrottleSetupRequest()
Processes the next loco from the queue of requested locos for which to get a LocoNetThrottle.void
releaseThrottle(DccThrottle t, ThrottleListener l)
Dispatch a loco from a LnThrottle object.void
requestThrottleSetup(LocoAddress address, boolean control)
Start creating a Throttle object.void
responseThrottleDecision(LocoAddress address, ThrottleListener l, ThrottleListener.DecisionType decision)
Perform the actual "Steal" of the requested throttle.protected boolean
singleUse()
LocoNet allows multiple throttles for the same device.java.util.EnumSet<SpeedStepMode>
supportedSpeedModes()
What speed modes are supported by this system?-
Methods inherited from class jmri.jmrix.AbstractThrottleManager
addressReleased, addressStillRequired, addressStillRequired, addressStillRequired, addressStillRequired, attachListener, cancelThrottleRequest, cancelThrottleRequest, cancelThrottleRequest, enablePrefSilentShareOption, forceDisposeThrottle, getAddress, getAddress, getAddressProtocolTypes, getAddressTypes, getAddressTypeString, getProtocolFromString, getThrottleInfo, getThrottleUsageCount, getThrottleUsageCount, getThrottleUsageCount, getThrottleUsageCount, getUserName, hideStealNotifications, makeHardwareDecision, notifyDecisionRequest, notifyThrottleKnown, removeListener, requestThrottle, requestThrottle, requestThrottle, requestThrottle, requestThrottle, requestThrottle, requestThrottleSetup, responseThrottleDecision, responseThrottleDecision, showSessionCancelDialogue, updateNumUsers
-
-
-
-
Field Detail
-
slotManager
protected SlotManager slotManager
-
tc
protected LnTrafficController tc
-
retrySetupThread
volatile java.lang.Thread retrySetupThread
-
waitingForNotification
java.util.Hashtable<java.lang.Integer,java.lang.Thread> waitingForNotification
-
slotForAddress
java.util.Hashtable<java.lang.Integer,LocoNetSlot> slotForAddress
-
requestList
java.util.concurrent.LinkedBlockingQueue<LnThrottleManager.ThrottleRequest> requestList
-
requestOutstanding
boolean requestOutstanding
-
throttleID
protected int throttleID
-
-
Constructor Detail
-
LnThrottleManager
public LnThrottleManager(LocoNetSystemConnectionMemo memo)
Constructor. Gets a reference to the LocoNet SlotManager.- Parameters:
memo
- connection's memo
-
-
Method Detail
-
singleUse
protected boolean singleUse()
LocoNet allows multiple throttles for the same device.Does this DCC system allow a Throttle (e.g. an address) to be used by only one user at a time?
- Overrides:
singleUse
in classAbstractThrottleManager
- Returns:
- false always
-
enablePrefSilentStealOption
public boolean enablePrefSilentStealOption()
Display the Silent Stealing checkbox option in Throttles Preferences- Specified by:
enablePrefSilentStealOption
in interfaceThrottleManager
- Overrides:
enablePrefSilentStealOption
in classAbstractThrottleManager
- Returns:
- true if steal is possible; false otherwise
-
requestThrottleSetup
public void requestThrottleSetup(LocoAddress address, boolean control)
Start creating a Throttle object. This returns directly, having arranged for the Throttle object to be delivered via callback since there are situations where the command station does not respond, (slots full, command station powered off, others?) this code will retry and then fail the request if no response occurs.- Specified by:
requestThrottleSetup
in classAbstractThrottleManager
- Parameters:
address
- locomotive address to be controlledcontrol
- true if throttle wishes to control the speed and direction of the loco.
-
processQueuedThrottleSetupRequest
protected void processQueuedThrottleSetupRequest()
Processes the next loco from the queue of requested locos for which to get a LocoNetThrottle.
-
hasDispatchFunction
public boolean hasDispatchFunction()
LocoNet does have a Dispatch function.- Specified by:
hasDispatchFunction
in interfaceThrottleManager
- Overrides:
hasDispatchFunction
in classAbstractThrottleManager
- Returns:
- true
-
supportedSpeedModes
public java.util.EnumSet<SpeedStepMode> supportedSpeedModes()
What speed modes are supported by this system? value should be xor of possible modes specified by the DccThrottle interface.- Specified by:
supportedSpeedModes
in interfaceThrottleManager
- Overrides:
supportedSpeedModes
in classAbstractThrottleManager
- Returns:
- an integer containing the combined speed step modes supported
-
notifyChangedSlot
public void notifyChangedSlot(LocoNetSlot s)
Get notification that an address has changed slot. This method creates a throttle for all ThrottleListeners of that address and notifies them via the ThrottleListener.notifyThrottleFound method.- Specified by:
notifyChangedSlot
in interfaceSlotListener
- Parameters:
s
- LocoNet slot which has been changed
-
notifyComplete
protected void notifyComplete(DccThrottle t, LocoNetSlot s)
Called from the throttle slot when the final write of throttle id has been completed, and the slot is set as initialized, or called directly for our own shared throttles.- Parameters:
t
- the throttles
- the lot.
-
notifyRefused
public void notifyRefused(int address, java.lang.String cause)
Loco acquisition failed. Propagate the failure message to the (GUI) throttle.- Parameters:
address
- of the loco which could not be acquiredcause
- reason for the failure
-
createThrottle
DccThrottle createThrottle(LocoNetSystemConnectionMemo memo, LocoNetSlot s)
Create a LocoNet Throttle to control a loco.This is called during the loco acquisition process by logic within LnThrottleManager. Generally, it should not be directly called by other methods.
- Parameters:
memo
- connection memo used by the throttle for communicationss
- slot holding an acquired loco- Returns:
- throttle holding an acquired loco
-
canBeLongAddress
public boolean canBeLongAddress(int address)
Determines if the loco address is a long address.For LocoNet, address 128 and above is a long address.
- Specified by:
canBeLongAddress
in interfaceThrottleManager
- Parameters:
address
- to be checked- Returns:
- true if long address, else false
-
canBeShortAddress
public boolean canBeShortAddress(int address)
Determines if the loco address is a short address.For LocoNet, address 127 and below is a short address
- Specified by:
canBeShortAddress
in interfaceThrottleManager
- Parameters:
address
- to be checked- Returns:
- true if short address, else false
-
addressTypeUnique
public boolean addressTypeUnique()
Reports whether all loco addresses are uniquely long or short, without any ambiguity for any address.For LocoNet, there are no ambiguous addresses.
- Specified by:
addressTypeUnique
in interfaceThrottleManager
- Returns:
- true
-
isLongAddress
protected static boolean isLongAddress(int num)
Local method for deciding short/long address.- Parameters:
num
- address to be checked- Returns:
- true if num is a long address else false
-
disposeThrottle
public boolean disposeThrottle(DccThrottle t, ThrottleListener l)
Disposes a LnThrottle object.Generally, this will cause the slot to be made "common" and the LnThrottle is disposed of.
After disposal, the throttle may not be used to control the loco.
- Specified by:
disposeThrottle
in interfaceThrottleManager
- Overrides:
disposeThrottle
in classAbstractThrottleManager
- Parameters:
t
- is a throttle to be disposed ofl
- is the listener for the throttle- Returns:
- false if throttle is not a LocoNetThrottle, else true
-
dispatchThrottle
public void dispatchThrottle(DccThrottle t, ThrottleListener l)
Dispatches a loco from a LnThrottle object.Generally, this will cause the slot to be made "common" and then linked via the "Dispatch" slot.
After dispatching, the throttle may not be used to control the loco. You should check getUsageCountBefore calling as it will fail if not 1.
- Specified by:
dispatchThrottle
in interfaceThrottleManager
- Overrides:
dispatchThrottle
in classAbstractThrottleManager
- Parameters:
t
- is a throttle to be disposed ofl
- is the listener for the throttle
-
releaseThrottle
public void releaseThrottle(DccThrottle t, ThrottleListener l)
Dispatch a loco from a LnThrottle object.Generally, this will cause the slot to be made "common".
After disposal, the throttle may not be used to control the loco.
- Specified by:
releaseThrottle
in interfaceThrottleManager
- Overrides:
releaseThrottle
in classAbstractThrottleManager
- Parameters:
t
- is a throttle to be disposed ofl
- is the listener for the throttle
-
failedThrottleRequest
public void failedThrottleRequest(LocoAddress address, java.lang.String reason)
Cancels the loco acquisition process when throttle acquisition of a loco fails.- Overrides:
failedThrottleRequest
in classAbstractThrottleManager
- Parameters:
address
- loco address which could not be acquiredreason
- for the failure
-
cancelThrottleRequest
public void cancelThrottleRequest(LocoAddress address, ThrottleListener l)
Cancel a request for a throttle.- Specified by:
cancelThrottleRequest
in interfaceThrottleManager
- Overrides:
cancelThrottleRequest
in classAbstractThrottleManager
- Parameters:
address
- The decoder address desired. address.l
- The ThrottleListener cancelling request for a throttle.
-
getThrottleID
public int getThrottleID()
Get the ThrottleID value for this throttle.- Returns:
- the ThrottleID value
-
dispose
public void dispose()
Allow to cleanly release the traffic controller in ThrottleManager Tests- remove listeners, if any
- stop timers, is any
- Specified by:
dispose
in interfaceThrottleManager
- Overrides:
dispose
in classAbstractThrottleManager
-
notifyStealRequest
public void notifyStealRequest(int locoAddr)
Inform the requesting throttle object (not the connection-specific throttle implementation!) that the address is in-use and the throttle user may either choose to "steal" the address, or quit the acquisition process. The LocoNet acquisition process "retry" timer is stopped as part of this process, since a positive response has been received from the command station and since user intervention is required. Reminder: for LocoNet throttles which are not using "expanded slot" functionality, "steal" really means "share". For those LocoNet throttles which are using "expanded slots", "steal" really means take control and let the command station issue a "StealZap" LocoNet message to the other throttle.- Parameters:
locoAddr
- address of DCC loco or consist
-
responseThrottleDecision
public void responseThrottleDecision(LocoAddress address, ThrottleListener l, ThrottleListener.DecisionType decision)
Perform the actual "Steal" of the requested throttle.This is a call-back, as a result of the throttle user's agreement to "steal" the locomotive.
Reminder: for LocoNet throttles which are not using "expanded slot" functionality, "steal" really means "share". For those LocoNet throttles which are using "expanded slots", "steal" really means "force any other throttle running that address to drop the loco".
- Specified by:
responseThrottleDecision
in interfaceThrottleManager
- Overrides:
responseThrottleDecision
in classAbstractThrottleManager
- Parameters:
address
- desired DccLocoAddressdecision
- made by the ThrottleListener, only listening for STEALl
- The ThrottleListener which has made the decision- Since:
- 4.9.2
-
-