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:
  • reserved_events (list) –

    Maintains events corresponding to reserved items to preserve item order by index

  • reserve_put_queue (list) –

    Queue for managing reserve_put reservations

  • reservations_put (list) –

    List of successful put reservations

  • reserve_get_queue (list) –

    Queue for managing reserve_get reservations

  • reservations_get (list) –

    List of successful get reservations

  • trigger_delay (int) –

    Delay time after which a trigger_reserve_get is called to allow waiting get calls to succeed.

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:
  • priority (int, default: 0 ) –

    The priority level of the reservation request. Lower values indicate higher priority. Defaults to 0.

Returns:
  • event( Event ) –

    A reservation event that will succeed when space is available.

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:
  • put_event_to_cancel (Event) –

    The reservation event that needs to be canceled.

Returns:
  • proceed( bool ) –

    True if the reservation was successfully canceled.

Raises:
  • RuntimeError

    If the specified event does not exist in reserve_put_queue or reservations_put.

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:
  • get_event_to_cancel (Event) –

    The reservation event that needs to be canceled.

Returns:
  • proceed( bool ) –

    True if the reservation was successfully canceled.

Raises:
  • RuntimeError

    If the specified event does not exist in reserve_get_queue or reservations_get.

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:
  • priority (int, default: 0 ) –

    The priority level of the reservation request. Lower values indicate higher priority. Defaults to 0.

  • filter (filter=lambdaitem=True, default: None ) –

    Filter to be used while using "reserve_get

Returns:
  • event( Event ) –

    A reservation event that will succeed when an item becomes available.

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:
  • get_event (Event) –

    The reservation event associated with the request.

Returns:
  • item( Object ) –

    The retrieved item if successful, otherwise raises an error

Raises:
  • RuntimeError

    If no reservations are available in the reservations_get

  • RuntimeError

    If item returned is None

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:
  • put_event (Event) –

    The event corresponding to the reservation.

  • item (object) –

    The item to be added to the store.

Returns:
  • proceed( bool ) –

    True if the put operation succeeded, False otherwise.

Raises:
  • RuntimeError

    If no reservations are available in the reservations_put

  • RuntimeError

    If proceed is False after put operation