Kinetica   C#   API  Version 7.2.3.1
WorkerQueue.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 
4 
5 namespace kinetica.Utils;
6 
7 internal sealed class WorkerQueue<T>
8  {
9  public System.Uri url { get; private set; }
10  private readonly int capacity;
11  private List<T> queue;
12 
13 
18  public WorkerQueue( System.Uri url )
19  {
20  this.url = url;
21  this.capacity = 1;
22 
23  queue = [];
24  } // end constructor WorkerQueue<T>
25 
26 
27 
35  public WorkerQueue(System.Uri url, int capacity, bool hasPrimaryKey, bool updateOnExistingPk)
36  {
37  this.url = url;
38  this.capacity = capacity;
39 
40  queue = [];
41 
42  // Note: hasPrimaryKey and updateOnExistingPk parameters are reserved for future
43  // primary key deduplication functionality but not currently implemented.
44  } // end constructor WorkerQueue<T>
45 
46 
47 
52  public IList<T> flush()
53  {
54  IList<T> old_queue = this.queue;
55  queue = new List<T>(this.capacity);
56 
57  return old_queue;
58  } // end flush
59 
60 
61 
69  public IList<T>? insert(T record, RecordKey key)
70  {
71  queue.Add(record);
72  // If the queue is full, then flush and return the 'old' queue
73  if (queue.Count == capacity)
74  return flush();
75  else // no records to return
76  return null;
77  } // end insert
78  } // end class WorkerQueue
IList< T >? insert(T record, RecordKey key)
Inserts a record into the queue (if all conditions are favourable).
Definition: WorkerQueue.cs:69
IList< T > flush()
Returns the current queue and creates a new empty one.
Definition: WorkerQueue.cs:52
WorkerQueue(System.Uri url)
Creates an insertion queue for a given worker.
Definition: WorkerQueue.cs:18
A binary key used for shard routing.
Definition: RecordKey.cs:16
WorkerQueue(System.Uri url, int capacity, bool hasPrimaryKey, bool updateOnExistingPk)
Creates an insertion queue for a given worker.
Definition: WorkerQueue.cs:35
System.Uri url
Definition: WorkerQueue.cs:9