Class ResourceSet

  • All Implemented Interfaces:
    SeizeIfc, ObservableIfc, GetNameIfc, IdentityIfc

    public class ResourceSet
    extends ModelElement
    implements SeizeIfc
    A ResourceSet holds a set of resources so that they can be selected for allocation via a ResouceSelectionRuleIfc. A ResouceSet can have many resources and a resource can be in many resource sets. The selectIdleResource(Request r) method uses the ResourceSelectionRuleIfc (if provided) to select the next idle resource for a request. The default is to cycle through the resources to select the resources in the order in which they were released.
    • Constructor Detail

      • ResourceSet

        public ResourceSet​(ModelElement parent)
        Creates a resource set with the given model element as a parent and assigned a default name.
        Parameters:
        parent -
      • ResourceSet

        public ResourceSet​(ModelElement parent,
                           java.lang.String name)
        Creates a resource set with the given model element as a parent and the given name.
        Parameters:
        parent -
        name -
    • 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
      • getMaxCapacity

        public final int getMaxCapacity()
        Returns:
        Returns the MaxCapacity.
      • addResource

        public final Resource addResource()
        Creates and adds a resource to the set
        Returns:
      • addResource

        public final Resource addResource​(int capacity)
        Creates and adds a resource to the set
        Parameters:
        capacity -
        Returns:
      • addResource

        public final Resource addResource​(int capacity,
                                          java.lang.String name)
        Creates and adds a resource to the set
        Parameters:
        capacity -
        name -
        Returns:
      • addResource

        public final void addResource​(Resource resource)
        Adds a resource to the set.
        Parameters:
        resource -
      • getResourceIterator

        public final java.util.ListIterator<Resource> getResourceIterator()
        Returns an iterator to the resources in this set
        Returns:
      • selectAvailableResource

        public Resource selectAvailableResource​(int amtNeeded,
                                                ResourceSelectionRuleIfc rule)
        Returns the next available resource to be used for allocating to requests, null if none are found that can satisfy the request. Uses the supplied rule to select the resource
        Parameters:
        amtNeeded -
        Returns:
      • selectAvailableResource

        public Resource selectAvailableResource​(ResourceSelectionRuleIfc rule)
        Selects an available resource or null if none are available The default is to find the first available resource that has the maximum available units. To change this either override this method or supply a ResourceSelectionRuleIfc
        Returns:
      • addWaitingRequest

        protected void addWaitingRequest​(Request request)
        Adds the request to the list of waiting requests based on the Comparable interface for Request
        Parameters:
        request -
      • removeWaitingRequest

        protected void removeWaitingRequest​(Request request)
        Removes the request from the list of waiting requests
        Parameters:
        request -
      • peekNextRequest

        protected Request peekNextRequest()
        Returns the next request without removing it
        Returns:
      • removeNextRequest

        protected Request removeNextRequest()
        Removes the next request from the waiting list of requests
        Returns:
      • seize

        public final void seize​(Request request)
        Description copied from interface: SeizeIfc
        Seizes the resource using the request. Conditions: 1) request must not be null 2) request.getEntity() must not be null 3) The request must not have been seized with another resource 4) The request must have a ResourceAllocationListener attached.
        Specified by:
        seize in interface SeizeIfc
      • getNumberAvailableResources

        public final int getNumberAvailableResources()
        Returns the current number of idle resources in the set
        Returns:
      • hasAvailableResources

        public final boolean hasAvailableResources()
      • 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
      • getResourceSelectionRule

        public final ResourceSelectionRuleIfc getResourceSelectionRule()
        Returns the current resource selection rule or null if none
        Returns:
      • setResourceSelectionRule

        public final void setResourceSelectionRule​(ResourceSelectionRuleIfc rule)
        Sets the resource selection rule. The supplied rule is responsible for both recommending an idle resource (not removing it) and for returning an idle resource back to the list. This allows the rule to maintain the list in an order if necessary.
        Parameters:
        rule -
      • resourceBecameUnavailable

        protected void resourceBecameUnavailable​(Resource resource)
        If a resource within the set becomes unavailable (busy, failed, inactive) it should be removed from the potential list of availabe resources.
        Parameters:
        resource -
      • resourceBecameAvailable

        protected void resourceBecameAvailable​(Resource resource)
        When a resource becomes available it needs to be added to the list of available resources
        Parameters:
        resource -
      • processWaitingRequests

        protected void processWaitingRequests()
        This method processes any waiting requests whenever a resource within the set has notified the set that it has become available Any waiting requests have not previously used a resource because they wait if and only if a resource is not available from the set when they make their seize.