Class LockedRoutesManager
- java.lang.Object
-
- jmri.jmrit.ctc.LockedRoutesManager
-
public class LockedRoutesManager extends java.lang.Object
This object manages all of the active routes. As of 6/24/2020:Code was added to support fleeting over "existing" routes. Either the dispatcher codes a O.S. section a second time in the same direction again for a following train, or the fleeting "toggle" is on.
Background: We KNOW from routine "anyInCommon", that it is IMPOSSIBLE to have overlapping routes in "_mArrayListOfLockedRoutes". That is enforced (and a requirement).
We ALSO know that when routine "checkRouteAndAllocateIfAvailable" is called, its parameter "sensors" has ALL of the new sensors for that route. We will take advantage of this later on.
New code design: In the routine "anyInCommon", we check to see if there is any overlap. If there is, a 2nd check is done to see if the overlapping route is in the same direction. If so, it is allowed.
IF (and only if) this is the case, we KNOW that the (old) existing overlapping route in "_mArrayListOfLockedRoutes" that it was checking against is either (regarding sensors) the same, or a (possible) subset. The subset case is due to occupancy sensor(s) turning off by the prior train as it advanced, and being removed from the set. Technically, it can NEVER be the same, since the ABS system would prevent the signal from going non-red if the prior train hasn't advanced at least one block past the O.S. section. But the code makes no assumptions regarding this.
-
-
Constructor Summary
Constructors Constructor Description LockedRoutesManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancelLockedRoute(LockedRoute lockedRoute)
This routine frees all resources allocated by the passed lockedRoute (listeners primarily) and then removes it from our "_mArrayListOfLockedRoutes".boolean
checkRoute(java.util.HashSet<Sensor> sensors, java.lang.String osSectionDescription, java.lang.String ruleDescription)
Call this routine with a set of resources that need to be checked against the presently allocated resources.LockedRoute
checkRouteAndAllocateIfAvailable(java.util.HashSet<Sensor> sensors, java.lang.String osSectionDescription, java.lang.String ruleDescription, boolean rightTraffic)
Call this routine with a set of resources that need to be checked against the presently allocated resources.void
clearAllLockedRoutes()
(package private) void
dumpAllRoutes()
Simple routine to dump all locked routes information.void
removeAllListeners()
Primarily called when the CTC system is restarted from within JMRI, nothing else external to this module should call this.
-
-
-
Constructor Detail
-
LockedRoutesManager
public LockedRoutesManager()
-
-
Method Detail
-
clearAllLockedRoutes
public void clearAllLockedRoutes()
-
checkRoute
public boolean checkRoute(java.util.HashSet<Sensor> sensors, java.lang.String osSectionDescription, java.lang.String ruleDescription)
Call this routine with a set of resources that need to be checked against the presently allocated resources.ONLY A CHECK IS DONE. No resources are modified!
Typically used for a O.S. section sensors check. Get the primary and possibly the secondary O.S. sensor(s) associated with it, and pass it in "sensors". NO CHECK is made of traffic direction.
- Parameters:
sensors
- set of sensors.osSectionDescription
- section description.ruleDescription
- rule description.- Returns:
- true if there is no overlap of resources, else returns false.
-
checkRouteAndAllocateIfAvailable
public LockedRoute checkRouteAndAllocateIfAvailable(java.util.HashSet<Sensor> sensors, java.lang.String osSectionDescription, java.lang.String ruleDescription, boolean rightTraffic)
Call this routine with a set of resources that need to be checked against the presently allocated resources. IF the traffic direction is the same as presently allocated, then it is ALWAYS allowed, as some form of fleeting operation has been requested by the dispatcher.If there is no overlap, then add the set to the presently allocated resources and return the LockedRoute object. If there is overlap, modify nothing and return null. See explanation at the start of this source code about support put in here for Fleeting.
- Parameters:
sensors
- set of sensors.osSectionDescription
- section description.ruleDescription
- rule description.rightTraffic
- true if right traffic, else false if left traffic- Returns:
- locked route if success, null if failed.
-
cancelLockedRoute
public void cancelLockedRoute(LockedRoute lockedRoute)
This routine frees all resources allocated by the passed lockedRoute (listeners primarily) and then removes it from our "_mArrayListOfLockedRoutes". Now the route does NOT exist anywhere.- Parameters:
lockedRoute
- The route to cancel.NOTE: The child (LockedRoute object) or running time done calls us when it determines it's empty, so we can delete it from our master list. It's already de-allocated all of its resources, but for safety call "removeAllListeners" anyways.
-
removeAllListeners
public void removeAllListeners()
Primarily called when the CTC system is restarted from within JMRI, nothing else external to this module should call this.
-
dumpAllRoutes
void dumpAllRoutes()
Simple routine to dump all locked routes information. Called from CTCMain when the debug sensor goes active.
-
-