java.lang.Object
org.bzdev.devqsim.SimObject
org.bzdev.drama.generic.GenericSimObject<S,A,C,D,DM,F,G>
org.bzdev.drama.generic.GenericTaskObject<S,A,C,D,DM,F,G>
org.bzdev.drama.common.MessageRecipient<S,A,C,D,DM,F,G>
org.bzdev.drama.generic.GenericMsgRecipient<S,A,C,D,DM,F,G>
org.bzdev.drama.generic.GenericActor<DramaSimulation,Actor,Condition,Domain,DomainMember,DramaFactory,Group>
org.bzdev.drama.Actor
org.bzdev.bikeshare.HubBalancer
- All Implemented Interfaces:
CondObserver<Condition,
,Actor> NamedObjectOps
- Direct Known Subclasses:
BasicHubBalancer
Base class for hub balancers.
A hub balancer schedules hub workers in response to changes
in the hub states. This class will arrange for the hub workers
that continually move between hubs for load balancing to start
automatically. Subclasses can schedule additional hub workers
based on changing conditions.
Two classes must be implemented by subclasses:
startAdditionalWorkers()
. This method will be called when hubs change the number of bicycles in the overflow area or when the number of bicycles in the preferred area changes when the number is above or below the upper and lower thresholds.getHubSorter(HubWorker.Mode, StorageHub,Hub[])
. This method determines thehub sorter
to use by workers when the worker is started in a particular mode.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
HubBalancer
(DramaSimulation sim, String name, boolean intern) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
protected Object
clone()
final boolean
delete()
final boolean
abstract HubWorker.HubSorter
getHubSorter
(HubWorker.Mode mode, StorageHub shub, Hub[] hubs) Get a hub sorter.final String
getName()
protected Simulation
Get the set of hubs whose overflow area contains bicycles.Get the set of hubs whose preferred location contains more bicycles than allowed by the hub's upper trigger.protected SysDomain
Get the system domain.Get the set of hubs whose preferred location contains less bicycles than allowed by the hub's lower trigger.void
initDomain
(SysDomain sysDomain) Initialize this hub balancer by configuring its system domain.final boolean
boolean
protected void
onConditionChangeImpl
(HubCondition c, ConditionMode mode, SimObject source) Respond to a change in a hub condition.void
printConfiguration
(String iPrefix, String prefix, boolean printName, PrintWriter out) Print the configuration for an instance of HubBalancer.void
printState
(String iPrefix, String prefix, boolean printName, PrintWriter out) Print the state for an instance of HubBalancer.protected abstract void
Start additional works on an as-needed basis.protected void
Start the workers that loop between hubs.Methods inherited from class org.bzdev.drama.Actor
doReceive, onConditionChange
Methods inherited from class org.bzdev.drama.generic.GenericActor
addCondition, conditionSet, domainSet, drainMessageQueue, findMsgFrwdngInfo, findMsgFrwdngInfo, findMsgFrwdngInfo, findMsgFrwdngInfo, findMsgFrwdngInfo, findMsgFrwdngInfo, findMsgFrwdngInfo, getChildDomains, getConditionChangeQMode, getCondObserverImpl, hasCondition, inDomain, joinDomain, joinDomain, leaveDomain, onConditionChange, onDelete, removeCondition, send, send, send, send, send, send, send, send, send, send, send, setConditionChangeQMode, setMessageQueueing, setSharedDomainMember
Methods inherited from class org.bzdev.drama.generic.GenericMsgRecipient
getGroups, inGroup, joinGroup, joinGroup, leaveGroup
Methods inherited from class org.bzdev.drama.generic.GenericTaskObject
cancelDefaultCall, cancelDefaultTask, defaultCall, defaultTask, scheduleDefaultCall, scheduleDefaultTask, scheduleDefaultTask
Methods inherited from class org.bzdev.drama.generic.GenericSimObject
getSimulation
Methods inherited from class org.bzdev.devqsim.SimObject
addSimulationListener, addTraceSet, bindCallable, bindCallable, bindCallable, bindCallable, bindRunnable, bindRunnable, bindRunnable, bindRunnable, callableObject, callableScript, callScriptFunction, callScriptMethod, clearTraceSets, evalScript, getEventListenerList, getScriptObject, getTraceSets, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printConfiguration, printState, printState, printState, printState, printState, printState, putScriptObject, removeSimulationListener, removeTraceSet, runnableObject, runnableScript, scheduleCall, scheduleCall, scheduleCall, scheduleCall, scheduleCallObject, scheduleScript, scheduleTask, scheduleTask, scheduleTask, scheduleTask, scheduleTaskObject, scheduleTaskScript, startImmediateTask, startImmediateTask, trace, trace, unscheduledTaskThread, unscheduledTaskThread, update, update, usesTraceSet
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.obnaming.NamedObjectOps
canDelete, delete, deletePending, getName, isDeleted, isInterned
-
Constructor Details
-
HubBalancer
Constructor.- Parameters:
sim
- the simulationname
- the name of this objectintern
- true if this object should be interned in the simulation's name table; false otherwise
-
-
Method Details
-
getSysDomain
Get the system domain.- Returns:
- the system domain for this hub balancer
-
getOverSet
Get the set of hubs whose preferred location contains more bicycles than allowed by the hub's upper trigger.- Returns:
- the set of hubs whose preferred location contains more bicycles than allowed by the hub's upper trigger
-
getUnderSet
Get the set of hubs whose preferred location contains less bicycles than allowed by the hub's lower trigger.- Returns:
- the set of hubs whose preferred location contains less bicycles than allowed by the hub's lower trigger
-
getOverflowSet
Get the set of hubs whose overflow area contains bicycles. The hubs are ones using the same user domain as this hub balancer.- Returns:
- the set of hubs whose overflow area contains bicycles
-
startInitialWorkers
protected void startInitialWorkers()Start the workers that loop between hubs. -
startAdditionalWorkers
protected abstract void startAdditionalWorkers()Start additional works on an as-needed basis. This method may be called in response to a condition change. When a subclass implements this method, it is the responsibility of the subclass to determine the number of workers that should be used. This number may be zero. The classBasicHubBalancer
, for example, uses an implementation where there is a threshold for the number of hubs that can use an extra worker and a quiet period that prevents a large number of workers from being scheduled at once. -
printConfiguration
Print the configuration for an instance of HubBalancer. The documentation for methodSimObject.printConfiguration(String,String,boolean,java.io.PrintWriter)
contains a description of how this method is used and how to override it. The methodGenericActor.printConfiguration(String,String,boolean,java.io.PrintWriter)
describes the data that will be printed for the superclass of this class. The data that will be printed when this method is called are the following.For class
HubBalancer
:- (No data associated with the HubBalancer class is printed.)
- Overrides:
printConfiguration
in classGenericActor<DramaSimulation,
Actor, Condition, Domain, DomainMember, DramaFactory, Group> - Parameters:
iPrefix
- the prefix to use for an initial line when printName is true with null treated as an empty stringprefix
- a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is trueprintName
- requests printing the name of an objectout
- the output print writer
-
printState
Print the state for an instance of HubBalancer. The documentation for methodSimObject.printState(String,String,boolean,java.io.PrintWriter)
contains a description of how this method is used and how to override it. The methodGenericSimObject.printState(String,String,boolean,java.io.PrintWriter)
describes the data that will be printed for the superclass of this class. The data that will be printed when this method is called are the following.For class
HubBalancer
:- the over-trigger set (the hubs whose bicycle count is larger than its upper-trigger value).
- the under-trigger set (the hubs whose bicycle count is below its under-trigger value).
- the overflow set (the hubs that have bicycles in their overflow areas).
- Overrides:
printState
in classGenericSimObject<DramaSimulation,
Actor, Condition, Domain, DomainMember, DramaFactory, Group> - Parameters:
iPrefix
- the prefix to use for an initial line when printName is true with null treated as an empty stringprefix
- a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is trueprintName
- requests printing the name of an objectout
- the output print writer
-
clone
- Overrides:
clone
in classObject
- Throws:
CloneNotSupportedException
-
isInterned
public boolean isInterned()- Specified by:
isInterned
in interfaceNamedObjectOps
-
getObjectNamer
-
getName
- Specified by:
getName
in interfaceNamedObjectOps
-
canDelete
public boolean canDelete()- Specified by:
canDelete
in interfaceNamedObjectOps
-
delete
public final boolean delete()- Specified by:
delete
in interfaceNamedObjectOps
-
isDeleted
public final boolean isDeleted()- Specified by:
isDeleted
in interfaceNamedObjectOps
-
deletePending
public final boolean deletePending()- Specified by:
deletePending
in interfaceNamedObjectOps
-