This module provides queue containers for scheduler requests for the Robotics in Concert (ROCON) project.
This is a container class for ROCON scheduler request queue elements.
Parameters: | iterable – Iterable yielding initial contents, either QueueElement objects, or something that behaves similarly. |
---|
This implementation is based on the heapq module and uses some of the ideas explained in its priority queue implementation notes.
Returns: | The number of elements in the queue. |
---|
Param request: | (uuid.UUID or QueueElement) request to query. |
---|---|
Returns: | True if request is in the queue. |
Add a new element to the queue.
Parameters: |
|
---|
If a request with the same identifier was already in the queue, its old element is removed and replaced by the new element.
If a new priority is specified, the priority of the original request is updated. That is the only safe way to change the priority of an element that is already queued.
Warning
Changing priority via some other name for that request would break the queue implementation.
Return the top-priority element from the queue head without removing it.
Raises: | IndexError if queue was empty. |
---|
Remove the top-priority element from the queue head.
Raises: | IndexError if queue was empty. |
---|
Remove element corresponding to request_id.
Parameters: | request_id (uuid.UUID or QueueElement) – Identifier of the request to remove. |
---|---|
Raises: | KeyError if request_id not in the queue. |
Request queue element class.
Parameters: |
|
---|
Queue elements need fit into normal Python dictionaries, so they provide the required hash() operator, based on the unique ID of that request.
Returns: | (int) Hash signature for element. |
---|
Python 3 requires that hashable objects must also provide an equals operator. The hash signatures of equal requests must be equal.
Returns: | True if element and other have the same request ID (not their requester_id values). |
---|
Returns: | True if element and other do not have the same request ID. |
---|
Queue elements need to sort in the normal Python way, so they provide the required < operator. The __cmp__ method is not used, because Python 3 does not allow it. But, we want requests with higher-numbered priorities to sort ahead of lower priority ones, so heapq and other Python modules work properly.
Returns: | True if element has higher priority than other, or their priorities are the same and element has a lower sequence number. |
---|
This class does not provide a total ordering. The == and < operators test completely different fields. However, the request identifiers are unique, so no two valid queue elements should ever compare both equal and less, although that situation could be constructed artificially.
Returns: | String representation of this queue element, empty if it is not active. |
---|
Corresponding scheduler ActiveRequest object.
Unique sequence number of this queue element. All elements created earlier have lower numbers, those created afterward will be higher.
True unless this element has been removed from its queue.