Class HubBalancer

All Implemented Interfaces:
CondObserver<Condition,Actor>, NamedObjectOps
Direct Known Subclasses:
BasicHubBalancer

public abstract class HubBalancer extends Actor
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 the hub sorter to use by workers when the worker is started in a particular mode.
  • Constructor Details

    • HubBalancer

      protected HubBalancer(DramaSimulation sim, String name, boolean intern)
      Constructor.
      Parameters:
      sim - the simulation
      name - the name of this object
      intern - true if this object should be interned in the simulation's name table; false otherwise
  • Method Details

    • getSysDomain

      protected SysDomain getSysDomain()
      Get the system domain.
      Returns:
      the system domain for this hub balancer
    • initDomain

      public void initDomain(SysDomain sysDomain)
      Initialize this hub balancer by configuring its system domain.
      Parameters:
      sysDomain - the system domain that should be associated with this load balancer
    • getOverSet

      protected Set<Hub> 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

      public Set<Hub> 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

      protected Set<Hub> 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 class BasicHubBalancer, 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.
    • getHubSorter

      public abstract HubWorker.HubSorter getHubSorter(HubWorker.Mode mode, StorageHub shub, Hub[] hubs)
      Get a hub sorter.
      Parameters:
      mode - the worker mode for this hub sorter
      shub - the storage hub used to obtain a worker.
      hubs - a list of hubs to sort.
      Returns:
      a hub sorter.
      See Also:
    • onConditionChangeImpl

      protected void onConditionChangeImpl(HubCondition c, ConditionMode mode, SimObject source)
      Respond to a change in a hub condition. This implementation will ignore all condition modes other than OBSERVER_NOTIFIED.
      Parameters:
      c - the hub condition representing a change
      mode - the type of condition change
      source - the object that caused the change.
    • printConfiguration

      public void printConfiguration(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print the configuration for an instance of HubBalancer. The documentation for method SimObject.printConfiguration(String,String,boolean,java.io.PrintWriter) contains a description of how this method is used and how to override it. The method GenericActor.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 class GenericActor<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 string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • printState

      public void printState(String iPrefix, String prefix, boolean printName, PrintWriter out)
      Print the state for an instance of HubBalancer. The documentation for method SimObject.printState(String,String,boolean,java.io.PrintWriter) contains a description of how this method is used and how to override it. The method GenericSimObject.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 class GenericSimObject<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 string
      prefix - a prefix string (typically whitespace) to put at the start of each line other than the initial line that is printed when printName is true
      printName - requests printing the name of an object
      out - the output print writer
    • clone

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • isInterned

      public boolean isInterned()
      Specified by:
      isInterned in interface NamedObjectOps
    • getObjectNamer

      protected Simulation getObjectNamer()
    • getName

      public final String getName()
      Specified by:
      getName in interface NamedObjectOps
    • canDelete

      public boolean canDelete()
      Specified by:
      canDelete in interface NamedObjectOps
    • delete

      public final boolean delete()
      Specified by:
      delete in interface NamedObjectOps
    • isDeleted

      public final boolean isDeleted()
      Specified by:
      isDeleted in interface NamedObjectOps
    • deletePending

      public final boolean deletePending()
      Specified by:
      deletePending in interface NamedObjectOps