Class AutoAllocate
- java.lang.Object
-
- jmri.jmrit.dispatcher.AutoAllocate
-
- All Implemented Interfaces:
java.lang.Runnable
public class AutoAllocate extends java.lang.Object implements java.lang.Runnable
Handles automatic allocation of Sections for DispatcherAutoAllocate.java is an extension of DispatcherFrame.java.
When AutoAllocate is triggered, it scans the list of Allocation Requests, in order of the priorities of ActiveTrains with pending AllocationRequests, testing if a requested allocation can be made. AutoAllocate returns when either: A Section has been allocated -or- All AllocationRequests have been tested, and no allocation is indicated.
If AutoAllocate needs to save information related to a plan requiring multiple allocations, an AllocationPlan object is created. When the plan is complete, the AllocationPlan object is disposed of. Multiple AllocationPlan objects may be active at any one time.
AutoAllocate is triggered by each of the following events: An AllocatedSection has been released, freeing up a Section. A new AllocationRequest has been entered into the queue of AllocationRequests. A Section has been allocated, either by AutoAllocate or manually by the dispatcher.
AutoAllocate requires that AutoRelease is active.
AutoAllocate operates conservatively, that is, if there is any doubt that a Section should be allocated, it will not allocate the Section.
AutoAllocate develops plans for meets when multiple ActiveTrains are using the same Sections of track. These plans are automatically created and removed. They are stored in AllocationPlan objects to avoid having to continually recreate them, since the logic to create them is rather complicated.
The dispatcher is free to switch AutoAllocate on or off at any tine in DispatcherFrame. When AutoAllocate is switched off, all existing AllocationPlan objects are discarded.
All work done within the class is queued using a blocking queue. This is to ensure the integrity of arrays, both in Dispatcher and ActiveTrain, and to prevent calls within calls to modify those arrays, including autorelease.
This file is part of JMRI.JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.
JMRI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) Section
curSection
(package private) java.util.concurrent.LinkedBlockingQueue<TaskAllocateRelease>
taskList
-
Constructor Summary
Constructors Constructor Description AutoAllocate(DispatcherFrame d, java.util.List<AllocationRequest> inAllocationRequests)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
allRequestsDone()
protected Section
autoNextSectionChoice(java.util.List<Section> sList, AllocationRequest ar, int sectionSeqNo)
Entered to request a choice of Next Section when a Section is being allocated and there are alternate Section choices for the next Section.protected Section
checkBlocksNotInReservedSection(ActiveTrain at, Section sectionToCheck)
protected void
clearAllocationPlans()
protected void
releaseReservation(java.lang.String trainName, java.lang.String sectionSystemName)
Remove a specific section reservation for a train.protected void
removeAllReservesForTrain(java.lang.String trainName)
Remove all reserved sections for a train namevoid
run()
protected void
scanAllocationRequests(TaskAllocateRelease task)
protected void
setAbort()
Stops the autoAllocate nicely
-
-
-
Field Detail
-
taskList
java.util.concurrent.LinkedBlockingQueue<TaskAllocateRelease> taskList
-
curSection
Section curSection
-
-
Constructor Detail
-
AutoAllocate
public AutoAllocate(DispatcherFrame d, java.util.List<AllocationRequest> inAllocationRequests)
-
-
Method Detail
-
setAbort
protected void setAbort()
Stops the autoAllocate nicely
-
allRequestsDone
protected boolean allRequestsDone()
-
scanAllocationRequests
protected void scanAllocationRequests(TaskAllocateRelease task)
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
removeAllReservesForTrain
protected void removeAllReservesForTrain(java.lang.String trainName)
Remove all reserved sections for a train name- Parameters:
trainName
- remove reserved spaces for this train
-
releaseReservation
protected void releaseReservation(java.lang.String trainName, java.lang.String sectionSystemName)
Remove a specific section reservation for a train.- Parameters:
trainName
- Name of the trainsectionSystemName
- Systemname
-
checkBlocksNotInReservedSection
protected Section checkBlocksNotInReservedSection(ActiveTrain at, Section sectionToCheck)
-
autoNextSectionChoice
protected Section autoNextSectionChoice(java.util.List<Section> sList, AllocationRequest ar, int sectionSeqNo)
Entered to request a choice of Next Section when a Section is being allocated and there are alternate Section choices for the next Section.- Parameters:
sList
- the possible next Sectionsar
- the section being allocated when a choice is neededsectionSeqNo
- transit sequence number attempting to be allocated- Returns:
- the allocated section
-
clearAllocationPlans
protected void clearAllocationPlans()
-
-