Interface SupplyManager

All Known Implementing Classes:
VariableListenerSupport

public interface SupplyManager
Provides a Supply for subsystems that submit a Demand.
  • Method Details

    • demand

      <Supply_ extends Supply> Supply_ demand(Demand<Supply_> demand)
      Returns the Supply for a Demand, preferably an existing one. If the Supply doesn't exist yet (as part of the domain model or externalized), it creates and attaches it. If two Demand instances are equal, they will result in the same Supply instance. Each supply instance keeps a counter of how many times it was requested, which can be decremented by cancel(Demand).
      Type Parameters:
      Supply_ - Subclass of Supply
      Parameters:
      demand - never null
      Returns:
      never null
    • cancel

      <Supply_ extends Supply> boolean cancel(Demand<Supply_> demand)
      Cancel an active demand(Demand). Once the number of active demands reaches zero, the Supply in question is removed.

      This operation is optional. Supplies with active demands will live for as long as the SupplyManager lives, and get garbage-collected together with it.

      Type Parameters:
      Supply_ -
      Parameters:
      demand - never null
      Returns:
      true if the counter was decremented, false if there is no such supply
    • getActiveCount

      <Supply_ extends Supply> long getActiveCount(Demand<Supply_> demand)
      Type Parameters:
      Supply_ -
      Parameters:
      demand -
      Returns:
      0 when there is no active Supply for the given Demand, more when there is one.