Resource
A Resource represents a number of common units that can be allocated to entities. A resource has an initial capacity that can be changed during a replication.
A resource is busy if at least 1 unit has been allocated. A resource becomes busy when it has allocations. If a seize-request occurs and the resource has capacity to fill it completely, then the request is allocated the requested amount. If insufficient capacity is available at the time of the request, then the request waits until the requested units can be allocated.
If b(t) is the number of units allocated at time t, and c(t) is the current capacity of the resource, then the number of available units, a(t), is defined as a(t) = c(t) - b(t). Thus, a resource is idle if a(t) = c(t). Since a resource is busy if b(t) > 0, busy and idle are complements of each other. A resource is either busy b(t) > 0 or idle b(t) = 0. If a(t) > 0, then the resource has units that can be allocated.
The utilization of a resource is defined as the ratio of the average number of busy units to the average number of active units. Units are active if they are part of the current capacity of the resource.
Subclasses of Resource implement additional state behavior.
Parameters
the parent holding this resource
the name of the resource
the initial capacity of the resource. Cannot be changed during a replication. The default capacity is 1.
Inheritors
Types
Properties
Whether each replication starts the behavior. With false, a replication starts without it and startBehavior starts it when the model wants it, so an experiment can compare runs with and without the behavior. Set while the model is not running.
The process of the running behavior, so that another process can interrupt its delays (for example with interruptDelay); null when no behavior is running.
Access to the busy state. Busy means at least 1 unit of the resource is allocated.
The default rule is IGNORE. This can be changed via the useSchedule() function or when there is no schedule being used. The rule cannot be changed when there are pending capacity changes.
Returns the default reporting option. True means that the response should appear on the default reports
A resource can be allocated to 0 or more entities. An entity that is using a resource can have more than 1 allocation of the resource. The key to this map represents the entities that are using the resource. The element of this map represents the list of allocations allocated to the entity.
Access to the failed state. Failed means that no units of the resource can be allocated until it is repaired. An implementation that cannot fail keeps the default, a state that is never entered.
If a(t) is greater than zero
True if a behavior, of either form, has been declared for this resource.
If b(t) is greater than zero
True if failures have been declared with failures.
Access to the idle state. Idle means that no units of the resource are allocated.
Access to the inactive state. Inactive means that the capacity of the resource is 0
The initial capacity of the resource at the start of the replication. The initial capacity must be greater than 0.
The initial request queue notification rule for controlling the order in which queues are notified for processing requests after a capacity change.
If b(t) is the number of busy units, and c(t) is the current capacity, then the instantaneous utilization iu(t) is
What happens to work in service when this resource's units are taken away, by a failure or by a more urgent request: FINISH (the default) lets it complete, RESUME holds the holder's delay and goes on with the time left, RESTART holds it and starts it again in full. A failure or a preemption can override it for itself. Set while the model is not running.
True while the behavior is running in this replication, from its activation until it ends: by returning from its block, by a stop, by the model terminating its process (as clearing the queue it waits in does), or at the end of the replication.
True when a stop after the current cycle has been asked for and the cycle has not yet finished.
True when some units are allocated, whatever the capacity, and the resource is not failed. A resource whose capacity has just gone to zero stays busy until its allocated units are released. A failed resource is in the failed state even with units allocated (see isFailed), so it is neither busy nor idle.
True when no units are allocated and the capacity is zero, as when a resource is off shift and its last unit has been released.
True while this resource has been taken off shift with goOffShift.
Indicates whether capacity changes are pending. The resource cannot allocate units when capacity changes are pending because released busy units will be used to fill the capacity change.
The number of consecutive cycles of a cyclic behavior that may end at the simulated time they began; one more is taken to be looping without waiting, and throws. Large enough for a legitimate burst, such as a cycle that takes each of many messages already waiting. Set while the model is not running; at least 1.
The busy state, keeps track of when the resource has an allocation A resource is busy if any of its units are allocated.
Tracks which queues have requests targeting the resource
The failed state, keeps track of when no units are available because the resource is failed. It takes precedence over the other three until the resource is repaired.
The idle state keeps track of when no units have been allocated
The inactive state, keeps track of when no units are available because the resource's capacity is zero.
The units that can be allocated now: the capacity less the busy units and less any units held for a reservation still collecting them. None while the resource is failed.
Statistical response representing the number of busy units of the resource.
The number of preemptions of this resource in the replication: each preempt that took units from at least one holder, or reserved them from holders that finish their work.
The number of times that the resource has been released (deallocated)
The number of times that the resource has been seized (allocated)
When the pending capacity change ends. NaN when no change is pending (see isPendingCapacityChange). Positive infinity when the pending change lasts until another change supersedes it (a notice with an infinite duration, as shift changes use), or when its end is not yet known because, under the WAIT rule, it is still waiting for busy units to be released.
The last (previous) state before the current state.
Changing this during a replication will only affect the current replication. The rule will be reset to the initial setting at the beginning of each replication.
Statistical response representing the utilization of the resource. This is the time average number of busy units divided by the time average capacity: the utilization of the capacity actually on shift.
The number of allocations made from the resource: one per allocation whatever its amount, including direct allocate() calls. It counts starts of service, not completions or throughput.
A general attribute that can be used to assist with selecting resources
Time when state time accumulation started. May be greater than 0 because of warmup.
The current state of the resource.
Indicates if proportion of time spent in states (idle, busy, inactive) is automatically reported
time average instantaneous utilization (see instantaneousUtil): time with no capacity counts as zero when no unit is busy, and as one while units are still busy. Under a capacity schedule it generally differs from scheduledUtil, which divides the average busy by the average capacity, and either can be the larger.
Total time that the resource has been idle, busy, or inactive
Functions
Add an allocation listener. Allocation listeners are notified when (after) units are allocated to an entity and after units are deallocated.
It is essential that subclasses that override this function call the super. This ensures that suspended entities are cleaned up after a replication
Called when this resource's units come back by other than a release: at the end of a capacity increase, including the one a goOnShift makes, and of a repair, and at a goOnShift that raises no capacity because the capacity was put back directly while off shift. It is called once for each, except under CapacityChangeRule.WAIT when the return to shift waits behind a decrease still in progress: then once at the return and once when the increase is made. It is not called once the run has ended. A subclass whose waiting requests are not reached by the offer to the resource's own queues offers its units here.
Notifies any attached listeners when units are allocated, once the change is complete.
Declares a behavior whose block runs once from time 0 of every replication, for a set-up that is not a cycle, such as a delayed start. Otherwise as cyclicBehavior, which is the usual form; a block that loops by itself cannot be stopped after its current cycle or guarded against a cycle that never waits.
A resource may fill a request in many ways. This function indicates if the request for the amount needed can be allocated immediately, without any wait based on the current state of the resource. Since the underlying state of the resource may be more complex than indicated by the state exposed in the API, it is important to use this method to determine if the requested amount can be allocated.
Represents the actions that occur when a capacity change's duration is completed.
It is an error to try to change the capacity directly via this method if the resource is using a capacity change schedule.
Called by cyclicBehavior and behavior before a behavior is stored. A subclass that cannot have a behavior in some state (an agent resource with a statechart) throws here.
Adds two statistics for this resource's failures, whether they come from failures or from calls of fail: the proportion of time it is failed (PTimeFailed) and the number of failures in a replication (NumFailures). Without them the failed state still keeps its own times, and no element is added to the model. Called while the model is not running; a second call does nothing.
Declares a behavior that the library repeats: block is one cycle, run again as soon as it ends, from time 0 of every replication. This is the usual form of a resource's own behavior, such as a break taken every so often:
Notifies any attached listeners when units are deallocated, once the change is complete.
A resource without a behavior has nothing for behaviorActiveAtStart to switch, so it is not a control.
Fails this resource now: no unit can be allocated until repair, and the requests waiting for it go on waiting. Its holders meet rule: under FINISH they complete their work, and the units they release are kept from the waiting requests until the repair; under RESUME and RESTART all their units go missing, so a holder's delay that depends on them is held, and a delay it starts while failed begins held. The capacity is unchanged, and capacity changes and shifts still apply underneath. A resource that is already failed throws; isFailed is the check.
Declares that this resource fails and is repaired on its own, in every replication: it waits out timeBetween on basis, fails under rule, stays failed for repairTime, and is repaired, over and over. A failure that comes due while the resource is already failed by a call of fail waits for that repair, and its time between failures starts again from there. A call of repair during the repair time ends that failure early, and the time to the next failure counts from that repair. The declared failures repair only a failure they started: if the model fails the resource again during what was the repair time, that failure lasts until the model repairs it. The waiting is done by an entity of the resource's own, separate from a behavior it may have.
Takes this resource off shift until goOnShift: its capacity goes to zero, so new seize requests wait in their queues. Work already allocated finishes under the resource's capacityChangeRule, IGNORE by default: a unit that is busy finishes its current allocation, and when it is released it goes to the off-shift change, not to the next waiting request. A second call while off shift does nothing.
Brings this resource back on shift, restoring the initialCapacity it had when this replication's first goOffShift was made. The requests waiting for it are offered the units as for any capacity increase. Nothing happens when the resource is on shift.
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
Checks if the entity is using (has allocated units) of the resource.
Computes the number of different allocations of the resource held by the entity. Recall that allocations can be for different amounts.
Declares what to do after the behavior is stopped by stopBehavior, to put back what it changed, for example bringing the resource back on shift when a break was cut short. It does not suspend. It does not run when the behavior ends on its own or when a replication ends. A second call replaces the first. Declared while the model is not running.
Resources can be associated with a capacity change schedule. If a capacity change occurs, especially a decrease that makes the resource inactive or an increase that allows the resource to be available occurs, then queues that hold requests for the resource may want to be notified of the capacity change.
Removes the listener
Repairs this resource: the units its holders lost come back (a held delay goes on, or starts again under RESTART), the resource takes the state its capacity and busy units give, and its available units are offered to the waiting requests as for a capacity increase. A resource that is not failed throws; isFailed is the check.
This method should be overridden by subclasses that need actions performed when the replication ends and prior to the calling of afterReplication(). It is called when each replication ends and can be used to collect data from the model element, etc.
This function is called from the InactiveState when the state is exited. The current behavior is to do nothing. That is, the normal operation of the resource occurs. This function can be used by subclasses to inject logic into this event.
This function is called from the InactiveState when the state is entered. The purpose of this function is to permit the notification of entities that may have requests waiting in a queue that is supported by the resource that became inactive. There might not be requests in the queue by the entity when the resource becomes inactive; however, if there are, then the entity may want to not have the request wait during the inactive period. This allows the entity to react to this situation.
A trigger for units of this resource, for use in a wait for the first of several things (waitForFirst). The trigger fires when the request it places in queue is served while the wait is open, or at once when the units can be allocated and no waiting request would be chosen first, as seize takes them. Its value is the allocation, made when the request is served and returned when the process resumes, as seize makes it; release it as any other. While the wait is open the request waits in queue as a seize request does. If the wait ends otherwise, the request leaves the queue.
Starts the behavior again at the current time, after the calling event, as a fresh process with fresh local state. It must have been declared, the model must be running, and it must not be running already; isBehaviorActive is the check.
Stops the running behavior. With BehaviorStop.AFTER_CYCLE (the default) a cyclic behavior finishes its current cycle and starts no other; a second such call before the cycle ends throws, and isBehaviorStopRequested is the check. With BehaviorStop.NOW, and for a behavior declared with behavior, it ends at once: its process is terminated, releasing anything it holds and running its finally blocks, and a stop not yet begun cancels its start. A stop NOW after a pending AFTER_CYCLE is allowed. Then the action given to onBehaviorStopped runs.
If the resource is using a schedule, the resource stops listening for capacity changes and is no longer using a schedule. The current capacity will be used for the remainder of the replication.
Computes the total number of units of the specified resource that are allocated to the entity.
Unregisters a queue from this resource, so that units freed on it are no longer offered to the requests in queue. If the queue was not registered, nothing occurs.
Assigns the state the capacity and the busy units give, even when it is unchanged, as each change of either always has. While failed it does nothing: the failed state takes precedence until repair.
Tells the resource to listen and react to capacity changes in the supplied Schedule. The model cannot be running when changing the schedule.