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 classLnThrottleManager.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) booleanrequestOutstanding(package private) java.lang.ThreadretrySetupThread(package private) java.util.Hashtable<java.lang.Integer,LocoNetSlot>slotForAddressprotected SlotManagerslotManagerprotected LnTrafficControllertcprotected intthrottleID(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 booleanaddressTypeUnique()Reports whether all loco addresses are uniquely long or short, without any ambiguity for any address.booleancanBeLongAddress(int address)Determines if the loco address is a long address.booleancanBeShortAddress(int address)Determines if the loco address is a short address.voidcancelThrottleRequest(LocoAddress address, ThrottleListener l)Cancel a request for a throttle.(package private) DccThrottlecreateThrottle(LocoNetSystemConnectionMemo memo, LocoNetSlot s)Create a LocoNet Throttle to control a loco.voiddispatchThrottle(DccThrottle t, ThrottleListener l)Dispatches a loco from a LnThrottle object.voiddispose()Allow to cleanly release the traffic controller in ThrottleManager Tests remove listeners, if any stop timers, is anybooleandisposeThrottle(DccThrottle t, ThrottleListener l)Disposes a LnThrottle object.booleanenablePrefSilentStealOption()Display the Silent Stealing checkbox option in Throttles PreferencesvoidfailedThrottleRequest(LocoAddress address, java.lang.String reason)Cancels the loco acquisition process when throttle acquisition of a loco fails.intgetThrottleID()Get the ThrottleID value for this throttle.booleanhasDispatchFunction()LocoNet does have a Dispatch function.protected static booleanisLongAddress(int num)Local method for deciding short/long address.voidnotifyChangedSlot(LocoNetSlot s)Get notification that an address has changed slot.protected voidnotifyComplete(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.voidnotifyRefused(int address, java.lang.String cause)Loco acquisition failed.voidnotifyStealRequest(int locoAddr)Inform the requesting throttle object (not the connection-specific throttle implementation!)protected voidprocessQueuedThrottleSetupRequest()Processes the next loco from the queue of requested locos for which to get a LocoNetThrottle.voidreleaseThrottle(DccThrottle t, ThrottleListener l)Dispatch a loco from a LnThrottle object.voidrequestThrottleSetup(LocoAddress address, boolean control)Start creating a Throttle object.voidresponseThrottleDecision(LocoAddress address, ThrottleListener l, ThrottleListener.DecisionType decision)Perform the actual "Steal" of the requested throttle.protected booleansingleUse()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:
singleUsein classAbstractThrottleManager- Returns:
- false always
-
enablePrefSilentStealOption
public boolean enablePrefSilentStealOption()
Display the Silent Stealing checkbox option in Throttles Preferences- Specified by:
enablePrefSilentStealOptionin interfaceThrottleManager- Overrides:
enablePrefSilentStealOptionin 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:
requestThrottleSetupin 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:
hasDispatchFunctionin interfaceThrottleManager- Overrides:
hasDispatchFunctionin 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:
supportedSpeedModesin interfaceThrottleManager- Overrides:
supportedSpeedModesin 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:
notifyChangedSlotin 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:
canBeLongAddressin 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:
canBeShortAddressin 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:
addressTypeUniquein 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:
disposeThrottlein interfaceThrottleManager- Overrides:
disposeThrottlein 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:
dispatchThrottlein interfaceThrottleManager- Overrides:
dispatchThrottlein 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:
releaseThrottlein interfaceThrottleManager- Overrides:
releaseThrottlein 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:
failedThrottleRequestin 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:
cancelThrottleRequestin interfaceThrottleManager- Overrides:
cancelThrottleRequestin 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:
disposein interfaceThrottleManager- Overrides:
disposein 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:
responseThrottleDecisionin interfaceThrottleManager- Overrides:
responseThrottleDecisionin classAbstractThrottleManager- Parameters:
address- desired DccLocoAddressdecision- made by the ThrottleListener, only listening for STEALl- The ThrottleListener which has made the decision- Since:
- 4.9.2
-
-