Class AbstractThrottleManager
- All Implemented Interfaces:
ThrottleManager
- Direct Known Subclasses:
BiDiBThrottleManager,CbusThrottleManager,DCCppThrottleManager,DebugThrottleManager,EasyDccThrottleManager,EcosDccThrottleManager,LnPr2ThrottleManager,LnThrottleManager,MarklinThrottleManager,MqttThrottleManager,MrcThrottleManager,Mx1ThrottleManager,NceThrottleManager,OlcbThrottleManager,SerialThrottleManager,SprogCSThrottleManager,SprogThrottleManager,SRCPThrottleManager,TamsThrottleManager,ThrottleManager,XNetThrottleManager,XpaThrottleManager
Based on Glen Oberhauser's original LnThrottleManager implementation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classThis subClass keeps track of which loco address have been requested and by whom.(package private) static class -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanRelease a Throttle from a ThrottleListener.booleanaddressStillRequired(int address) booleanaddressStillRequired(int address, boolean isLongAddress) booleanbooleanvoidAttach a PropertyChangeListener to a specific loco address, where the requesting code does not need or require control over the loco.voidcancelThrottleRequest(int address, boolean isLong, ThrottleListener l) Cancel a request for a throttle.voidcancelThrottleRequest(int address, ThrottleListener l) Cancel a request for a throttle.voidCancel a request for a throttle.voidCancel a request for a throttle.voidThe throttle listener has finished with the specific Throttle and is is available for reuse/reallocation by somebody else.voiddispose()Allow to cleanly release the traffic controller in ThrottleManager Tests remove listeners, if any stop timers, is anybooleanNot for general use, seereleaseThrottleanddispatchThrottle.booleanHardware that uses the Silent Share preference will need to override Test if the Silent Share Throttles preference option should be enabled.booleanHardware that uses the Silent Steal preference will need to override Test if the Silent Steal Throttles preference option should be enabled.voidfailedThrottleRequest(LocoAddress address, String reason) If the system-specific ThrottleManager has been unable to create the DCC throttle then it needs to be removed from the throttleListeners, otherwise any subsequent request for that address results in the address being reported as already in use, if singleUse is set.protected voidThrottle can no longer be relied upon, potentially from an external forced steal or hardware error.getAddress(String value, String protocol) Get the object representing a particular address.getAddress(String value, LocoAddress.Protocol protocol) Get the object representing a particular address.Get a list of different protocols supported by the system, to include short vs long or DCC vs Selectrix vs Motorola.String[]By default, only DCC in this implementationBy default, only DCC in this implementationgetProtocolFromString(String selection) Get a protocol given a description.getThrottleInfo(LocoAddress la, String item) Provides a Proxy method to return the SpeedSetting, Direction, Function Settings, of a throttle, where the requesting code has usedattachListenerto only be notified of changes in the throttle and not control it.intgetThrottleUsageCount(int address) Get the number of Throttles sharing the throttle for a ddcaddress.intgetThrottleUsageCount(int address, boolean isLongAddress) Get the number of Throttles sharing the throttle for a ddcaddress.intGet the number of Throttles sharing the throttle for a ddcaddress.intGet the number of Throttles sharing the throttle for a ddcaddress.Get the user name of the system that the programmer is associated with.booleanCheck to see if the Dispatch Button should be enabled or not Default to true, override if necessaryvoidhideStealNotifications(boolean hide) Receive notification from a throttle dialogue to display steal dialogues for rest of the JMRI instance session.protected voidmakeHardwareDecision(LocoAddress address, ThrottleListener.DecisionType question) For when a steal / share decision is needed and the ThrottleListener has delegated this decision to the ThrottleManager.protected voidnotifyDecisionRequest(LocoAddress address, ThrottleListener.DecisionType question) When the system-specific ThrottleManager has been unable to create the DCC throttle because it is already in use and must be "stolen" or "shared" to take control, it needs to notify the listener of this situation.voidnotifyThrottleKnown(DccThrottle throttle, LocoAddress addr) Handle throttle information when it's finally available, e.g. when a new Throttle object has been created.voidThe specified Throttle Listener has finished using a given throttle and no longer requires access to it.voidRemove a PropertyChangeListener to a specific loco address, where the requesting code has usedattachListenerto get notification of changes in a throttle.booleanrequestThrottle(int address, boolean isLongAddress, ThrottleListener l, boolean canHandleDecisions) Request a throttle, given a decoder address and whether it is a long or short DCC address.booleanrequestThrottle(int address, ThrottleListener l) Request Throttle with no Steal / Share Callbacks Request a throttle, given a decoder address.booleanrequestThrottle(int address, ThrottleListener l, boolean canHandleDecisions) Request a throttle, given a decoder address.booleanrequestThrottle(BasicRosterEntry re, ThrottleListener l, boolean canHandleDecisions) Request a throttle from a given RosterEntry.protected booleanrequestThrottle(LocoAddress la, BasicRosterEntry re, ThrottleListener l, boolean canHandleDecisions) Request a throttle, given a decoder address.booleanrequestThrottle(LocoAddress la, ThrottleListener l, boolean canHandleDecisions) Request a throttle, given a LocoAddress.voidAbstract member to actually do the work of configuring a new throttle, usually via interaction with the DCC systemabstract voidrequestThrottleSetup(LocoAddress a, boolean control) Abstract member to actually do the work of configuring a new throttle, usually via interaction with the DCC system.voidresponseThrottleDecision(int address, boolean isLong, ThrottleListener l, ThrottleListener.DecisionType decision) Steal or Share a requested throttle.voidresponseThrottleDecision(int address, ThrottleListener l, ThrottleListener.DecisionType decision) Steal or Share a requested throttle.voidresponseThrottleDecision(LocoAddress address, ThrottleListener l, ThrottleListener.DecisionType decision) Steal or Share a requested throttle.protected voidshowSessionCancelDialogue(LocoAddress address) If not headless, display a session stolen dialogue box with checkbox to hide notifications for rest of JMRI sessionprotected booleanDoes this DCC system allow a Throttle (e.g. an address) to be used by only one user at a time?What speed modes are supported by this system?protected voidupdateNumUsers(LocoAddress la, int numUsers) The number of users of this throttle has been updatedMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jmri.ThrottleManager
addressTypeUnique, canBeLongAddress, canBeShortAddress
-
Field Details
-
adapterMemo
-
userName
-
-
Constructor Details
-
AbstractThrottleManager
public AbstractThrottleManager() -
AbstractThrottleManager
-
-
Method Details
-
getUserName
Get the user name of the system that the programmer is associated with.- Specified by:
getUserNamein interfaceThrottleManager- Returns:
- the user name for the system
-
getAddressTypes
By default, only DCC in this implementation- Specified by:
getAddressTypesin interfaceThrottleManager- Returns:
- the list of supported address protocols
-
getAddressTypeString
By default, only DCC in this implementation- Specified by:
getAddressTypeStringin interfaceThrottleManager- Parameters:
prot- the protocol- Returns:
- a human-readable, possibly localized, description of the protocol
-
getAddressProtocolTypes
Get a list of different protocols supported by the system, to include short vs long or DCC vs Selectrix vs Motorola.- Specified by:
getAddressProtocolTypesin interfaceThrottleManager- Returns:
- a list of supported address protocols
-
getAddress
Get the object representing a particular address.- Specified by:
getAddressin interfaceThrottleManager- Parameters:
value- address in protocol-specific formatprotocol- the control protocol- Returns:
- the address, possibly as a protocol-specific subclass
-
getAddress
Get the object representing a particular address.- Specified by:
getAddressin interfaceThrottleManager- Parameters:
value- address in protocol-specific formatprotocol- specific protocol string, see the specific throttle manager for values- Returns:
- the address, possibly as a protocol-specific subclass
-
getProtocolFromString
Get a protocol given a description.- Specified by:
getProtocolFromStringin interfaceThrottleManager- Parameters:
selection- human-readable, possibly localized, description of the protocol- Returns:
- the protocol
-
singleUse
Does this DCC system allow a Throttle (e.g. an address) to be used by only one user at a time?- Returns:
- true or false
-
requestThrottle
public boolean requestThrottle(int address, boolean isLongAddress, ThrottleListener l, boolean canHandleDecisions) Request a throttle, given a decoder address and whether it is a long or short DCC address. When the decoder address is located, the ThrottleListener gets a callback via the ThrottleListener.notifyThrottleFound method.- Specified by:
requestThrottlein interfaceThrottleManager- Parameters:
address- desired decoder addressisLongAddress- true if requesting a DCC long (extended) addressl- ThrottleListener awaiting notification of a found throttlecanHandleDecisions- true if the ThrottleListener has a mechanism for dealing with Share / Steal decisions, else false- Returns:
- true if the request will continue, false if the request will not be made; false may be returned if a the throttle is already in use
-
requestThrottle
public boolean requestThrottle(@Nonnull BasicRosterEntry re, ThrottleListener l, boolean canHandleDecisions) Request a throttle from a given RosterEntry. When the decoder address is located, the ThrottleListener gets a callback via the ThrottleListener.notifyThrottleFound method.- Specified by:
requestThrottlein interfaceThrottleManager- Parameters:
re- desired RosterEntryl- ThrottleListener awaiting notification of a found throttlecanHandleDecisions- true if the ThrottleListener has a mechanism for dealing with Share / Steal decisions, else false- Returns:
- true if the request will continue, false if the request will not be made; false may be returned if a the throttle is already in use
-
requestThrottle
Request a throttle, given a LocoAddress. When the address is located, the ThrottleListener gets a callback via the ThrottleListener.notifyThrottleFound method.- Specified by:
requestThrottlein interfaceThrottleManager- Parameters:
la- desired loco addressl- ThrottleListener awaiting notification of a found throttlecanHandleDecisions- true if the ThrottleListener has a mechanism for dealing with Share / Steal decisions, else false- Returns:
- true if the request will continue, false if the request will not be made; false may be returned if a the throttle is already in use
-
requestThrottle
protected boolean requestThrottle(LocoAddress la, BasicRosterEntry re, ThrottleListener l, boolean canHandleDecisions) Request a throttle, given a decoder address.When the decoder address is located, the ThrottleListener gets a callback via the ThrottleListener.notifyThrottleFound method.
- Parameters:
la- LocoAddress of the decoder desired.l- The ThrottleListener awaiting notification of a found throttle.re- A BasicRosterEntry can be passed, this is attached to a throttle after creation.canHandleDecisions- true if theThrottleListener can make a steal or share decision, else false.- Returns:
- True if the request will continue, false if the request will not be made. False may be returned if a the throttle is already in use.
-
requestThrottle
Request Throttle with no Steal / Share Callbacks Request a throttle, given a decoder address. When the decoder address is located, the ThrottleListener gets a callback via the ThrottleListener.notifyThrottleFound method.This is a convenience version of the call, which uses system-specific logic to tell whether the address is a short or long form, and assumes that the hardware makes and steal / share decisions. Request a throttle, given a decoder address. When the decoder address is located, the ThrottleListener gets a callback via the ThrottleListener.notifyThrottleFound method.
This is a convenience version of the call, which uses system-specific logic to tell whether the address is a short or long form.
- Specified by:
requestThrottlein interfaceThrottleManager- Parameters:
address- The decoder address desired.l- The ThrottleListener awaiting notification of a found throttle.- Returns:
- True if the request will continue, false if the request will not be made. False may be returned if a the throttle is already in use.
-
requestThrottle
Request a throttle, given a decoder address. When the decoder address is located, the ThrottleListener gets a callback via the ThrottleListener.notifyThrottleFound method.This is a convenience version of the call, which uses system-specific logic to tell whether the address is a short or long form, and assumes that the hardware makes and steal / share decisions.
- Specified by:
requestThrottlein interfaceThrottleManager- Parameters:
address- desired decoder addressl- ThrottleListener awaiting notification of a found throttlecanHandleDecisions- true if the ThrottleListener has a mechanism for dealing with Share / Steal decisions, else false- Returns:
- true if the request will continue, false if the request will not be made; false may be returned if a the throttle is already in use
-
requestThrottleSetup
Abstract member to actually do the work of configuring a new throttle, usually via interaction with the DCC system.- Parameters:
a- addresscontrol- false - read only.
-
requestThrottleSetup
Abstract member to actually do the work of configuring a new throttle, usually via interaction with the DCC system- Parameters:
a- address.
-
cancelThrottleRequest
Cancel a request for a throttle.- Specified by:
cancelThrottleRequestin interfaceThrottleManager- Parameters:
address- desired decoder addressisLong- true if requesting a DCC long (extended) addressl- ThrottleListener canceling request for a throttle
-
cancelThrottleRequest
Cancel a request for a throttle.This is a convenience version of the call, which uses system-specific logic to tell whether the address is a short or long form.
- Specified by:
cancelThrottleRequestin interfaceThrottleManager- Parameters:
re- desired Roster Entryl- ThrottleListener canceling the request for a throttle
-
cancelThrottleRequest
Cancel a request for a throttle.- Specified by:
cancelThrottleRequestin interfaceThrottleManager- Parameters:
la- unwanted Loco addressl- ThrottleListener canceling request for a throttle
-
cancelThrottleRequest
Cancel a request for a throttle.This is a convenience version of the call, which uses system-specific logic to tell whether the address is a short or long form. Cancel a request for a throttle.
This is a convenience version of the call, which uses system-specific logic to tell whether the address is a short or long form.
- Specified by:
cancelThrottleRequestin interfaceThrottleManager- Parameters:
address- The decoder address desired.l- The ThrottleListener cancelling request for a throttle.
-
responseThrottleDecision
public void responseThrottleDecision(int address, ThrottleListener l, ThrottleListener.DecisionType decision) Steal or Share a requested throttle.This is a convenience version of the call, which uses system-specific logic to tell whether the address is a short or long form.
- Specified by:
responseThrottleDecisionin interfaceThrottleManager- Parameters:
address- desired decoder addressl- ThrottleListener requesting the throttle steal occur.decision- from the ThrottleListener, STEAL or SHARE.
-
responseThrottleDecision
public void responseThrottleDecision(int address, boolean isLong, ThrottleListener l, ThrottleListener.DecisionType decision) Steal or Share a requested throttle.This is a convenience version of the call, which uses system-specific logic to tell whether the address is a short or long form.
- Specified by:
responseThrottleDecisionin interfaceThrottleManager- Parameters:
address- desired decoder addressisLong- true if requesting a DCC long (extended) addressl- ThrottleListener requesting the throttle steal occur.decision- from the ThrottleListener, STEAL or SHARE.
-
responseThrottleDecision
public void responseThrottleDecision(LocoAddress address, ThrottleListener l, ThrottleListener.DecisionType decision) Steal or Share a requested throttle.- Specified by:
responseThrottleDecisionin interfaceThrottleManager- Parameters:
address- desired LocoAddressl- The ThrottleListener which has made the decisiondecision- from the ThrottleListener, STEAL or SHARE.
-
failedThrottleRequest
If the system-specific ThrottleManager has been unable to create the DCC throttle then it needs to be removed from the throttleListeners, otherwise any subsequent request for that address results in the address being reported as already in use, if singleUse is set. This also sends a notification message back to the requestor with a string reason as to why the request has failed.- Parameters:
address- The Loco Address that the request failed on.reason- A text string passed by the ThrottleManager as to why
-
notifyThrottleKnown
Handle throttle information when it's finally available, e.g. when a new Throttle object has been created.This method creates a throttle for all ThrottleListeners of that address and notifies them via the ThrottleListener.notifyThrottleFound method.
- Parameters:
throttle- throttle objectaddr- address.
-
makeHardwareDecision
For when a steal / share decision is needed and the ThrottleListener has delegated this decision to the ThrottleManager.Responds to the question by requesting a Throttle "Steal" by default.
Can be overridden by hardware types which do not wish the default behaviour to Steal.
This applies only to those systems where "stealing" or "sharing" applies, such as LocoNet.
- Parameters:
address- The LocoAddress the steal / share question relates toquestion- The Question to be put to the ThrottleListener
-
notifyDecisionRequest
When the system-specific ThrottleManager has been unable to create the DCC throttle because it is already in use and must be "stolen" or "shared" to take control, it needs to notify the listener of this situation.This applies only to those systems where "stealing" or "sharing" applies, such as LocoNet.
- Parameters:
address- The LocoAddress the steal / share question relates toquestion- The Question to be put to the ThrottleListener
-
hasDispatchFunction
Check to see if the Dispatch Button should be enabled or not Default to true, override if necessary- Specified by:
hasDispatchFunctionin interfaceThrottleManager- Returns:
- true if dispatch is possible; false otherwise
-
supportedSpeedModes
What speed modes are supported by this system? value should be xor of possible modes specifed by the DccThrottle interface- Specified by:
supportedSpeedModesin interfaceThrottleManager- Returns:
- an XOR of the possible modes specified in the throttle interface
-
enablePrefSilentStealOption
Hardware that uses the Silent Steal preference will need to override Test if the Silent Steal Throttles preference option should be enabled.- Specified by:
enablePrefSilentStealOptionin interfaceThrottleManager- Returns:
- true if steal is possible; false otherwise
-
attachListener
Attach a PropertyChangeListener to a specific loco address, where the requesting code does not need or require control over the loco. If the loco address is not in the active in the list, then a new throttle will be created by the manager and the listener attached.The PropertyChangeListener will be notified if it has been attached to a loco address or not, via a PropertyChange notification.
- Specified by:
attachListenerin interfaceThrottleManager- Parameters:
la- LocoAddress of the loco we wish to monitorp- PropertyChangeListener to attach to the throttle
-
removeListener
Remove a PropertyChangeListener to a specific loco address, where the requesting code has usedattachListenerto get notification of changes in a throttle.The PropertyChangeListener will be notified if it has been removed via a PropertyChange notification.
- Specified by:
removeListenerin interfaceThrottleManager- Parameters:
la- LocoAddress of the loco we wish to monitorp- PropertyChangeListener to remove from the throttle
-
addressStillRequired
- Specified by:
addressStillRequiredin interfaceThrottleManager- Parameters:
la- Loco address to test- Returns:
- true, its still required, false its not.
-
addressStillRequired
- Specified by:
addressStillRequiredin interfaceThrottleManager- Parameters:
address- Loco number to test.isLongAddress- true if long address.- Returns:
- true, its still required, false its not.
-
addressStillRequired
- Specified by:
addressStillRequiredin interfaceThrottleManager- Parameters:
address- Loco number to test- Returns:
- true, its still required, false its not.
-
addressStillRequired
- Specified by:
addressStillRequiredin interfaceThrottleManager- Parameters:
re- roster entry to test- Returns:
- true, its still required, false its not.
-
releaseThrottle
The specified Throttle Listener has finished using a given throttle and no longer requires access to it.After releasing the throttle, the manager will perform further checks to see if it is in use by any other listeners or if there are any PropertyChangeListeners attached. If there are no other uses of the throttle then it is disposed of.
Normally, release ends with a call to dispose.
- Specified by:
releaseThrottlein interfaceThrottleManager- Parameters:
t- Throttle being releasedl- Throttle Listener releasing the throttle
-
disposeThrottle
Not for general use, seereleaseThrottleanddispatchThrottle.Dispose of object when finished it. This will free up hardware resource
Used for handling certain internal error conditions, where the object still exists but hardware is not associated with it.
After this, further usage of this Throttle object will result in a JmriException.
- Specified by:
disposeThrottlein interfaceThrottleManager- Parameters:
t- Throttle being releasedl- Throttle Listener releasing the throttle- Returns:
- true if the throttle has been disposed of.
-
forceDisposeThrottle
Throttle can no longer be relied upon, potentially from an external forced steal or hardware error.Normally, #releaseThrottle should be used to close throttles.
Removes locoaddress from list to force new throttle requests to request new sessions where the Command station model implements a dynamic stack, not a static stack.
Managers still need to advise listeners that the session has been cancelled and actually dispose of the throttle
- Parameters:
la- address release
-
dispatchThrottle
The throttle listener has finished with the specific Throttle and is is available for reuse/reallocation by somebody else. If possible, tell the layout that this locomotive has been dispatched to another user. Not all layouts will implement this, in which case it is synomous with release();Normally, dispatch ends with a call to dispose.
- Specified by:
dispatchThrottlein interfaceThrottleManager- Parameters:
t- Throttle being releasedl- Throttle Listener releasing the throttle
-
dispose
Allow to cleanly release the traffic controller in ThrottleManager Tests- remove listeners, if any
- stop timers, is any
- Specified by:
disposein interfaceThrottleManager
-
getThrottleUsageCount
Get the number of Throttles sharing the throttle for a ddcaddress.- Specified by:
getThrottleUsageCountin interfaceThrottleManager- Parameters:
la- LocoAddress of the loco you want the throttle usage count for.- Returns:
- number of throttles for this address, or 0 if throttle does not exist
-
getThrottleUsageCount
Get the number of Throttles sharing the throttle for a ddcaddress.- Specified by:
getThrottleUsageCountin interfaceThrottleManager- Parameters:
address- number of the loco you want the throttle usage count for.isLongAddress- indicates whether the address is long or not.- Returns:
- number of throttles for this address, or 0 if throttle does not exist
-
getThrottleUsageCount
Get the number of Throttles sharing the throttle for a ddcaddress.- Specified by:
getThrottleUsageCountin interfaceThrottleManager- Parameters:
address- number of the loco you want the throttle usage count for.- Returns:
- number of throttles for this address, or 0 if throttle does not exist
-
getThrottleUsageCount
Get the number of Throttles sharing the throttle for a ddcaddress.- Specified by:
getThrottleUsageCountin interfaceThrottleManager- Parameters:
re- BasicRosterEntry of the loco you want the throttle usage count for.- Returns:
- number of throttles for this address, or 0 if throttle does not exist
-
addressReleased
Release a Throttle from a ThrottleListener.- Parameters:
la- address releasel- listening object- Returns:
- True if throttle still has listeners or a positive use count, else False
-
updateNumUsers
The number of users of this throttle has been updatedTypically used to update dispatch / release availablility specific implementations can override this function to get updates
- Parameters:
la- the Loco Address which has been updatednumUsers- current number of users
-
getThrottleInfo
Provides a Proxy method to return the SpeedSetting, Direction, Function Settings, of a throttle, where the requesting code has usedattachListenerto only be notified of changes in the throttle and not control it.Valid values for item are IsForward SpeedSetting SpeedIncrement SpeedStepMode F0-F28
- Specified by:
getThrottleInfoin interfaceThrottleManager- Parameters:
la- LocoAddress that we wish interrogateitem- A string of the item we wish to know the value of.- Returns:
- the value as an object, if the loco address has not been assigned to a throttle or the item value is not valid, null is returned.
-
showSessionCancelDialogue
If not headless, display a session stolen dialogue box with checkbox to hide notifications for rest of JMRI session- Parameters:
address- the LocoAddress of the stolen / cancelled Throttle
-
hideStealNotifications
Receive notification from a throttle dialogue to display steal dialogues for rest of the JMRI instance session. False by default to show notifications- Parameters:
hide- set True to hide notifications, else False.
-