Kinetica   C#   API  Version 7.2.3.0
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 readonly bool has_primary_key;
12  private readonly bool update_on_existing_pk;
13  private List<T> queue;
14  private Dictionary<RecordKey, int> primary_key_map;
15 
16 
21  public WorkerQueue( System.Uri url )
22  {
23  this.url = url;
24  this.capacity = 1;
25 
26  queue = [];
27  } // end constructor WorkerQueue<T>
28 
29 
30 
38  public WorkerQueue(System.Uri url, int capacity, bool has_primary_key, bool update_on_existing_pk)
39  {
40  this.url = url;
41  this.capacity = capacity;
42 
43  queue = [];
44 
45  } // end constructor WorkerQueue<T>
46 
47 
48 
53  public IList<T> flush()
54  {
55  IList<T> old_queue = this.queue;
56  queue = new List<T>(this.capacity);
57 
58  return old_queue;
59  } // end flush
60 
61 
62 
70  public IList<T>? insert(T record, RecordKey key)
71  {
72  queue.Add(record);
73  // If the queue is full, then flush and return the 'old' queue
74  if (queue.Count == capacity)
75  return flush();
76  else // no records to return
77  return null;
78  } // end insert
79  } // end class WorkerQueue
80 
81 } // end namespace kinetica.Utils
A key based on a given record that serves as either a primary key or a shard key.
Definition: RecordKey.cs:13
WorkerQueue(System.Uri url)
Creates an insertion queue for a given worker.
Definition: WorkerQueue.cs:21
WorkerQueue(System.Uri url, int capacity, bool has_primary_key, bool update_on_existing_pk)
Creates an insertion queue for a given worker.
Definition: WorkerQueue.cs:38
IList< T > flush()
Returns the current queue and creates a new empty one.
Definition: WorkerQueue.cs:53
IList< T >? insert(T record, RecordKey key)
Inserts a record into the queue (if all conditions are favourable).
Definition: WorkerQueue.cs:70