Skip to main content

DoubleBufferedQueue<T>

A class in Alta.Api.Client, Alta.Api.Client.LowLevel.

Two queues that swap: entries collect in one until a timer runs out or it is full, then it is passed to ProcessQueue and the other takes new entries. Used by ApiBatchRequestService (30 s, 100 entries).

Constructors​

MemberWhat it is
DoubleBufferedQueue(int lifetimeMs, int maxEntries)Creates a DoubleBufferedQueue from lifetimeMs and maxEntries.

Fields​

7 private and internal fields
MemberWhat it is
private DoubleBufferedQueue<T> activeQueueWhich queue takes new entries.
private readonly object enqueueLockLock held while adding an entry.
private readonly Queue<T> primaryQueueThe first of the two queues.
private readonly int queueMaxEntriesEntry count above which a queue is flushed early.
private readonly Timer queueTimerTimer that flushes the active queue after the lifetime set in the constructor.
private readonly Queue<T> secondaryQueueThe second of the two queues.
private readonly object swapLockLock held while swapping and flushing.

Properties​

MemberWhat it is
Action<IEnumerable<T>> ProcessQueue { get; set; }Callback given the full or expired queue.

Methods​

MemberWhat it is
void Enqueue(T entry)Adds an entry to the active queue, flushing first if it is full, and starts the timer.
5 private and internal methods
MemberWhat it is
private bool IsQueueFull(Queue<T> queue)True when the queue holds more than queueMaxEntries.
private void OnQueueExpired(object sender, ElapsedEventArgs e)Swaps the active queue, passes the old one to ProcessQueue and stops the timer. Nothing here clears the old queue.
private void OnQueueExpired()Swaps the active queue, passes the old one to ProcessQueue and stops the timer. Nothing here clears the old queue.
private void SwapActiveQueue()Switches which queue takes new entries.
private async void WatchActiveQueue()Starts the timer if it is not running.

Used in​

Members of other types that take, return or hold a DoubleBufferedQueue&lt;T>: