Queueing
Preempting
Entities in Simulation Studio are hierarchical. That is, entities can hold other entities. The term controlling entity denotes an entity that holds other entities, and the term root entity denotes an entity that is not held by another entity. Each entity that is held by another entity has one root entity associated with it. The root entity for any held entity is found by moving up the entity hierarchy from the held entity.
Entities that are being held by a Queue block can be preempted either by input to the block’s InPreempt port or by a scheduled resource entity event. In order for a root entity that is held by a Queue block to be preempted, the OutPreempt port (or OutBalk port) must have at least one link attached to it. Similarly, for a resource entity that is held by a controlling entity that is in turn held by the Queue block to be preempted, the OutResource port (or OutBalk port) must have at least one link connected to it.
The Queue block’s InPreempt port accepts an Entity Group object as input. (An Entity Group is a collection of entity references.) When an Entity Group object is pushed to a Queue block’s InPreempt port, the Queue block iterates through the Entity Group collection, looking for matches to root entities held by the Queue block. For any matched entity, the Queue block first tries to push that entity out its OutPreempt port. If this push is not successful, the block attempts to push the entity out the OutBalk port. If this also fails, the entity continues to be held by the Queue block until it either exits the OutEntity port or is preempted again.
The Queue block, like all entity holding blocks, detects potential preemptive changes (such as those scheduled by a Resource Scheduler block) to resource entities that it holds (either directly or indirectly through a controlling entity). If the number of units that are associated with a held resource entity decreases or the state of a held resource entity becomes nonfunctional, the Queue block attempts to preempt that resource entity. If the resource entity that is identified for preemption is a root entity, then the Queue block follows the same protocol for pushing an entity out its OutPreempt port that the InPreempt port uses. If the resource entity is part of a controlling entity, the Queue block removes the resource entity from the controlling entity and attempts to push the associated root entity out the OutPreempt port. The Queue block then attempts to push the preempted resource entity out its OutResource port, or if that fails, out its OutBalk port. If there is a connection to the Queue block’s OutResource port and the block cannot push the resource entity out either the OutResource or OutBalk port, the resource entity is destroyed.
The Queue block also provides an OutHoldings port that other blocks can use to pull an Entity Group object that contains a collection of references to entities held by the Queue block.