Removing unused files

This commit is contained in:
Taha Afzal committed 2024-03-06 14:19:12 -05:00
1 parent ee4e011611
commit a1de0faac9
11 files changed
+4 -474

No files matched your search

@@ -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) {
@@ -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<string, string>();
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);
}
}
}
@@ -1,91 +0,0 @@
using System;
//using BCG.Utilities.General;
//using BCG.Utilities.BlueConfiguration;
//using BCG.Utilities;
namespace BCG
{
[Serializable]
public class PubMetaData
{
/// <summary>
/// tag to be subscribed
/// </summary>
public string tag;
/// <summary>
/// type of tag
/// </summary>
public string type;
/// <summary>
/// size of the data published
/// </summary>
public int size;
/// <summary>
/// How big is the data when it's decompressed
/// </summary>
public int decompressedSize = 0;
/// <summary>
/// is the data compressed?
/// </summary>
public bool isCompressed = false;
/// <summary>
/// identification of the publisher and the connection to the server to send the data
/// machine; ip; pid; serverURL
/// </summary>
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.");
}
/// <summary>
/// Returns true if the ticks on this message are greater than the latency report threshold in config
/// </summary>
/// <returns></returns>
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;
}
}
}
@@ -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;
// }
// }
// }
@@ -1,28 +0,0 @@
using System;
namespace BCG {
//[Serializable]
public class SubMetaData {
/// <summary>
/// connection URL on which the connection will receive data
/// </summary>
public string connection;
/// <summary>
/// identification of the client and the connection on which to receive data
/// machine; ip; port; clientURL
/// </summary>
public readonly string subscribing_app = ClientInfo.thisClient.processString;
/// <summary>
/// tags that are to be subscribed
/// </summary>
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;
}
}
}
@@ -1,24 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BCG
{
/// <summary>
/// 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
/// </summary>
[Serializable]
public class TransactionMetaData
{
public int nMessages;
public TransactionMetaData() { }
public TransactionMetaData(int theNMessages)
{
nMessages = theNMessages;
}
}
}
@@ -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;
}
}
}
@@ -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}";
}
}
}
@@ -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);
}
}
@@ -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;
}
}
}
@@ -77,25 +77,6 @@ namespace BCG {
get { return _dead_pub_conn_to_app_map; }
}
/// <summary>
/// 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
/// </summary>
/// <param name="sub"></param>
/// <returns></returns>
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 {
}
}
/// <summary>
/// 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
/// </summary>
/// <param name="unsub"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Called by pubsubState, when this tag is published. if publisher
/// has changed, the out paramater is set to true
/// </summary>
/// <param name="pub"></param>
/// <param name="publisherChanged"></param>
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;