ReservablePriorityReqFilterStore
¶
Bases: FilterStore
This is a class that is derived from SimPy's Store class and has extra capabilities that makes it a priority-based reservable store for processes to reserve space for storing and retrieving items with priority-based access. It supports user tp only get items that match a user criteria
Processes can use reserve_put() and reserve_get() methods to get notified when a space becomes available in the store or when an item gets available in the ReservablePriorityReqStore. These methods returns a unique event (SimPy.Event) to the process for every reserve requests it makes. Processes can also pass a priority as argument in the request. Lower values indicate higher priority. Filter to be used while using "get" can be passed in the reserve_get request.
get and put are two methods that can be used for item storing and retrieval from ReservablePriorityReqStore.
Process has to make a prior reservation and pass the associated reservation event as argument in the get and
put requests. ReservablePriorityReqStore maintains separate queues for reserve_put
and reserve_get
operations
to ensures that only processes with valid reservations can store or retrieve items.
ReservablePriorityReqStore preserves item order by associating an unreserved item in the store with a reservation event by index when a reserve_get() request is made. As a result, it maintains a list of reserved events to preserve item order.
It also allows users to cancel an already placed reserve_get or reserve_put request even if it is yielded. It also handles the dissociation of the event and item done at the time of reservation when an already yielded event is canceled.
Attributes: |
|
---|
reserve_put(priority=0)
¶
Create a reservation request to put an item into the store.
This function generates a SimPy event representing a reservation request. The event is
assigned attributes such as priority, resource name, and the process making the request.
The event is then added to reserve_put_queue
, which is maintained in priority order.
After adding the event to the queue, _trigger_reserve_put
is called to process
any pending reservations.
Parameters: |
|
---|
Returns: |
|
---|
reserve_put_cancel(put_event_to_cancel)
¶
Cancel a previously made reserve_put
request.
This method allows a process to cancel its reservation for putting an item
into the store. If the reservation exists in the reserve_put_queue
, it is
removed before triggering _trigger_reserve_put
to process any pending reservations.
If the reservation is already in reservations_put
, it is also removed and
_trigger_reserve_put
is triggered.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
reserve_get_cancel(get_event_to_cancel)
¶
Cancel a previously made reserve_get
request.
This method allows a process to cancel its reservation for retrieving an item
from the store. If the reservation exists in the reserve_get_queue
, it is removed,
and _trigger_reserve_get()
is called to process any remaining reservations.
If the reservation is already in reservations_get
, it is removed, and the corresponding
item is repositioned in the store to maintain order. _trigger_reserve_get()
is then
triggered to handle pending reservations.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
reserve_get(priority=0, filter=None)
¶
Create a reservation request to retrieve an item from the store.
This method generates a SimPy event representing a request to reserve an item
for retrieval (get
). The event is assigned attributes such as priority,
the resource it belongs to, and the process making the request.
The event is then added to reserve_get_queue
, which is maintained in
priority order, and _trigger_reserve_get()
is called to process pending
reservations if items are available.
Parameters: |
|
---|
Returns: |
|
---|
get(get_event)
¶
Retrieve an item from the store after a successful reservation.
This method attempts to retrieve an item associated with a reserve_get
event. If the reservation exists, it triggers _trigger_get
to retrieve
the item. If successful, _trigger_reserve_put
is called to process any
pending reserve_put
requests. If the item retrieval fails, an error
message is raised.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|
put(put_event, item)
¶
Perform a put
operation on the store and trigger any pending reserve_get
requests.
Ensures that only processes with a valid reservation can put items into the store.
If the put operation succeeds, it triggers _trigger_reserve_get
to process pending get requests.
Parameters: |
|
---|
Returns: |
|
---|
Raises: |
|
---|