Kinetica C# API  Version 7.1.10.0
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Pages
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 int capacity;
11  private bool has_primary_key;
12  private bool update_on_existing_pk;
13  private IList<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 = new List<T>();
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 = new List<T>();
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