Class PriorityQueue
- Namespace
- Sportradar.LiveData.Sdk.Services.PriorityQueue
- Assembly
- Sportradar.LiveData.Sdk.dll
Simple priority queue implementation supporting only fixed number of priorities. Under the hood it is implemented as N x FIFO queue where elements are ordered by time of arrival. This means that PriorityQueueElt comparison operator is not in use here. Might be extended with LimitedPriorityQueue or replaced by SafePriorityQueue. This is a thread-safe implementation.
public class PriorityQueue : IPriorityQueue
- Inheritance
-
PriorityQueue
- Implements
- Derived
- Inherited Members
Constructors
PriorityQueue(ISdkLogger)
public PriorityQueue(ISdkLogger sdk_logger)
Parameters
sdk_loggerISdkLogger
Fields
m_item_sema
Semaphore that is set every time a new item is enqueued
protected SemaphoreSlim m_item_sema
Field Value
m_queue_name
protected string m_queue_name
Field Value
m_queue_stats
protected IQueueTimeStats m_queue_stats
Field Value
m_queues
Queues on which the priority queue is based.
protected List<Queue<PriorityQueueElt>> m_queues
Field Value
m_sdk_logger
protected ISdkLogger m_sdk_logger
Field Value
Properties
Count
Number of items in the queue.
public virtual int Count { get; }
Property Value
Name
Priority queue name
public string Name { get; set; }
Property Value
QueueStats
Queue statistic (total, daily, hourly, minutely). Various avg/min/max performance queue counters.
public IQueueTimeStats QueueStats { get; }
Property Value
Methods
Clear()
Empties the queue.
public virtual void Clear()
Dequeue()
Dequeues an object from the priority queue. Returns null if the queue is empty
public virtual PriorityQueueElt Dequeue()
Returns
- PriorityQueueElt
The top item (max priority) from the queue or null if it does not exist.
Dequeue(Priority)
Dequeues an object of specific priority from the priority queue. Returns null if the queue is empty.
public virtual PriorityQueueElt Dequeue(Priority prio)
Parameters
prioPriorityPriority constraint
Returns
- PriorityQueueElt
The top item (max priority) from the queue or null if it does not exist.
Dequeue(Priority, TimeSpan)
Dequeues an object of specific priority from the priority queue.
public virtual PriorityQueueElt Dequeue(Priority prio, TimeSpan timeout)
Parameters
Returns
- PriorityQueueElt
The top item (max priority) from the queue. Returns null in case of timeout.
Dequeue(TimeSpan)
Dequeues an object from the priority queue.
public virtual PriorityQueueElt Dequeue(TimeSpan timeout)
Parameters
timeoutTimeSpanThe number of milliseconds to wait
Returns
- PriorityQueueElt
The top item (max priority) from the queue. Returns null in case of timeout.
Enqueue(PriorityQueueElt)
Enqueues an item to the priority queue.
public virtual void Enqueue(PriorityQueueElt elt)
Parameters
eltPriorityQueueElt
Peek()
Returns the value of the element at the top of the queue (highest priority) without removing it from the queue. Returns with null immediately if the queue is empty.
public virtual PriorityQueueElt Peek()
Returns
- PriorityQueueElt
The top item (max priority) from the queue or null if it does not exist.
Peek(TimeSpan)
Returns the value of the element at the top of the queue (highest priority) without removing it from the queue.
public virtual PriorityQueueElt Peek(TimeSpan timeout)
Parameters
timeoutTimeSpanThe number of milliseconds to wait
Returns
- PriorityQueueElt
The top item (max priority) from the queue or null if it doesn't exist.