Files
spark/src/DataStreamSuite/DataStreamCore/Messaging/Publish/SinglePubTableBroker.cs
T
John Colvin f2ace4ae32 refactor: Decouple PubTableBroker from IPublisherCore impl
Reference interface rather than the PublisherCore impl.
2025-11-03 16:13:18 -05:00

55 lines
2.3 KiB
C#

using bts;
using System;
using System.Collections;
using System.IO;
namespace BCG {
/// <summary>
/// The only instance of IPubTableBroker. It handles the publishing of one tag, and holds a specialized serializer
/// that it initializes according to the table, to optimize serialiazation, hence bw and performance
/// This class is held (as an interface) by the PubTableBroker, which guarantees the sanity of calls,
/// ie the first call will always be create.
/// </summary>
public class SinglePubTableBroker {
private readonly string _tag;
protected IStreamIOMsgSerializer _serializer;
protected IPublisherCore _publisher_core;
public SinglePubTableBroker(string tag, IPublisherCore publisher_core) {
bts.Log.Gen.info($"SinglePubTableBroker.cons created for tag: {tag}");
_tag = tag;
_publisher_core = publisher_core;
_serializer = new UniversalStreamIOSerializer();
}
public void create_table(IBlueRowCollection rows) {
bts.StreamIOMessage.CreateMessage cr_msg = new bts.StreamIOMessage.CreateMessage(rows);
bts.StreamIOMessage stream_io_msg = new bts.StreamIOMessage(cr_msg);
byte[] msg_bytes = _serializer.serialize(stream_io_msg);
PublishMsg pub_msg = new PublishMsg() {
tag = DSTagManager.get_stream_tag(rows.schema.tableName),
tag_type = DSTagManager.DataStreamTagType,
data_to_publish = msg_bytes
};
PubSubClientMessage msg = new PubSubClientMessage(pub_msg);
_publisher_core.publish(msg);
}
public void make_batch_changes(IBlueRowCollection del_rows, IBlueRowCollection added_rows) {
bts.StreamIOMessage.MultipleRemoveAddMessage mra_msg =
new bts.StreamIOMessage.MultipleRemoveAddMessage(del_rows, added_rows);
bts.StreamIOMessage stream_io_msg = new bts.StreamIOMessage(mra_msg);
byte[] msg_bytes = _serializer.serialize(stream_io_msg);
PublishMsg pub_msg = new PublishMsg() {
tag = DSTagManager.get_stream_tag(added_rows.schema.tableName),
tag_type = DSTagManager.DataStreamTagType,
data_to_publish = msg_bytes
};
PubSubClientMessage msg = new PubSubClientMessage(pub_msg);
_publisher_core.publish(msg);
}
}
}