Package jsl.modeling.elements.entity
Class ResourceProvider
- java.lang.Object
-
- jsl.simulation.ModelElement
-
- jsl.simulation.SchedulingElement
-
- jsl.modeling.elements.entity.ResourceProvider
-
- All Implemented Interfaces:
ObservableIfc
,GetNameIfc
,IdentityIfc
public class ResourceProvider extends SchedulingElement
-
-
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 protected jsl.modeling.elements.entity.ResourceProvider.EndServiceListener
myEndServiceListener
protected Queue<Entity>
myEntityQ
A queue to hold waiting requests when an idle resource is not immediately available.protected EntitySelectionRuleIfc
myEntitySelectionRule
Can be used to supply a rule for how the requests are selected for allocationprotected EntitySelectionRuleIfc
myInitialRequestSelectionRule
Can be used to supply a rule for how the requests are selected for allocationprotected TimeWeighted
myNS
protected ResourceSet
myResourceSet
The resource set used by this provider to ask for and and return idle resourcesprotected RandomVariable
myServiceRV
The service time when using the providerprotected ResponseVariable
myWs
-
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 ResourceProvider(ModelElement parent)
Creates a ResourceProviderr that uses a FIFO queue discipline.ResourceProvider(ModelElement parent, java.lang.String name)
Creates a ResourceProviderr that uses a FIFO queue discipline.ResourceProvider(ModelElement parent, java.lang.String name, ResourceSet set)
Creates a ResourceProvider that uses the supplied set and FIFO queue disciplineResourceProvider(ModelElement parent, java.lang.String name, ResourceSet set, Queue.Discipline discipline)
Creates a ResourceProvider that uses the supplied set and queue disciplineResourceProvider(ModelElement parent, ResourceSet set)
Creates a ResourceProvider that uses the supplied set and FIFO queue disciplineResourceProvider(ModelElement parent, ResourceSet set, Queue.Discipline discipline)
Creates a ResourceProvider that uses the supplied set and queue discipline
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Resource
addResource()
Adds a resource with unit capacity to the underlying resource setResource
addResource(int capacity)
Adds a resource with the given capacity to the underlying resource setResource
addResource(int capacity, java.lang.String name)
Adds a resource with the given capacity and name to the underlying resource setvoid
addResource(Resource resource)
Adds the given resource to the underlying set of the providerprotected void
allocated(Request request)
void
changeQueueDiscipline(Queue.Discipline discipline)
This will change the queue discipline of the underlying Queueprotected void
endOfService(Allocation a)
EntitySelectionRuleIfc
getInitialRequestSelectionRule()
The rule to use when this provider is initializedint
getNumberInQueue()
Returns the current number of requests in the queueint
getNumberOfIdleResources()
Returns the current number of idle resources within the underlying resource setQueue.Discipline
getQueueInitialDiscipline()
Returns the initial discipline for the queueEntitySelectionRuleIfc
getRequestSelectionRule()
Returns a reference to the request selection rule.ResourceSet
getResourceSet()
Returns a reference to the resource set used within the providerprotected void
initialize()
This method should be overridden by subclasses that need actions performed to initialize prior to a replication.void
seize(Entity entity)
void
seize(Entity entity, int amtNeeded)
void
seize(Entity entity, int amtNeeded, int priority)
void
seize(Entity entity, int amtNeeded, int priority, boolean partialFillFlag)
The client asks the ResourceProvider to seize the given amount of the resource.protected Entity
selectNextEntity()
Selects a candidate request from the queue for allocation to one of the resources.void
setInitialRequestSelectionRule(EntitySelectionRuleIfc rule)
The rule to use when this provider is initializedvoid
setQueueInitialDiscipline(Queue.Discipline discipline)
Sets the initial queue disciplinevoid
setRequestSelectionRule(EntitySelectionRuleIfc rule)
A request selection rule can be supplied to provide alternative behavior within the selectNextRequest() method.protected void
setResourceSet(ResourceSet set)
void
setServiceTime(RandomIfc d)
-
Methods inherited from class jsl.simulation.SchedulingElement
cancelEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, rescheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent, scheduleEvent
-
Methods inherited from class jsl.simulation.ModelElement
addObserver, addObserverToModelElements, afterExperiment, afterExperiment_, afterReplication, afterReplication_, asString, 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
-
myResourceSet
protected ResourceSet myResourceSet
The resource set used by this provider to ask for and and return idle resources
-
myEntityQ
protected Queue<Entity> myEntityQ
A queue to hold waiting requests when an idle resource is not immediately available.
-
myServiceRV
protected RandomVariable myServiceRV
The service time when using the provider
-
myInitialRequestSelectionRule
protected EntitySelectionRuleIfc myInitialRequestSelectionRule
Can be used to supply a rule for how the requests are selected for allocation
-
myEntitySelectionRule
protected EntitySelectionRuleIfc myEntitySelectionRule
Can be used to supply a rule for how the requests are selected for allocation
-
myEndServiceListener
protected jsl.modeling.elements.entity.ResourceProvider.EndServiceListener myEndServiceListener
-
myNS
protected final TimeWeighted myNS
-
myWs
protected ResponseVariable myWs
-
-
Constructor Detail
-
ResourceProvider
public ResourceProvider(ModelElement parent)
Creates a ResourceProviderr that uses a FIFO queue discipline. An empty ResourceSet is created and must be filled- Parameters:
parent
-
-
ResourceProvider
public ResourceProvider(ModelElement parent, java.lang.String name)
Creates a ResourceProviderr that uses a FIFO queue discipline. An empty ResourceSet is created and must be filled- Parameters:
parent
-name
-
-
ResourceProvider
public ResourceProvider(ModelElement parent, java.lang.String name, ResourceSet set)
Creates a ResourceProvider that uses the supplied set and FIFO queue discipline- Parameters:
parent
-name
-set
-
-
ResourceProvider
public ResourceProvider(ModelElement parent, ResourceSet set)
Creates a ResourceProvider that uses the supplied set and FIFO queue discipline- Parameters:
parent
-set
-
-
ResourceProvider
public ResourceProvider(ModelElement parent, ResourceSet set, Queue.Discipline discipline)
Creates a ResourceProvider that uses the supplied set and queue discipline- Parameters:
parent
-set
-discipline
-
-
ResourceProvider
public ResourceProvider(ModelElement parent, java.lang.String name, ResourceSet set, Queue.Discipline discipline)
Creates a ResourceProvider that uses the supplied set and queue discipline- Parameters:
parent
-name
-set
-discipline
-
-
-
Method Detail
-
setServiceTime
public void setServiceTime(RandomIfc d)
-
getResourceSet
public final ResourceSet getResourceSet()
Returns a reference to the resource set used within the provider- Returns:
-
addResource
public final Resource addResource()
Adds a resource with unit capacity to the underlying resource set- Returns:
-
addResource
public final Resource addResource(int capacity)
Adds a resource with the given capacity to the underlying resource set- Parameters:
capacity
-- Returns:
-
addResource
public Resource addResource(int capacity, java.lang.String name)
Adds a resource with the given capacity and name to the underlying resource set- Parameters:
capacity
-name
-- Returns:
-
addResource
public final void addResource(Resource resource)
Adds the given resource to the underlying set of the provider- Parameters:
resource
-
-
getNumberOfIdleResources
public final int getNumberOfIdleResources()
Returns the current number of idle resources within the underlying resource set- Returns:
-
changeQueueDiscipline
public final void changeQueueDiscipline(Queue.Discipline discipline)
This will change the queue discipline of the underlying Queue- Parameters:
discipline
-
-
getQueueInitialDiscipline
public final Queue.Discipline getQueueInitialDiscipline()
Returns the initial discipline for the queue- Returns:
-
setQueueInitialDiscipline
public final void setQueueInitialDiscipline(Queue.Discipline discipline)
Sets the initial queue discipline- Parameters:
discipline
-
-
getNumberInQueue
public final int getNumberInQueue()
Returns the current number of requests in the queue- Returns:
-
getRequestSelectionRule
public final EntitySelectionRuleIfc getRequestSelectionRule()
Returns a reference to the request selection rule. May be null.- Returns:
-
setRequestSelectionRule
public final void setRequestSelectionRule(EntitySelectionRuleIfc rule)
A request selection rule can be supplied to provide alternative behavior within the selectNextRequest() method. A request selection rule, provides a mechanism to select the next request from the queue of waiting requests- Parameters:
rule
-
-
getInitialRequestSelectionRule
public final EntitySelectionRuleIfc getInitialRequestSelectionRule()
The rule to use when this provider is initialized- Returns:
-
setInitialRequestSelectionRule
public final void setInitialRequestSelectionRule(EntitySelectionRuleIfc rule)
The rule to use when this provider is initialized
-
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 classModelElement
-
setResourceSet
protected final void setResourceSet(ResourceSet set)
-
selectNextEntity
protected Entity selectNextEntity()
Selects a candidate request from the queue for allocation to one of the resources. The selection process does not remove the request from the queue.- Returns:
- The request that was selected to for a resource
-
seize
public void seize(Entity entity)
-
seize
public void seize(Entity entity, int amtNeeded)
-
seize
public void seize(Entity entity, int amtNeeded, int priority)
-
seize
public void seize(Entity entity, int amtNeeded, int priority, boolean partialFillFlag)
The client asks the ResourceProvider to seize the given amount of the resource. The entity associated with the request immediately enters the providers queue. If there is an idle resource available that can be used to allocate to the request then the request is processed. If the request can be satisfied in full it is removed from the queue and the units of the resource are allocated to it. If it cannot be allocated in full, it is checked to see if it allows partial filling, if so the available units of the resource are allocated to it, but it remains in the queue. NOTE: It is up to the ResourceAllocationListenerIfc to check if the request is still in the queue or if it has been satisfied before proceeding. The amount requested must not exceed the maximum capacity of the underlying resource set.- Parameters:
entity
-amtNeeded
-priority
-partialFillFlag
-
-
allocated
protected void allocated(Request request)
-
endOfService
protected void endOfService(Allocation a)
-
-