Class SResource

  • All Implemented Interfaces:
    ObservableIfc, GetNameIfc, IdentityIfc

    public class SResource
    extends SchedulingElement
    A SResource represents a simple resource that can have units become busy. A resource is considered busy when it has 1 or more units busy. A resource is considered idle when all available units are idle. A resource has an initial capacity, which represents the units that can be allocated. The capacity of the resource represents the maximum number of units available for use. For example, if the resource has capacity 3, it may have 2 units busy and 1 unit idle. A resource cannot have more units busy than the capacity.
    • Field Detail

      • SEIZE

        public static final int SEIZE
        Indicates that the resource was seized for state change purposes That is, units of the resource became busy.
      • RELEASE

        public static final int RELEASE
        Indicates that the resource was released for state change purposes That is, units of resource became idle.
    • Constructor Detail

      • SResource

        public SResource​(ModelElement parent)
        The capacity is set to 1
        Parameters:
        parent - the parent model element
      • SResource

        public SResource​(ModelElement parent,
                         java.lang.String name)
        The capacity is set to 1
        Parameters:
        parent - the parent model element
        name - a unique name for the resource
      • SResource

        public SResource​(ModelElement parent,
                         int capacity)
        The capacity represents the maximum number of units available to use when the resource is idle.
        Parameters:
        parent - the parent model element
        capacity - the initial capacity of the resource
      • SResource

        public SResource​(ModelElement parent,
                         int capacity,
                         java.lang.String name)
        The capacity represents the maximum number of units available to use when the resource is idle.
        Parameters:
        parent - the parent model element
        capacity - the initial capacity of the resource
        name - a unique name for the resource
    • Method Detail

      • initialize

        protected void initialize()
        Description copied from class: ModelElement
        This method should be overridden by subclasses that need actions performed to initialize prior to a replication. It is called once before each replication occurs if the model element wants initialization. It is called after beforeReplication() is called
        Overrides:
        initialize in class ModelElement
      • getNumberTimesSeized

        public final int getNumberTimesSeized()
        Returns how many times the resource has had units used.
        Returns:
        how many times the resource has had units used.
      • getNumberTimesReleased

        public final int getNumberTimesReleased()
        Returns how many times the resource has had units returned from use.
        Returns:
        how many times the resource has had units returned from use
      • getFractionBusy

        public final double getFractionBusy()
        The fraction of the capacity that is currently busy
        Returns:
        fraction of the capacity that is currently busy
      • getNumBusy

        public final int getNumBusy()
        The number of units that are currently busy
        Returns:
        number of units that are currently busy
      • seize

        public final void seize()
        Seizes 1 unit of the resource. If the resource has no units available, then an exception occurs. If getNumberAvailable() = 0 then an exception occurs.
      • seize

        public void seize​(int amt)
        Seizes amt units of the resource. If amt = 0, then an exception occurs. If the resource has no units available, then an exception occurs. If the amt > getNumberAvailable() then an exception occurs.
        Parameters:
        amt - the amount to seize
      • updateState

        protected void updateState​(int change)
      • release

        public final void release()
        Releases 1 unit of the resource. If the number busy is zero, then an exception occurs.
      • release

        public void release​(int amt)
        Releases amt units of the resource. If amt is 0 then an exception occurs. If the amt is > getNumBusy() then an exception occurs
        Parameters:
        amt - the amount to release
      • asString

        public java.lang.String asString()
        Description copied from class: ModelElement
        Allows sub-classes to provide more detail than toString() to represent the ModelElement as a String
        Overrides:
        asString in class ModelElement
        Returns:
        a detailed String representation
      • isIdle

        public final boolean isIdle()
        Checks if the resource is idle. The resource is idle if all available units are idle.
        Returns:
        true if idle, false otherwise
      • isBusy

        public final boolean isBusy()
        Checks to see if the resource is busy. The resource is busy if 1 or more of its units are busy.
        Returns:
        true if busy
      • getCapacity

        public final int getCapacity()
        The current capacity of the resource.
        Returns:
        the capacity
      • getNumberAvailable

        public int getNumberAvailable()
        Returns the number of units that are currently available for use
        Returns:
        the number of units that are currently available for use
      • hasAvailableUnits

        public final boolean hasAvailableUnits()
        Returns true if getNumberAvailable() > 0
        Returns:
        true if getNumberAvailable() > 0
      • getInitialCapacity

        public final int getInitialCapacity()
        Gets the initial capacity of the resource
        Returns:
        the initial capacity of the resource
      • setInitialCapacity

        public final void setInitialCapacity​(int capacity)
        Sets the initial capacity of the resource. This only changes it for when the resource is initialized.
        Parameters:
        capacity - the initial capacity of the resource
      • notifyStateChangeListeners

        protected void notifyStateChangeListeners()
      • getNBAcrossReplicationStatistic

        public final StatisticAccessorIfc getNBAcrossReplicationStatistic()
        Across replication statistics on the number busy
        Returns:
      • getUtilAcrossReplicationStatistic

        public final StatisticAccessorIfc getUtilAcrossReplicationStatistic()
        Across replication statistics on the utilization
        Returns: