Skip to main content

ApiBatchRequestService

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

Collects small API posts and sends them in batches: entries are queued and flushed every 30 seconds or at 100 entries, grouped by URI into one JSON list per URI.

Fields​

6 private and internal fields
MemberWhat it is
private static HttpClient authorizedClientHTTP client used to send batches; set by every Enqueue call.
private static bool isWatchingQueueUnused flag.
private static readonly Logger loggerClass logger.
private const int MaxQueueEntriesQueue size (100) that triggers a flush.
private const int MaxQueueLifetimeMsLongest time (30000 ms) entries wait before a flush.
private static DoubleBufferedQueue<BatchedRequestEntry> queueThe double-buffered queue holding pending entries.

Methods​

MemberWhat it is
static async void Enqueue(string uri, object data, HttpClient client)Queues data to be posted to uri in the next batch. The last client passed is the one used for sending.
4 private and internal methods
MemberWhat it is
private static void InitializeQueue()Creates the double-buffered queue on first use and hooks up ProcessQueue.
private static bool IsRequestValid(string uri, object data, HttpClient client)Rejects (with an error log) entries with a null client, empty URI or null data.
private static void ProcessQueue(IEnumerable<BatchedRequestEntry> queueToProcess)Queue flush callback; starts ProcessQueueInternal without waiting for it.
private static async Task ProcessQueueInternal(IEnumerable<BatchedRequestEntry> list)Groups queued entries by URI and posts each group as one JSON list.