Package jsl.modeling.elements.entity
Class ResourceSet
- java.lang.Object
-
- jsl.simulation.ModelElement
-
- jsl.modeling.elements.entity.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jsl.simulation.ModelElement
ModelElement.EventBuilderIfc<T>, ModelElement.EventScheduler<T>, ModelElement.ModelElementComparator, ModelElement.RequestBuilder, ModelElement.RequestDurationIfc, ModelElement.RequestTimeIfc, ModelElement.RequestUsingIfc, ModelElement.TimedUpdateEventAction, ModelElement.TimeUnitIfc<T>, ModelElement.WarmUpEventAction
-
-
Field Summary
Fields Modifier and Type Field Description static ResourceSelectionRuleIfcCYCLICALprotected java.util.List<Resource>myAvailableResourcesprotected TimeWeightedmyNumAvailableResourcesprotected java.util.List<Resource>myResourcesprotected ResourceSelectionRuleIfcmyResourceSelectionRuleprotected OrderedList<Request>myWaitingRequests-
Fields inherited from class jsl.simulation.ModelElement
AFTER_EXPERIMENT, AFTER_REPLICATION, BEFORE_EXPERIMENT, BEFORE_REPLICATION, CONDITIONAL_ACTION_REGISTRATION, DEFAULT_TIMED_EVENT_PRIORITY, INITIALIZED, MONTE_CARLO, myAfterExperimentOption, myAfterReplicationOption, myBeforeExperimentOption, myBeforeReplicationOption, myInitializationOption, myLengthOfWarmUp, myModelElements, myMonteCarloOption, myObservableComponent, myReplicationEndedOption, myTimedUpdateActionListener, myTimedUpdateEvent, myTimedUpdateInterval, myTimedUpdateOption, myTimedUpdatePriority, myWarmUpActionListener, myWarmUpEvent, myWarmUpIndicator, myWarmUpOption, myWarmUpPriority, NONE, REMOVED_FROM_MODEL, REPLICATION_ENDED, TIME_UNIT_DAY, TIME_UNIT_HOUR, TIME_UNIT_MILLISECOND, TIME_UNIT_MINUTE, TIME_UNIT_SECOND, TIME_UNIT_WEEK, TIMED_UPDATE, UPDATE, WARMUP
-
-
Constructor Summary
Constructors Constructor Description ResourceSet(ModelElement parent)Creates a resource set with the given model element as a parent and assigned a default name.ResourceSet(ModelElement parent, java.lang.String name)Creates a resource set with the given model element as a parent and the given name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResourceaddResource()Creates and adds a resource to the setResourceaddResource(int capacity)Creates and adds a resource to the setResourceaddResource(int capacity, java.lang.String name)Creates and adds a resource to the setvoidaddResource(Resource resource)Adds a resource to the set.protected voidaddWaitingRequest(Request request)Adds the request to the list of waiting requests based on the Comparable interface for Requestjava.lang.StringasString()Allows sub-classes to provide more detail than toString() to represent the ModelElement as a StringintgetMaxCapacity()intgetNumberAvailableResources()Returns the current number of idle resources in the setjava.util.ListIterator<Resource>getResourceIterator()Returns an iterator to the resources in this setResourceSelectionRuleIfcgetResourceSelectionRule()Returns the current resource selection rule or null if nonebooleanhasAvailableResources()protected voidinitialize()This method should be overridden by subclasses that need actions performed to initialize prior to a replication.protected RequestpeekNextRequest()Returns the next request without removing itprotected voidprocessWaitingRequests()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.protected RequestremoveNextRequest()Removes the next request from the waiting list of requestsprotected voidremoveWaitingRequest(Request request)Removes the request from the list of waiting requestsprotected voidresourceBecameAvailable(Resource resource)When a resource becomes available it needs to be added to the list of available resourcesprotected voidresourceBecameUnavailable(Resource resource)If a resource within the set becomes unavailable (busy, failed, inactive) it should be removed from the potential list of availabe resources.Requestseize(Entity entity, int amtNeeded, boolean partialFillFlag, AllocationListenerIfc listener)Requestseize(Entity entity, int amtNeeded, int priority, boolean partialFillFlag, AllocationListenerIfc listener)Requestseize(Entity entity, int amtNeeded, int priority, boolean partialFillFlag, AllocationListenerIfc listener, ResourceSelectionRuleIfc rule)Requestseize(Entity entity, int amtNeeded, int priority, AllocationListenerIfc listener)Requestseize(Entity entity, int amtNeeded, AllocationListenerIfc listener)Requestseize(Entity entity, AllocationListenerIfc listener)voidseize(Request request)Seizes the resource using the request.ResourceselectAvailableResource(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.ResourceselectAvailableResource(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.voidsetResourceSelectionRule(ResourceSelectionRuleIfc rule)Sets the resource selection rule.-
Methods inherited from class jsl.simulation.ModelElement
addObserver, addObserverToModelElements, afterExperiment, afterExperiment_, afterReplication, afterReplication_, beforeExperiment, beforeExperiment_, beforeReplication, beforeReplication_, buildEventGenerator, cancelTimedUpdateEvent, cancelWarmUpEvent, changeParentModelElement, checkForAfterExperiment, checkForAfterReplication, checkForBeforeExperiment, checkForBeforeReplication, checkForConditionalActionRegistration, checkForInitialize, checkForMonteCarlo, checkForRemoveFromModel, checkForReplicationEnded, checkForTimedUpdate, checkForUpdate, checkForWarmUp, checkObserverState, checkWarmUpOption, clearModelElementObservers, contains, countObservers, createEntity, createEntity, createQObject, day, deleteObserver, deleteObserverFromModelElements, deleteObservers, findModelElementWithWarmUpEvent, getAfterExperimentOption, getAfterReplicationOption, getAllCounters, getAllModelElements, getAllRandomElements, getAllResponseVariables, getAllVariables, getBeforeExperimentOption, getBeforeReplicationOption, getChildModelElementIterator, getCurrentReplicationNumber, getDefaultEntityType, getExecutive, getExperiment, getId, getInitializationOption, getInitializationOrderAsString, getLeftPreOrderTraversalCount, getLengthOfWarmUp, getModel, getModelElementCompartor, getModelElementsAsString, getModelElementsAsString, getModelElementsAsString, getMonteCarloOption, getName, getNumberOfModelElements, getObserverState, getParentModelElement, getPreviousObserverState, getReplicationEndedOption, getRightPreOrderTraversalCount, getSimulation, getSpatialModel, getStringLabel, getThisElementsCounters, getThisElementsModelElements, getThisElementsRandomVariables, getThisElementsResponseVariables, getThisElementsVariables, getTime, getTimedUpdateInterval, getTimedUpdateOption, getUpdateNotificationFlag, getVariable, getWarmUpEventTime, getWarmUpOption, hour, indent, initialize_, isTimedUpdateEventScheduled, isWarmedUp, isWarmUpEventScheduled, isWarmUpScheduled, millisecond, minute, montecarlo, montecarlo_, notifyAfterExperimentObservers, notifyAfterReplicationObservers, notifyBeforeExperimentObservers, notifyBeforeReplicationObservers, notifyConditionalActionRegistrationObservers, notifyInitializationObservers, notifyMonteCarloObservers, notifyObservers, notifyObservers, notifyRemovingFromModelObservers, notifyReplicationEndedObservers, notifyTimedUpdateObservers, notifyUpdateObservers, notifyWarmUpObservers, registerConditionalActions, registerConditionalActions_, removedFromModel, removeFromModel, replicationEnded, replicationEnded_, schedule, second, seize, setAfterExperimentOption, setAfterExperimentOptionForModelElements, setAfterReplicationOption, setAfterReplicationOptionForModelElements, setBeforeExperimentOption, setBeforeExperimentOptionForModelElements, setBeforeReplicationOption, setBeforeReplicationOptionForModelElements, setInitializationOption, setInitializationOptionForModelElements, setLengthOfWarmUp, setModel, setMonteCarloOption, setMonteCarloOptionForModelElements, setName, setObserverState, setParentModelElement, setReplicationEndedOption, setReplicationEndedOptionForModelElements, setSpatialModel, setStringLabel, setTimedUpdateInterval, setTimedUpdateOption, setTimedUpdateOptionForModelElements, setUpdateNotificationFlag, setWarmUpOption, setWarmUpOptionForModelElements, stopExecutive, stopExecutive, timedUpdate, timedUpdate_, toString, update, useControls, warmUp, warmUp_, week
-
-
-
-
Field Detail
-
CYCLICAL
public static final ResourceSelectionRuleIfc CYCLICAL
-
myResources
protected java.util.List<Resource> myResources
-
myAvailableResources
protected java.util.List<Resource> myAvailableResources
-
myResourceSelectionRule
protected ResourceSelectionRuleIfc myResourceSelectionRule
-
myNumAvailableResources
protected TimeWeighted myNumAvailableResources
-
myWaitingRequests
protected OrderedList<Request> myWaitingRequests
-
-
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:ModelElementThis 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:
initializein classModelElement
-
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:SeizeIfcSeizes 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.
-
seize
public final Request seize(Entity entity, AllocationListenerIfc listener)
-
seize
public final Request seize(Entity entity, int amtNeeded, int priority, AllocationListenerIfc listener)
-
seize
public final Request seize(Entity entity, int amtNeeded, AllocationListenerIfc listener)
-
seize
public final Request seize(Entity entity, int amtNeeded, boolean partialFillFlag, AllocationListenerIfc listener)
-
seize
public final Request seize(Entity entity, int amtNeeded, int priority, boolean partialFillFlag, AllocationListenerIfc listener)
-
seize
public final Request seize(Entity entity, int amtNeeded, int priority, boolean partialFillFlag, AllocationListenerIfc listener, ResourceSelectionRuleIfc rule)
-
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:ModelElementAllows sub-classes to provide more detail than toString() to represent the ModelElement as a String- Overrides:
asStringin classModelElement- 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.
-
-