Files
spark/src/DataStreamSuite/DataStream/Publish/CircularPublisher.cs
T
John Colvin b4cb6ac856 Add PubSub service modules designed for Dependency Injection
* Get rid of JsonPropertyName attributes in PubSubConfig
  - The Dependency Injection framework (based around dotnet ApplicationBuilder)
    does not support this attribute, and maps property names verbatim to json fields.

* Change PubSubServer json fields to match cs class property names verbatim
2025-11-03 16:13:18 -05:00

63 lines
2.1 KiB
C#

using Bts.DataStreamCore;
using System;
namespace BCG {
/// <summary>
/// Publishes the rows in the form of a circular buffer, ie if the buffer size is n
/// then the n'th row being puclished results in the deletion of the 0th row
/// </summary>
public class CircularPublisher {
private CircularRowCollection myBuffer;
private readonly IPubTableBroker myBroker;
private int myBufferSize;
public CircularPublisher(int bufferSize, IPubTableBroker broker) {
myBufferSize = bufferSize;
myBroker = broker;
}
public CircularPublisher(int bufferSize, IPubTableBroker broker, IBlueRowCollection rows)
: this(bufferSize, broker) {
publishRows(rows);
}
public void publishRow(IBlueRow nr) {
if (myBuffer == null) {
myBuffer = new CircularRowCollection(
new BlueTableSchema(nr.schema.tableName, nr.schema.columnInfo),
myBufferSize);
myBroker.create_table(myBuffer);
}
IBlueRow br = myBuffer.addRowWithReturn(nr);
myBroker.make_batch_changes(myBuffer,
myReturnCollection(br),
myReturnCollection(nr));
}
public void publishRows(IBlueRowCollection nrs) {
if (myBuffer == null) {
myBuffer = new CircularRowCollection(
new BlueTableSchema(BlueDataUtility.extractRow(nrs, 0).schema.tableName,
BlueDataUtility.extractRow(nrs, 0).schema.columnInfo),
myBufferSize);
myBroker.create_table(myBuffer);
}
BlueTable deletes = new BlueTable(myBuffer.schema);
foreach (IBlueRow nr in nrs) {
IBlueRow dr = myBuffer.addRowWithReturn(nr);
if (dr != null)
deletes.addRow(dr);
}
myBroker.make_batch_changes(myBuffer, deletes, nrs);
}
private IBlueRowCollection myReturnCollection(IBlueRow r) {
if (r == null)
return new BlueTable(myBuffer.schema);
BlueTable retVal = new BlueTable(r.schema);
retVal.addRow(r);
return retVal;
}
}
}