From ee4e011611eb5108802b2b9dd639a778d4d2d0e2 Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Thu, 29 Feb 2024 22:12:08 -0500 Subject: [PATCH 1/2] Meta tags work now --- .../SystemStatsPublisher.cs | 4 +- .../SystemSubscriptionMapPublisher.cs | 16 ++++++- .../PubSub/Server/PubSubMessageReactor.cs | 17 +++++-- .../PubSub/Server/PubSubState.cs | 46 ++++++++++--------- .../Subscription/PubSubServerStateStream.cs | 3 +- 5 files changed, 56 insertions(+), 30 deletions(-) diff --git a/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemStatsPublisher.cs b/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemStatsPublisher.cs index c47d2ce25..08ec4bb5d 100644 --- a/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemStatsPublisher.cs +++ b/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemStatsPublisher.cs @@ -67,9 +67,11 @@ namespace BCG { _dirty_tags.Clear(); var bytes = TagStatsInfo.serialize(dirty_ts_info); PublishMsg pub_msg = new PublishMsg() { - connection = "InternalPublish", + connection = "Internal", + publishing_app = "PubSubServer", tag = SystemStatsPublisher.tag_name, tag_type = SystemStatsPublisher.tag_type, + publish_time_epoch_ms = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), data_to_publish = bytes }; PubSubMessageReactor.internal_publish(pub_msg); diff --git a/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemSubscriptionMapPublisher.cs b/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemSubscriptionMapPublisher.cs index f7a01f311..6a50fa273 100644 --- a/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemSubscriptionMapPublisher.cs +++ b/src/DataStreamSuite/PubSub/Server/InternalTagHandling/SystemSubscriptionMapPublisher.cs @@ -50,7 +50,15 @@ namespace BCG { } private void _on_tag_state_changes(string[] tags) { - bts.Log.Gen.info($"SystemSubscriptionMapPublisher._on_tag_state_changes len: {tags.Length}"); + Func tags_to_string = () => { + var rv = String.Empty; + foreach (var t in tags) { + rv += t + " "; + } + rv.Trim(); + return rv; + }; + bts.Log.Gen.info($"SystemSubscriptionMapPublisher._on_tag_state_changes tags: {tags_to_string()}"); _dirty_tags.AddRange(tags); } @@ -68,7 +76,11 @@ namespace BCG { _dirty_tags.Clear(); var ser_bytes = TagPubSubInfo.serialize(tpsis); PublishMsg pub_msg = new PublishMsg() { - publish_time_epoch_ms = 0, + connection = "Internal", + publishing_app = "PubSubServer", + tag = tag_name, + tag_type = tag_type, + publish_time_epoch_ms = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), is_compressed = false, data_to_publish = ser_bytes }; diff --git a/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs b/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs index ca27c30d6..411b31c73 100644 --- a/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs +++ b/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs @@ -85,7 +85,7 @@ namespace BCG { Action handle_internal_pubs = () => { var internal_pubs = _internal_pub_queue.dequeueMultipleElements(1, 64000); foreach (var msg in internal_pubs) - _handle_pub("Internal", msg); + _handle_pub("Internal", msg, true); }; while (true) { @@ -124,7 +124,7 @@ namespace BCG { _handle_transaction(sender, ps_client_msg.transaction_msg); break; case PubSubMessageType.PUBLISH: - _handle_pub(sender, ps_client_msg.pub_msg); + _handle_pub(sender, ps_client_msg.pub_msg, false); break; } } @@ -153,9 +153,9 @@ namespace BCG { } } - private void _handle_pub(string sender, PublishMsg pub_msg) { + private void _handle_pub(string sender, PublishMsg pub_msg, bool is_internal_pub) { bts.Log.assert(!pub_msg.is_compressed); - bts.Log.Gen.info($"PubSubMessageReactor._handle_pub sender: {sender} pub_msg: {pub_msg}"); + bts.Log.Gen.info($"PubSubMessageReactor._handle_pub sender: {sender} pub_msg: {pub_msg} is_internal_pub: {is_internal_pub}"); // this is where pubsub's data state is updated _state.update_pub_data(pub_msg); var sub_connections_for_tag = _state.get_subscriber_connections_for_tag(pub_msg.tag); @@ -191,6 +191,15 @@ namespace BCG { //private static PubsSubM public static void internal_publish(PublishMsg msg) { bts.Log.Gen.info($"PubsubMessageReactor.internal_publish msg: {msg}"); + // if (String.IsNullOrEmpty(msg.tag)) { + // var b = true; + // while (b) { + // System.Threading.Thread.Sleep(250); + // Console.WriteLine("caught it !!"); + // } + // //bts.Log.Gen.info($"PubsubMessageReactor.internal_publish msg: {msg}"); + // } + bts.Log.assert(!String.IsNullOrEmpty(msg.tag)); _internal_pub_queue.enqueue(msg); } diff --git a/src/DataStreamSuite/PubSub/Server/PubSubState.cs b/src/DataStreamSuite/PubSub/Server/PubSubState.cs index 527dfd1fb..75e74be39 100644 --- a/src/DataStreamSuite/PubSub/Server/PubSubState.cs +++ b/src/DataStreamSuite/PubSub/Server/PubSubState.cs @@ -180,30 +180,32 @@ namespace BCG { // } public void update_pub_data(bts.PublishMsg pub_msg) { - // TODO - // int sz = (int)(msg.Length - msg.Position); - bts.Log.Gen.info($"PubSubData.update_pub_data pub_msg: {pub_msg}"); - ///this is the only place where SingleTagData should be created - if (!_tag_to_data_map.ContainsKey(pub_msg.tag)) { - ///first time data is published for this tag - _tag_to_data_map.Add(pub_msg.tag, new SingleTagData(pub_msg.tag, pub_msg.tag_type)); - } - _tag_to_data_map[pub_msg.tag].handle_publish(pub_msg); + try { + bts.Log.Gen.info($"PubSubData.update_pub_data pub_msg: {pub_msg}"); + ///this is the only place where SingleTagData should be created + if (!_tag_to_data_map.ContainsKey(pub_msg.tag)) { + ///first time data is published for this tag + _tag_to_data_map.Add(pub_msg.tag, new SingleTagData(pub_msg.tag, pub_msg.tag_type)); + } + _tag_to_data_map[pub_msg.tag].handle_publish(pub_msg); - if (!_tag_to_connection_map.ContainsKey(pub_msg.tag)) { - _tag_to_connection_map.Add(pub_msg.tag, new SingleTagConnectionData(pub_msg.tag)); - } - bool pub_changed = false; - _tag_to_connection_map[pub_msg.tag].handle_pub(pub_msg, out pub_changed); - if (pub_changed) { - if (onTagMapChanged != null) - onTagMapChanged(new string[] { pub_msg.tag }); + if (!_tag_to_connection_map.ContainsKey(pub_msg.tag)) { + _tag_to_connection_map.Add(pub_msg.tag, new SingleTagConnectionData(pub_msg.tag)); + } + bool pub_changed = false; + _tag_to_connection_map[pub_msg.tag].handle_pub(pub_msg, out pub_changed); + if (pub_changed) { + if (onTagMapChanged != null) + onTagMapChanged(new string[] { pub_msg.tag }); - if (onSingleTagChange != null) - onSingleTagChange( - new PubSubSingleTagStateEvent(pub_msg.tag, - PubSubSingleTagStateEvent.EventType.publish, - pub_msg.connection, pub_msg.publishing_app)); + if (onSingleTagChange != null) + onSingleTagChange( + new PubSubSingleTagStateEvent(pub_msg.tag, + PubSubSingleTagStateEvent.EventType.publish, + pub_msg.connection, pub_msg.publishing_app)); + } + } catch (Exception ex) { + bts.Log.Gen.error($"PubSubState.update_pub_data ex: {ex} pub_msg: {pub_msg}"); } if (onPublishStats != null) onPublishStats(pub_msg.tag, pub_msg.data_to_publish.Length); diff --git a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs index b4c929b3e..6ec046d62 100644 --- a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs +++ b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs @@ -27,6 +27,7 @@ namespace BCG { // TODO, construct schema _schema = BlueDataUtility.form_schema("pubsub_server_state", Tuple.Create("id", TypeCode.Int32), + Tuple.Create("tag", TypeCode.String), Tuple.Create("ps_server", TypeCode.String), Tuple.Create("subscibers", TypeCode.String), Tuple.Create("publisher", TypeCode.String), @@ -71,7 +72,7 @@ namespace BCG { var sorted_tags = _tag_map.Keys.OrderBy(t => t); foreach (var kv in _tag_map) { var tsi = kv.Value; - IBlueRow r = new BlueRow(_schema, bt.Count, tsi.pubsub_server, tsi.subscribers_as_string, + IBlueRow r = new BlueRow(_schema, bt.Count, tsi.tag, tsi.pubsub_server, tsi.subscribers_as_string, tsi.publishers_as_string, tsi.dead_publishers_as_string); bt.addRow(r); } From a1de0faac95a2ef777982770593d0dfb5cd5c15a Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Wed, 6 Mar 2024 14:19:12 -0500 Subject: [PATCH 2/2] Removing unused files --- .../PubSubServerManagedTCPConnection.cs | 8 +- .../PubSub/Client/MetaData/MetaData.cs | 150 ------------------ .../PubSub/Client/MetaData/PubMetaData.cs | 91 ----------- .../PubSub/Client/MetaData/RenewMetaData.cs | 25 --- .../PubSub/Client/MetaData/SubMetaData.cs | 28 ---- .../Client/MetaData/TransactionMetaData.cs | 24 --- .../PubSub/Client/MetaData/UnSubMetaData.cs | 17 -- src/DataStreamSuite/PubSub/PubSubMessage.cs | 42 ----- .../Server/Governors/IPubSubGovernor.cs | 20 --- .../Server/Governors/PermissiveGovernor.cs | 20 --- .../PubSub/Server/SingleTagConnectionData.cs | 53 ------- 11 files changed, 4 insertions(+), 474 deletions(-) delete mode 100644 src/DataStreamSuite/PubSub/Client/MetaData/MetaData.cs delete mode 100644 src/DataStreamSuite/PubSub/Client/MetaData/PubMetaData.cs delete mode 100644 src/DataStreamSuite/PubSub/Client/MetaData/RenewMetaData.cs delete mode 100644 src/DataStreamSuite/PubSub/Client/MetaData/SubMetaData.cs delete mode 100644 src/DataStreamSuite/PubSub/Client/MetaData/TransactionMetaData.cs delete mode 100644 src/DataStreamSuite/PubSub/Client/MetaData/UnSubMetaData.cs delete mode 100644 src/DataStreamSuite/PubSub/PubSubMessage.cs delete mode 100644 src/DataStreamSuite/PubSub/Server/Governors/IPubSubGovernor.cs delete mode 100644 src/DataStreamSuite/PubSub/Server/Governors/PermissiveGovernor.cs diff --git a/src/DataStreamSuite/PubSub/Client/Communication/ManagedTCP/PubSubServerManagedTCPConnection.cs b/src/DataStreamSuite/PubSub/Client/Communication/ManagedTCP/PubSubServerManagedTCPConnection.cs index 93b6077cd..5a5b9790d 100644 --- a/src/DataStreamSuite/PubSub/Client/Communication/ManagedTCP/PubSubServerManagedTCPConnection.cs +++ b/src/DataStreamSuite/PubSub/Client/Communication/ManagedTCP/PubSubServerManagedTCPConnection.cs @@ -97,10 +97,10 @@ namespace BCG { // send(msg.to_stream()); // } - public void send_with_confirmation(PubSubMessage msg, ref string conf_id) { - var bytes = msg.to_bytes(); - send_with_confirmation(bytes, ref conf_id); - } + // public void send_with_confirmation(PubSubMessage msg, ref string conf_id) { + // var bytes = msg.to_bytes(); + // send_with_confirmation(bytes, ref conf_id); + // } public void send_with_confirmation(bts.PubSubClientMessage msg, ref string conf_id, SendConfirmationDelegate del) { if (_connection == null) { diff --git a/src/DataStreamSuite/PubSub/Client/MetaData/MetaData.cs b/src/DataStreamSuite/PubSub/Client/MetaData/MetaData.cs deleted file mode 100644 index ac4d7c952..000000000 --- a/src/DataStreamSuite/PubSub/Client/MetaData/MetaData.cs +++ /dev/null @@ -1,150 +0,0 @@ -using System; -using System.Runtime.Serialization; -using System.Collections; -using System.Reflection; -using System.IO; -using System.Text; - - -using BCG; -using System.Collections.Generic; - -namespace BCG { - // Thhis "wraps" around the following 4 PubSub meta objects, serializes it on the client and - // deserialize it on the pubsub - // PubMetaData - // SubMetaData - // TransactionMetaData - // UnSubMetaData - // - public class MetaData : ICloneable { - private IDictionary _name_value_map = new Dictionary(); - int mySize = -1; - - public MetaData() { } - - public MetaData(object o) { copyFrom(o); } - - public MetaData(Stream s) { - long initPos = s.Position; - load(s); - mySize = Convert.ToInt32(s.Position - initPos); - } - - public string this[string name] { - get { return (string)_name_value_map[name]; } - set { - if (value != null) - _name_value_map[name] = value; - } - } - - private void _add_string_array(string name, string[] values) { - StringBuilder sb = new StringBuilder(); - foreach (string s in values) { - if (sb.Length != 0) - sb.Append(" "); - sb.Append(s); - } - _name_value_map[name] = sb.ToString(); - } - - private int getAsInt(string name) { return Int32.Parse(this[name]); } - - private string[] _get_as_string_array(string name) { - if (this[name] != "" && this[name] != null) - return this[name].Split(' '); - else - return new string[0]; - } - - public int size() { - if (mySize < 0) { - MemoryStream ms = new MemoryStream(); - this.save(ms); - return mySize = (int)ms.Position; - } else - return mySize; - } - - private bool isEqual(MetaData md) { - if (md._name_value_map.Keys.Count != _name_value_map.Keys.Count) - return false; - - foreach (string k in _name_value_map.Keys) - if (!_name_value_map[k].Equals(md._name_value_map[k])) - return false; - return true; - } - - // loads the content of the stream into this instance's map - private void load(Stream s) { - _name_value_map = new Hashtable(); - string[] state = - new BinaryReader(s).ReadString().Split('\n'); - - for (int i = 0; i < state.Length - 1; i += 2) - _name_value_map[state[i]] = state[i + 1]; - } - - // writes the content of this instance to stream s - public void save(Stream s) { - new BinaryWriter(s).Write(this.ToString()); - } - - public override string ToString() { - StringBuilder sb = new StringBuilder(); - foreach (string key in _name_value_map.Keys) - sb.AppendFormat("{0}\n{1}\n", key, _name_value_map[key]); - return sb.ToString(); - } - - // iterates through the fields and enters the name, values into _hash - public void copyFrom(object o) { - this["op-code"] = o.GetType().Name; - foreach (FieldInfo fi in o.GetType().GetFields()) { - if (fi.GetValue(o) == null) - continue; - else if (fi.GetValue(o) is String[]) - _add_string_array(fi.Name, (string[])fi.GetValue(o)); - else - _name_value_map[fi.Name] = fi.GetValue(o).ToString(); - - } - } - // copies the name value map into object o - public void copyTo(object o) { - foreach (FieldInfo fi in o.GetType().GetFields()) { - string value = this[fi.Name]; - if (value == null) { - } else { - if (fi.FieldType.Equals(typeof(string))) - fi.SetValue(o, value); - else if (fi.FieldType.Equals(typeof(int))) - fi.SetValue(o, Int32.Parse(value)); - else if (fi.FieldType.Equals(typeof(long))) - fi.SetValue(o, long.Parse(value)); - else if (fi.FieldType.Equals(typeof(double))) - fi.SetValue(o, double.Parse(value)); - else if (fi.FieldType.Equals(typeof(DateTime))) - fi.SetValue(o, DateTime.Parse(value)); - else if (fi.FieldType.Equals(typeof(Boolean))) - fi.SetValue(o, Boolean.Parse(value)); - else if (fi.FieldType.Equals(typeof(TimeSpan))) - fi.SetValue(o, TimeSpan.Parse(value)); - else if (fi.FieldType.Equals(typeof(String[]))) - fi.SetValue(o, value.Split(' ')); - else - throw new Exception("Field type not supported"); - } - } - } - - public object Clone() { - MemoryStream ms = new MemoryStream(); - this.save(ms); - ms.Seek(0, SeekOrigin.Begin); - return new MetaData(ms); - } - } -} diff --git a/src/DataStreamSuite/PubSub/Client/MetaData/PubMetaData.cs b/src/DataStreamSuite/PubSub/Client/MetaData/PubMetaData.cs deleted file mode 100644 index 13ab4bbdf..000000000 --- a/src/DataStreamSuite/PubSub/Client/MetaData/PubMetaData.cs +++ /dev/null @@ -1,91 +0,0 @@ -using System; -//using BCG.Utilities.General; -//using BCG.Utilities.BlueConfiguration; -//using BCG.Utilities; - -namespace BCG -{ - - [Serializable] - public class PubMetaData - { - /// - /// tag to be subscribed - /// - public string tag; - /// - /// type of tag - /// - public string type; - /// - /// size of the data published - /// - public int size; - - /// - /// How big is the data when it's decompressed - /// - public int decompressedSize = 0; - - /// - /// is the data compressed? - /// - public bool isCompressed = false; - /// - /// identification of the publisher and the connection to the server to send the data - /// machine; ip; pid; serverURL - /// - public string connection; - - public string publishingApp; - - public long publishTimeTicks; - - public PubMetaData() {} - - public PubMetaData(string theTagType, string theTag, int theSize, string theConnection, string thePublishingApp) - : this(theTagType,theTag,theSize,theSize,theConnection,thePublishingApp) - { - isCompressed = false; - } - - public PubMetaData(string theTagType, string theTag, int theSize, int theDecompressedSize, string theConnection, string thePublishingApp) - { - type = theTagType; - tag = theTag; - size = theSize; - connection = theConnection; - publishingApp = thePublishingApp; - decompressedSize = theDecompressedSize; - isCompressed = true; - - publishTimeTicks = DateTime.Now.ToUniversalTime().Ticks; - myValidateTag(); - } - - //make sure the tag doesn't contain any newlines - private void myValidateTag() - { - if (tag.Contains("\n")) - throw new ArgumentException("Error: tag " + tag + " is not valid; tags cannot contain newlines."); - - } - - /// - /// Returns true if the ticks on this message are greater than the latency report threshold in config - /// - /// - public bool warnIfLatencyExceedsThreshold() - { - DateTime publishTime = new DateTime(publishTimeTicks); - double elapsedSeconds = (DateTime.Now.ToUniversalTime() - publishTime).TotalMilliseconds; - if (elapsedSeconds > PubSub3Config.instance.PS3_LatencyReportThresholdMS) - { - //BlueEventLog.logEvent(string.Concat("Recieved pub message on tag ", tag, " ", elapsedSeconds, " milliseconds after the publisher ",publishingApp," sent it."), PS3LogLevels.latency); - return true; - } - return false; - } - - } -} diff --git a/src/DataStreamSuite/PubSub/Client/MetaData/RenewMetaData.cs b/src/DataStreamSuite/PubSub/Client/MetaData/RenewMetaData.cs deleted file mode 100644 index a55b4a111..000000000 --- a/src/DataStreamSuite/PubSub/Client/MetaData/RenewMetaData.cs +++ /dev/null @@ -1,25 +0,0 @@ -// using System; - -// namespace BCG -// { -// [Serializable] -// public class RenewMetaData -// { -// public string subscriber; -// public int lease; -// public bool c; - -// public SubAddress getSubAddress() -// {return SubAddress.decode(subscriber);} - -// public RenewMetaData() -// {} - -// public RenewMetaData(string s, -// int lease) -// { -// this.subscriber = s; -// this.lease = lease; -// } -// } -// } diff --git a/src/DataStreamSuite/PubSub/Client/MetaData/SubMetaData.cs b/src/DataStreamSuite/PubSub/Client/MetaData/SubMetaData.cs deleted file mode 100644 index 6c09a4c55..000000000 --- a/src/DataStreamSuite/PubSub/Client/MetaData/SubMetaData.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; - -namespace BCG { - //[Serializable] - public class SubMetaData { - /// - /// connection URL on which the connection will receive data - /// - public string connection; - /// - /// identification of the client and the connection on which to receive data - /// machine; ip; port; clientURL - /// - public readonly string subscribing_app = ClientInfo.thisClient.processString; - /// - /// tags that are to be subscribed - /// - public string[] tags; - - public SubMetaData() { } - - public SubMetaData(string the_connection, params string[] the_tags) { - connection = the_connection; - tags = the_tags; - //subscribing_app = ClientInfo.thisClient.processString; - } - } -} diff --git a/src/DataStreamSuite/PubSub/Client/MetaData/TransactionMetaData.cs b/src/DataStreamSuite/PubSub/Client/MetaData/TransactionMetaData.cs deleted file mode 100644 index 722c6dfa0..000000000 --- a/src/DataStreamSuite/PubSub/Client/MetaData/TransactionMetaData.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BCG -{ - /// - /// when a publisher sends transactional data to the pubsub server, - /// this is the first meta data, followed by pub messages. this indicated - /// the number of messages that are part of the transaction - /// - [Serializable] - public class TransactionMetaData - { - public int nMessages; - - public TransactionMetaData() { } - - public TransactionMetaData(int theNMessages) - { - nMessages = theNMessages; - } - } -} diff --git a/src/DataStreamSuite/PubSub/Client/MetaData/UnSubMetaData.cs b/src/DataStreamSuite/PubSub/Client/MetaData/UnSubMetaData.cs deleted file mode 100644 index deb98d8d8..000000000 --- a/src/DataStreamSuite/PubSub/Client/MetaData/UnSubMetaData.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; - -namespace BCG { - //[Serializable] - public class UnSubMetaData { - public string connection; - public readonly string[] tags; - public readonly string unsubscribing_app = ClientInfo.thisClient.processString; - - public UnSubMetaData() { } - - public UnSubMetaData(string the_connection, params string[] the_tags) { - connection = the_connection; - tags = the_tags; - } - } -} diff --git a/src/DataStreamSuite/PubSub/PubSubMessage.cs b/src/DataStreamSuite/PubSub/PubSubMessage.cs deleted file mode 100644 index db0aaa5a5..000000000 --- a/src/DataStreamSuite/PubSub/PubSubMessage.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.IO; - -using BCG; -using BCG.Utilities; - -namespace BCG { - // PubItems are published to the pubsub wrapped in this class. It contains PubMetaData, wrapped in the MetaData - // object and the actualy published payload in the body stream - public class PubSubMessage { - public PubSubMessage(MetaData metaData, Stream body) { this.meta_data = metaData; this.body = body; } - - public PubSubMessage(PubMetaData pub_meta_data, Stream body) - : this(new MetaData(pub_meta_data), body) { } - - public PubSubMessage(MetaData metaData) { this.meta_data = metaData; } - - public MetaData meta_data; - public Stream body = new MemoryStream(0); - - public Stream to_stream() { - MemoryStream ms = new MemoryStream(); - meta_data.save(ms); - if (body.Length == 0 || body.Length == body.Position) { - bts.Log.Gen.error("Error: Trying to publishing message with no content."); - Console.WriteLine("Error: Trying to publishing message with no content."); - } - StreamUtilityMethods.copyTo(new Stream[] { body }, ms); - ms.Position = 0; - return ms; - } - - public byte[] to_bytes() { - return StreamUtilityMethods.getBytesFromStream(to_stream()); - } - - public override string ToString() { - return $"PubSubMessage meta:data: {meta_data.ToString()} body.Posiiton: {body.Position} body.Length: {body.Length}"; - } - - } -} diff --git a/src/DataStreamSuite/PubSub/Server/Governors/IPubSubGovernor.cs b/src/DataStreamSuite/PubSub/Server/Governors/IPubSubGovernor.cs deleted file mode 100644 index 8c9bcd131..000000000 --- a/src/DataStreamSuite/PubSub/Server/Governors/IPubSubGovernor.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.IO; - -namespace BCG -{ - /* - * The PubSubGovernor accepts or rejects publishes to the pubsub - * if the governor rejects a publish attempt, the publish fails. - * Clients will not get the update and the state of the pubsub will not change. - * - */ - public enum PubSubGovernorResponse {Accepted, Rejected_ShouldBeImported, Rejected_ThisIsNotARootPubsub}; - public interface IPubSubGovernor - { - PubSubGovernorResponse requestToPublish(PubMetaData metaData, Stream pubData); - } -} diff --git a/src/DataStreamSuite/PubSub/Server/Governors/PermissiveGovernor.cs b/src/DataStreamSuite/PubSub/Server/Governors/PermissiveGovernor.cs deleted file mode 100644 index 0fc7477bf..000000000 --- a/src/DataStreamSuite/PubSub/Server/Governors/PermissiveGovernor.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace BCG -{ - public class PermissiveGovernor : IPubSubGovernor - { - public PermissiveGovernor() - { - - } - - public PubSubGovernorResponse requestToPublish(PubMetaData md, System.IO.Stream message) - { - return PubSubGovernorResponse.Accepted; - } - } -} diff --git a/src/DataStreamSuite/PubSub/Server/SingleTagConnectionData.cs b/src/DataStreamSuite/PubSub/Server/SingleTagConnectionData.cs index e4afc991f..a64288fff 100644 --- a/src/DataStreamSuite/PubSub/Server/SingleTagConnectionData.cs +++ b/src/DataStreamSuite/PubSub/Server/SingleTagConnectionData.cs @@ -77,25 +77,6 @@ namespace BCG { get { return _dead_pub_conn_to_app_map; } } - /// - /// Called by PubsubState when a subscription is made to this tag. - /// Returns a true, is the subscriber was not present, else logs - /// a warning and returns a false - /// - /// - /// - public bool onSub(SubMetaData sub) { - if (_sub_conn_to_app_map.ContainsKey(sub.connection)) { - string warningMsg = String.Format("tag {0} has already been subscribed by app {0}, subscriber {1}" - + "it should unsubscribe before resubscribing", _tag, sub.connection, sub.subscribing_app); - //BlueEventLog.logEvent(warningMsg, BlueEventLevel.Warning); - return false; - } else { - _sub_conn_to_app_map.Add(sub.connection, sub.subscribing_app); - return true; - } - } - public bool handle_sub(SubscribeMsg sub_msg) { if (_sub_conn_to_app_map.ContainsKey(sub_msg.connection)) { bts.Log.Gen.info($"tag: {_tag} has already been subscribed by connection: {sub_msg.connection}"); @@ -106,25 +87,6 @@ namespace BCG { } } - /// - /// Called by PubsubState when a subscriber unsubscribes to this tag. - /// Returns a true when a subscriber exists, else logs a warning and - /// returns a false - /// - /// - /// - public bool onUnsub(UnSubMetaData unsub) { - if (_sub_conn_to_app_map.ContainsKey(unsub.connection)) { - _sub_conn_to_app_map.Remove(unsub.connection); - return true; - } else { - string warningMsg = String.Format("tag {0} has already was either unsubscribed or never subscribed by app {0}, subscriber {1}", - _tag, unsub.connection, unsub.unsubscribing_app); - //BlueEventLog.logEvent(warningMsg, BlueEventLevel.Warning); - return false; - } - } - public bool handle_unsub(UnsubscribeMsg unsub_msg) { if (_sub_conn_to_app_map.ContainsKey(unsub_msg.connection)) { _sub_conn_to_app_map.Remove(unsub_msg.connection); @@ -159,21 +121,6 @@ namespace BCG { return rv; } - /// - /// Called by pubsubState, when this tag is published. if publisher - /// has changed, the out paramater is set to true - /// - /// - /// - public void onPub(PubMetaData pub, out bool newPublisher) { - if (_active_pub_conn_to_app_map.ContainsKey(pub.connection)) { - newPublisher = false; - } else { - _active_pub_conn_to_app_map.Add(pub.connection, pub.publishingApp); - newPublisher = true; - } - } - public void handle_pub(PublishMsg pub_msg, out bool new_publisher) { if (_active_pub_conn_to_app_map.ContainsKey(pub_msg.connection)) { new_publisher = false;