diff --git a/src/DataStreamSuite/DataStreamCore/ViewStreamDatabase.cs b/src/DataStreamSuite/DataStreamCore/ViewStreamDatabase.cs index 3588edd58..635d43c73 100644 --- a/src/DataStreamSuite/DataStreamCore/ViewStreamDatabase.cs +++ b/src/DataStreamSuite/DataStreamCore/ViewStreamDatabase.cs @@ -8,14 +8,12 @@ using System.Collections.Generic; using System.Threading; using mbts; -namespace BCG -{ +namespace BCG { using HighPerformanceTimer = mbts.spark.HighPerformanceTimer; - public class ViewStreamDatabase : IWorker, IDisposable - { + public class ViewStreamDatabase : IWorker, IDisposable { internal delegate void TagFireDelegate(string tag); - public delegate void DoWorkDelegate (); + public delegate void DoWorkDelegate(); public event DoWorkDelegate onDoWorkStart, onDoWorkEnd; internal event TagFireDelegate onTagFireStart, @@ -24,10 +22,10 @@ namespace BCG //and how big they are. //public delegate void OnTagUpdateDelegate(PubMetaData metaData); //public event OnTagUpdateDelegate onTagUpdate; - private IDictionary myITableAccumulatorMap = new Hashtable (); + private IDictionary myITableAccumulatorMap = new Hashtable(); private static ViewStreamDatabase mySelf; private ISubscriberCore mySubscriberCore; - private ArrayList myWorkers = new ArrayList (); + private ArrayList myWorkers = new ArrayList(); private bool myIsDisposed = false; private bool myIsInDoWork = false; private static object myTimeInterval; @@ -39,22 +37,18 @@ namespace BCG private static readonly object myInstanceLockObject = new object(); private readonly object myStateLock = new object(); - public ViewStreamDatabase () - : this (new SubscriberCore ()) - { + public ViewStreamDatabase() + : this(new SubscriberCore()) { } - public ViewStreamDatabase (ISubscriberCore subscriberCore) - { + public ViewStreamDatabase(ISubscriberCore subscriberCore) { mySubscriberCore = subscriberCore; // if (DataStreamLoadFileConfig.instance.profileStreams) // new DataStreamPerfRecorder(this); } - private static int myGetTimeInterval() - { - if (myTimeInterval == null) - { + private static int myGetTimeInterval() { + if (myTimeInterval == null) { // TODO string timeInterval = String.Empty; //ConfigurationRequester.request("viewStreamDatabaseTimeOut"); if (timeInterval == null || timeInterval == "") @@ -62,137 +56,130 @@ namespace BCG else myTimeInterval = Int32.Parse(timeInterval); } - return (int) myTimeInterval; + return (int)myTimeInterval; } public static int instance_hashcode = -1; - public static ViewStreamDatabase instance - { - get - { - if(mySelf == null || mySelf.myIsDisposed) - lock(myInstanceLockObject) - { - if (mySelf == null || mySelf.myIsDisposed) - { - mySelf = new ViewStreamDatabase(); - instance_hashcode = mySelf.GetHashCode(); + public static ViewStreamDatabase instance { + get { + if (mySelf == null || mySelf.myIsDisposed) + lock (myInstanceLockObject) { + if (mySelf == null || mySelf.myIsDisposed) { + mySelf = new ViewStreamDatabase(); + instance_hashcode = mySelf.GetHashCode(); + } } - } return mySelf; } - set - { - lock(myInstanceLockObject) - { + set { + lock (myInstanceLockObject) { if (mySelf != null) - mySelf.mySubscriberCore.Dispose (); + mySelf.mySubscriberCore.Dispose(); mySelf = value; instance_hashcode = mySelf.GetHashCode(); } } } - public ICollection getCachedTables() - { + public ICollection getCachedTables() { List result = new List(); - - - foreach (string s in myITableAccumulatorMap.Keys) - if (((ITableAccumulator)myITableAccumulatorMap[s]).isActive()) - result.Add(s); - + + + foreach (string s in myITableAccumulatorMap.Keys) + if (((ITableAccumulator)myITableAccumulatorMap[s]).isActive()) + result.Add(s); + return result; } - public ISubscriberCore subscriber{get{return mySubscriberCore;}} - - - public ITableAccumulator getITableAccumulator (string tableName) - { + public ISubscriberCore subscriber { get { return mySubscriberCore; } } + + + public ITableAccumulator getITableAccumulator(string tableName) { // If theres a ITableAccumulator for the tableName its returned (to share subscriptions), otherwise // a new one is obtained from the Subscriber factory - - myITableAccumulatorMap[tableName] = myITableAccumulatorMap[tableName] == null ? - AccumulatorFactory.getAccumulator(tableName, mySubscriberCore) : myITableAccumulatorMap[tableName]; - - return myITableAccumulatorMap [tableName] as ITableAccumulator; + + myITableAccumulatorMap[tableName] = myITableAccumulatorMap[tableName] == null ? + AccumulatorFactory.getAccumulator(tableName, mySubscriberCore) : myITableAccumulatorMap[tableName]; + + return myITableAccumulatorMap[tableName] as ITableAccumulator; } - public void doWork () - { + public void doWork() { verifyAccess(); + bts.Log.assert(false); + // TODO - if (myIsSuspended) - return; - if (myIsInDoWork) - return; - else - { - myIsInDoWork = true; // to allow reentrancy - try - { - if (onDoWorkStart != null) - onDoWorkStart(); + // if (myIsSuspended) + // return; + // if (myIsInDoWork) + // return; + // else + // { + // myIsInDoWork = true; // to allow reentrancy + // try + // { + // if (onDoWorkStart != null) + // onDoWorkStart(); - ArrayList updateList = mySubscriberCore.getUpdates(myGetTimeInterval()); - IDictionary updateMap = myGetUpdateMap(updateList); - - foreach (DictionaryEntry de in updateMap) - { - Stream[] allUpdates = (de.Value as ArrayList).ToArray(typeof(Stream)) as Stream[]; - string tag = de.Key.ToString(); - if (myITableAccumulatorMap[tag] == null){} - // BlueEventLog.logEvent("Received a SubscriberCore's callback for a tag that was never subscribed", BlueEventLevel.Warning); - else - { - myTimer.start(); + // //ArrayList updateList = mySubscriberCore.getUpdates(myGetTimeInterval()); + // IDictionary updateMap = myGetUpdateMap(updateList); - - if (onTagFireStart != null) - onTagFireStart(tag); - - (myITableAccumulatorMap[tag] as ITableAccumulator).update(allUpdates); - if (onTagFireEnd != null) - onTagFireEnd(tag); - myTimer.stop(); - if (myTimer.lastIntervalTime > myLogTimeThreshold) - { - // BlueEventLog.logEvent("callback on tag " + tag.ToUpper() + " took " + - // myTimer.lastIntervalTime + " msecs", BlueEventLevel.Warning); - } - } - } + // foreach (DictionaryEntry de in updateMap) + // { + // Stream[] allUpdates = (de.Value as ArrayList).ToArray(typeof(Stream)) as Stream[]; + // string tag = de.Key.ToString(); + // if (myITableAccumulatorMap[tag] == null){} + // // BlueEventLog.logEvent("Received a SubscriberCore's callback for a tag that was never subscribed", BlueEventLevel.Warning); + // else + // { + // myTimer.start(); - // to allow for registering of workers on the worker callback - myIsCallingWorkers = true; - myPendingOps = new ArrayList(); - foreach (IWorker w in myWorkers) - { - myTimer.start(); - w.doWork(); - myTimer.stop(); - if (myTimer.lastIntervalTime > _dowork_threshold){} - // mbts.Logger.log (bts.log.Level.Warn, bts.log.Subsystem.gen, String.Format ("VSD.dowork on worker {0} took {1}", w.GetType().ToString (), myTimer.lastIntervalTime)); - } - myIsCallingWorkers = false; - foreach (PendingAddRemoveWorker op in myPendingOps) - if (op.isAdd) - addWorker(op.w); - else - removeWorker(op.w); - } - finally - { - myPendingOps = null; - myIsInDoWork = false; - myIsCallingWorkers = false; - if (onDoWorkEnd != null) - onDoWorkEnd (); - } - }//end if we're not in do work - + // if (onTagFireStart != null) + // onTagFireStart(tag); + + // (myITableAccumulatorMap[tag] as ITableAccumulator).update(allUpdates); + // if (onTagFireEnd != null) + // onTagFireEnd(tag); + // myTimer.stop(); + // if (myTimer.lastIntervalTime > myLogTimeThreshold) + // { + // // BlueEventLog.logEvent("callback on tag " + tag.ToUpper() + " took " + + // // myTimer.lastIntervalTime + " msecs", BlueEventLevel.Warning); + // } + // } + // } + + // // to allow for registering of workers on the worker callback + // myIsCallingWorkers = true; + // myPendingOps = new ArrayList(); + // foreach (IWorker w in myWorkers) + // { + // myTimer.start(); + // w.doWork(); + // myTimer.stop(); + // if (myTimer.lastIntervalTime > _dowork_threshold){} + // // mbts.Logger.log (bts.log.Level.Warn, bts.log.Subsystem.gen, String.Format ("VSD.dowork on worker {0} took {1}", w.GetType().ToString (), myTimer.lastIntervalTime)); + // } + // myIsCallingWorkers = false; + + // foreach (PendingAddRemoveWorker op in myPendingOps) + // if (op.isAdd) + // addWorker(op.w); + // else + // removeWorker(op.w); + // } + // finally + // { + // myPendingOps = null; + // myIsInDoWork = false; + // myIsCallingWorkers = false; + // if (onDoWorkEnd != null) + // onDoWorkEnd (); + // } + // }//end if we're not in do work + } private bool myIsSuspended = false; @@ -201,38 +188,32 @@ namespace BCG public void resume() { myIsSuspended = false; } - public bool checkAccess() - { + public bool checkAccess() { if (this.myThreadOwner == null) this.myThreadOwner = Thread.CurrentThread; return this.myThreadOwner == Thread.CurrentThread; } - public void verifyAccess() - { - if (!checkAccess()) - { + public void verifyAccess() { + if (!checkAccess()) { string errorMessage = string.Format("Invalid cross thread access on ViewStreamDatabase. Owning thread: {0}. Accessing thread: {1}", this.myThreadOwner.ManagedThreadId, Thread.CurrentThread.ManagedThreadId); -//#if DEBUG -// BlueEventLog2.instance().assert(false, errorMessage); -//#else -// BlueEventLog2.instance().logEvent(errorMessage, BlueEventLog2Level.Fatal); -//#endif + //#if DEBUG + // BlueEventLog2.instance().assert(false, errorMessage); + //#else + // BlueEventLog2.instance().logEvent(errorMessage, BlueEventLog2Level.Fatal); + //#endif } } - private IDictionary myGetUpdateMap (ArrayList updates) - { - IDictionary retVal = new Hashtable (); - foreach (PubSubUpdate update in updates) - { + private IDictionary myGetUpdateMap(ArrayList updates) { + IDictionary retVal = new Hashtable(); + foreach (PubSubUpdate update in updates) { if (retVal[update.tag] == null) - retVal[update.tag] = new ArrayList (); - (retVal[update.tag] as ArrayList).Add (update.body); + retVal[update.tag] = new ArrayList(); + (retVal[update.tag] as ArrayList).Add(update.body); } - if (retVal.Count > 0) - { + if (retVal.Count > 0) { string tagString = ""; foreach (string tag in retVal.Keys) tagString += tag + " , "; @@ -240,44 +221,38 @@ namespace BCG return retVal; } - public bool isConsistent{get {return true;}} + public bool isConsistent { get { return true; } } - public void addWorker(IWorker w) - { + public void addWorker(IWorker w) { verifyAccess(); if (myIsCallingWorkers) - myPendingOps.Add(new PendingAddRemoveWorker(true,w)); + myPendingOps.Add(new PendingAddRemoveWorker(true, w)); else myWorkers.Add(w); } - public void removeWorker(IWorker w) - { + public void removeWorker(IWorker w) { verifyAccess(); if (myIsCallingWorkers) - myPendingOps.Add(new PendingAddRemoveWorker(false,w)); + myPendingOps.Add(new PendingAddRemoveWorker(false, w)); else myWorkers.Remove(w); } #region IDisposable Members - public void Dispose() - { - if (!myIsDisposed) - { + public void Dispose() { + if (!myIsDisposed) { myIsDisposed = true; - mySubscriberCore.Dispose (); + mySubscriberCore.Dispose(); } } private ArrayList myPendingOps; private bool myIsCallingWorkers = false; - class PendingAddRemoveWorker - { - public PendingAddRemoveWorker(bool isAdd, IWorker w) - { + class PendingAddRemoveWorker { + public PendingAddRemoveWorker(bool isAdd, IWorker w) { this.isAdd = isAdd; this.w = w; } diff --git a/src/DataStreamSuite/PubSub/Client/Communication/IPubSubServerConnection.cs b/src/DataStreamSuite/PubSub/Client/Communication/IPubSubServerConnection.cs index 223c2ca67..202d77d37 100644 --- a/src/DataStreamSuite/PubSub/Client/Communication/IPubSubServerConnection.cs +++ b/src/DataStreamSuite/PubSub/Client/Communication/IPubSubServerConnection.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Text; using System.IO; using BCG.Utilities.General; -using bts; namespace BCG { /// diff --git a/src/DataStreamSuite/PubSub/Client/SubscriptionUtilities/ManagedSubscriber.cs b/src/DataStreamSuite/PubSub/Client/SubscriptionUtilities/ManagedSubscriber.cs index 70bdf0258..93211605a 100644 --- a/src/DataStreamSuite/PubSub/Client/SubscriptionUtilities/ManagedSubscriber.cs +++ b/src/DataStreamSuite/PubSub/Client/SubscriptionUtilities/ManagedSubscriber.cs @@ -1,128 +1,113 @@ using System; using System.Collections; using System.IO; -using System.Runtime.Serialization.Formatters.Binary; +using System.Collections.Generic; using BCG.Utilities; using BCG.Utilities.General; -namespace BCG -{ - public delegate void Handler (IPubItem pi); - public delegate void RawDataHandler (string tag, Stream s); - +namespace BCG { + public delegate void Handler(IPubItem pi); + public delegate void RawDataHandler(string tag, Stream s); + /// /// Provides a callback based interface to the SubscriptionCore (this class is mainly here to allow backward compatibility /// with PubSub, as some clients are still using ManagedSubcribers) /// - public class ManagedSubscriber : IWorker, IDisposable - { + public class ManagedSubscriber : IWorker, IDisposable { private static ManagedSubscriber mySelf; private SubscriberCore mySubsCore; - private IDictionary myTypedDispatchTable = new Hashtable (), - myRawDispatchTable = new Hashtable (); + private IDictionary myTypedDispatchTable = new Hashtable(), + myRawDispatchTable = new Hashtable(); - private int myWaitTime = 0; - public ManagedSubscriber() : this (new SubscriberCore ()) {} + public ManagedSubscriber() : this(new SubscriberCore()) { } - public ManagedSubscriber (SubscriberCore subsCore) {mySubsCore = subsCore;} + public ManagedSubscriber(SubscriberCore subsCore) { mySubsCore = subsCore; } - public void doWork () - { - IDictionary temp = new Hashtable (); - ArrayList updates = mySubsCore.getUpdates (myWaitTime); - foreach (PubSubUpdate psu in updates) - { - temp [psu.tag] = temp [psu.tag] == null ? new ArrayList () : temp [psu.tag]; - (temp [psu.tag] as ArrayList).Add (psu.body); + public void doWork() { + var msg_map = new Dictionary>(); + var updates = mySubsCore.get_updates(TimeSpan.Zero); + foreach (bts.PubSubServerMessage ps_msg in updates) { + List tag_list = null; + if (!msg_map.TryGetValue(ps_msg.tag, out tag_list)) { + tag_list = new List(); + tag_list.Add(ps_msg); + } + tag_list.Add(ps_msg); } - myFireEvents (temp); + myFireEvents(msg_map); } - public void subscribe (string tag, Handler handler) - { + public void subscribe(string tag, Handler handler) { myTypedDispatchTable[tag] = !myTypedDispatchTable.Contains(tag) ? new TypedPubItemHandler(tag, mySubsCore) : myTypedDispatchTable[tag]; (myTypedDispatchTable[tag] as TypedPubItemHandler).addSubscription(handler); } - public void subscribe (string tag, Handler handler, IGenericFormatter formatter) - { - myTypedDispatchTable[tag] = !myTypedDispatchTable.Contains (tag) ? - new TypedPubItemHandler (tag, mySubsCore, formatter) : myTypedDispatchTable[tag]; - (myTypedDispatchTable[tag] as TypedPubItemHandler).addSubscription (handler); + public void subscribe(string tag, Handler handler, IGenericFormatter formatter) { + myTypedDispatchTable[tag] = !myTypedDispatchTable.Contains(tag) ? + new TypedPubItemHandler(tag, mySubsCore, formatter) : myTypedDispatchTable[tag]; + (myTypedDispatchTable[tag] as TypedPubItemHandler).addSubscription(handler); } - public void subscribe (string tag, RawDataHandler handler) - { - myRawDispatchTable [tag] = !myRawDispatchTable.Contains (tag) ? - new RawPubItemHandler (tag, mySubsCore) : myRawDispatchTable [tag]; - (myRawDispatchTable [tag] as RawPubItemHandler).addSubscription (handler); + public void subscribe(string tag, RawDataHandler handler) { + myRawDispatchTable[tag] = !myRawDispatchTable.Contains(tag) ? + new RawPubItemHandler(tag, mySubsCore) : myRawDispatchTable[tag]; + (myRawDispatchTable[tag] as RawPubItemHandler).addSubscription(handler); } - public void unsubscribe (string tag, Handler handler) - { - if (myTypedDispatchTable.Contains(tag)) - { + public void unsubscribe(string tag, Handler handler) { + if (myTypedDispatchTable.Contains(tag)) { (myTypedDispatchTable[tag] as TypedPubItemHandler).removeSubscription(handler); if ((myTypedDispatchTable[tag] as SingleSubHandler).nSubscribers == 0) myTypedDispatchTable.Remove(tag); - } - else{} - // BlueEventLog.logEvent("Trying to unsubscribe a PubItem tag that was never subsribed", BlueEventLevel.Error); + } else { } + // BlueEventLog.logEvent("Trying to unsubscribe a PubItem tag that was never subsribed", BlueEventLevel.Error); } - public bool alreadySubscribed(string tag) - { + public bool alreadySubscribed(string tag) { return myTypedDispatchTable.Contains(tag) || myRawDispatchTable.Contains(tag); } - public void unsubscribe (string tag, RawDataHandler handler) - { - if (myRawDispatchTable.Contains (tag)) - { - (myRawDispatchTable [tag] as RawPubItemHandler).removeSubscription (handler); + public void unsubscribe(string tag, RawDataHandler handler) { + if (myRawDispatchTable.Contains(tag)) { + (myRawDispatchTable[tag] as RawPubItemHandler).removeSubscription(handler); if ((myRawDispatchTable[tag] as SingleSubHandler).nSubscribers == 0) myRawDispatchTable.Remove(tag); - } - else {} - // BlueEventLog.logEvent ("Trying to unsubscribe a Raw tag that was never subsribed", BlueEventLevel.Warning); + } else { } + // BlueEventLog.logEvent ("Trying to unsubscribe a Raw tag that was never subsribed", BlueEventLevel.Warning); } - private void myFireEvents (IDictionary updates) - { - foreach (DictionaryEntry de in updates) - { - Stream s = StreamUtilityMethods.getAggregatedStream ((de.Value as ArrayList).ToArray (typeof (Stream)) as Stream[]); - if (myTypedDispatchTable.Contains (de.Key)) - (myTypedDispatchTable [de.Key] as TypedPubItemHandler).update (de.Key.ToString(), s); - else if (myRawDispatchTable.Contains (de.Key)) - (myRawDispatchTable [de.Key] as RawPubItemHandler).update (de.Key.ToString(), s); - else{} - // BlueEventLog.logEvent ("Received update for an unsubscribed tag", BlueEventLevel.Warning); + private void myFireEvents(Dictionary> update_map) { + // TODO + bts.Log.assert(false); + // foreach (DictionaryEntry de in updates) { + // Stream s = StreamUtilityMethods.getAggregatedStream((de.Value as ArrayList).ToArray(typeof(Stream)) as Stream[]); + // if (myTypedDispatchTable.Contains(de.Key)) + // (myTypedDispatchTable[de.Key] as TypedPubItemHandler).update(de.Key.ToString(), s); + // else if (myRawDispatchTable.Contains(de.Key)) + // (myRawDispatchTable[de.Key] as RawPubItemHandler).update(de.Key.ToString(), s); + // else { } + // // BlueEventLog.logEvent ("Received update for an unsubscribed tag", BlueEventLevel.Warning); + // } + } + + public IPubSubRouter router { + get { + return mySubsCore.get_router(); } } - public IPubSubRouter router - { - get - { - return mySubsCore.getRouter(); - } - } - - public static ManagedSubscriber instance - { - get {return mySelf = mySelf == null ? new ManagedSubscriber () : mySelf;} + public static ManagedSubscriber instance { + get { return mySelf = mySelf == null ? new ManagedSubscriber() : mySelf; } } #region IDisposable Members - public void Dispose() - { + public void Dispose() { mySubsCore.Dispose(); } diff --git a/src/DataStreamSuite/PubSub/ISubscriberCore.cs b/src/DataStreamSuite/PubSub/ISubscriberCore.cs index e834fadd5..e8e7c048a 100644 --- a/src/DataStreamSuite/PubSub/ISubscriberCore.cs +++ b/src/DataStreamSuite/PubSub/ISubscriberCore.cs @@ -3,18 +3,14 @@ using System.Collections; using System.Collections.Generic; using System.Text; -namespace BCG -{ +namespace BCG { public delegate void PubSubConnectionChange(bool isConnected, string connection); - public interface ISubscriberCore : IDisposable - { + public interface ISubscriberCore : IDisposable { void subscribe(params string[] tags); void unsubscribe(params string[] tags); - ArrayList getUpdates(); - ArrayList getUpdates(int ms); - ArrayList getUpdates(TimeSpan timeout); - IPubSubRouter getRouter(); + IEnumerable get_updates(TimeSpan timeout); + IPubSubRouter get_router(); event PubSubConnectionChange onPubSubConnectionChange; } diff --git a/src/DataStreamSuite/PubSub/SingleServerSubscriberCore.cs b/src/DataStreamSuite/PubSub/SingleServerSubscriberCore.cs index e4600a51d..612fa9400 100644 --- a/src/DataStreamSuite/PubSub/SingleServerSubscriberCore.cs +++ b/src/DataStreamSuite/PubSub/SingleServerSubscriberCore.cs @@ -10,7 +10,7 @@ using System.Linq; namespace BCG { /// - /// Deals with the subscriptions (and getting data) from one sole + /// Deals with the subscriptions (and getting data) from one single /// pubsub server. Theres no sharing of conenctions /// from this point. Every new instance of SingleServerSubscriberCore /// will open its new dedicated connection to the serverURL that @@ -18,7 +18,7 @@ namespace BCG { /// internal interface ISingleServerSubscriberCore : IDisposable { - IList get_updates(int timeout); + IList get_updates(int timeout); event PubSubConnectionChange onPubSubConnectionChange; void subscribe(params string[] tags); void unsubscribe(params string[] tags); @@ -31,16 +31,17 @@ namespace BCG { public event PubSubConnectionChange onPubSubConnectionChange; public SingleServerSubscriberCore(string server_url, PubSubServerConnectionFactory connection_factory) { + bts.Log.Gen.info($"SingleServerSubscriberCore consructed for server_url: {server_url}"); _connection = connection_factory.getConnection(server_url); _connection.register_connection_callback(new PubSubServerConnectionStatusChange(_handle_server_reboot)); } // gets as many data items that it can get in // timeout milliseconds - public IList get_updates(int timeout) { + public IList get_updates(int timeout) { _connection.doWork(); - List rv = new List(); - IList data_items = _connection.get_updates(new TimeSpan(0, 0, 0, 0, timeout), Int32.MaxValue); + List rv = new List(); + IList data_items = _connection.get_updates(TimeSpan.FromMilliseconds(timeout), Int32.MaxValue); foreach (byte[] data in data_items) { process_message(data, ref rv); } @@ -73,12 +74,15 @@ namespace BCG { "it was never subscribed"); } } - UnSubMetaData unsub = new UnSubMetaData(_connection.client_url, unsub_tags.ToArray()); - Stream str = new MemoryStream(); - new MetaData(unsub).save(str); - str.Position = 0; - // this is where data is actually sent out - _connection.send(str); + bts.PubSubClientMessage msg = new bts.PubSubClientMessage() { + msg_type = bts.PubSubMessageType.UNSUBSCRIIBE, + unsub_msg = new bts.UnsubscribeMsg() { + tags = unsub_tags.ToArray(), + connection = _connection.client_url, + subscribing_app = ClientInfo.thisClient.processString + } + }; + _connection.send(msg); } #region IDisposable Members @@ -86,8 +90,8 @@ namespace BCG { public void Dispose() { ///remove the subscriber //myConnection.send(new PubSubMessage(new MetaData(new RemoveSubscriberMetaData(myConnection.clientURL))).toStream()); + // unsub all ? _connection.Dispose(); - //clear the list of tags you've subscribed to. This way, if you're ever used again, //you have to send all the subscription metadata out again. _tags.Clear(); @@ -97,12 +101,17 @@ namespace BCG { // The only place where a tag is subsribed from the Pubsub server. the subscriptions are wrapped into SubMetaData, // which has a to_stream method - private void _subscribe(params string[] tags) { - SubMetaData sub = new SubMetaData(_connection.client_url, tags); - Stream str = new MemoryStream(); - new MetaData(sub).save(str); - str.Position = 0; - _connection.send(str); + private void _subscribe(params string[] tag_args) { + // coonnection and app + bts.PubSubClientMessage msg = new bts.PubSubClientMessage() { + msg_type = bts.PubSubMessageType.SUBSCRIIBE, + sub_msg = new bts.SubscribeMsg() { + connection = _connection.client_url, + subscribing_app = ClientInfo.thisClient.processString, + tags = tag_args + } + }; + _connection.send(msg); } private void _handle_server_reboot(string server_url, bool connection) { @@ -118,47 +127,13 @@ namespace BCG { } // processes one message - internal static void process_message(byte[] data, ref List updates) { + internal static void process_message(byte[] data, ref List updates) { bts.Log.Gen.info($"SingleServerSubscriberCore.process_message data_len: {data.Length}"); if (data != null && data.Length > 0) { MemoryStream str = new MemoryStream(data); - MetaData md = new MetaData(str); - bts.Log.Gen.info($"SingleServerSubscriberCore.processMessage meta_data: {md}"); - MemoryStream bodyStream = str; - long bodyPosition = str.Position; - object op = Activator.CreateInstance(Type.GetType("BCG." + md["op-code"])); - md.copyTo(op); - if (op is PubMetaData) { - PubMetaData p = op as PubMetaData; - //BCG.BlueTrace.WriteBlueCommReceiveW(p.tag, p.publishTimeTicks); - - //check to see if this publish took a while to get here - p.warnIfLatencyExceedsThreshold(); - //find out if we need to decompress this data - Stream realBody = bodyStream; - if (p.isCompressed) { - long compressedSize = bodyStream.Length - bodyStream.Position; - if (compressedSize == 0) { - string error_msg = "Error: tag " + p.tag + " had compressed size of 0 bytes. This shouldnt' happen. Not decompressing tag or sending out update."; - bts.Log.Gen.error(error_msg); - return; - } - realBody = StreamDecompressor.decompressStream(bodyStream); - realBody.Position = bodyPosition; - } - updates.Add(new PubSubUpdate(p.tag, p.type, realBody)); - } else if (op is TransactionMetaData) { - TransactionMetaData tr = op as TransactionMetaData; - for (int i = 0; i < tr.nMessages; i++) { - PubMetaData pub = new PubMetaData(); - new MetaData(bodyStream).copyTo(pub); - byte[] trConstituent = new byte[pub.size]; - bodyStream.Read(trConstituent, 0, trConstituent.Length); - updates.Add(new PubSubUpdate(pub.tag, pub.type, new MemoryStream(trConstituent))); - } - } else { - bts.Log.assert_d(false, $"Unknown message received: {md} only Pub and TransactionMetaData are legal"); - } + bts.PubSubServerMessage serv_msg = new bts.PubSubServerMessage(); + serv_msg.consruct_deserialize(str); + updates.Add(serv_msg); } } } diff --git a/src/DataStreamSuite/PubSub/StaticSubscriberCore.cs b/src/DataStreamSuite/PubSub/StaticSubscriberCore.cs index fdcf2ff2e..ccbf19eac 100644 --- a/src/DataStreamSuite/PubSub/StaticSubscriberCore.cs +++ b/src/DataStreamSuite/PubSub/StaticSubscriberCore.cs @@ -24,7 +24,7 @@ namespace BCG { /// to the servers even though there might be so created by other instances of the SubscriberCore /// /// - public class StaticSubscriberCore : ISubscriberCore { + public class SubscriberCore : ISubscriberCore { private Dictionary myServerURLToSubCore = new Dictionary(); private IPubSubRouter myRouter; private HighPerformanceTimer myTimer = new HighPerformanceTimer(); @@ -35,21 +35,21 @@ namespace BCG { #region constructors - public StaticSubscriberCore() { + public SubscriberCore() { //this defaults to a basic pubsubrouter if the config key is not filled out myInit(myGetRouter()); } - public StaticSubscriberCore(string siteName) { + public SubscriberCore(string siteName) { myInit(new PubSubRouter(PubSub3Config.instance.getRouting(siteName))); } private IPubSubRouter myGetRouter() { return new PubSubRouter(PubSub3Config.instance.getRouting()); } - public StaticSubscriberCore(PubSubRoute[] routes) { + public SubscriberCore(PubSubRoute[] routes) { myInit(new PubSubRouter(routes)); } - public StaticSubscriberCore(IPubSubRouter router) { + public SubscriberCore(IPubSubRouter router) { myInit(router); } @@ -59,38 +59,9 @@ namespace BCG { myRouter = router; } - public ArrayList getUpdates() { - return getUpdates(10); - } - - public ArrayList getUpdates(TimeSpan timeout) { - return getUpdates(Convert.ToInt32(timeout.TotalMilliseconds)); - } - - public ArrayList getUpdates(int timeout) { - //BCG.BlueTrace.WriteTraceMethodEnterW("StaticSubscriberCore.getUpdates"); - lock (myServerURLToSubCore) { - - if (myServerURLToSubCore.Count == 0) { - return new ArrayList(); - } else { - ///gets a time share for every subscriber and - ///calls their updates - myTimer.start(); - int timeShare = timeout / myServerURLToSubCore.Count; - List retVal = new List(); - foreach (ISingleServerSubscriberCore subCore in myServerURLToSubCore.Values) - retVal.AddRange(subCore.get_updates(timeShare)); - _log_n_updates(retVal); - myTimer.stop(); - //if (myTimer.lastIntervalTime > 10) - // BlueEventLog.logEvent("get updates taking " + myTimer.lastIntervalTime, BlueEventLevel.Error); - - //BCG.BlueTrace.WriteTraceMethodExitW("StaticSubscriberCore.getUpdates"); - return new ArrayList(retVal); - } - } - + public IEnumerable get_updates(TimeSpan timeout) { + // TODO + return null; } private IDictionary _n_update_map = new Dictionary(); @@ -154,7 +125,7 @@ namespace BCG { } } } - public IPubSubRouter getRouter() { + public IPubSubRouter get_router() { return myRouter; } diff --git a/src/DataStreamSuite/PubSub/SubscriberCore.cs b/src/DataStreamSuite/PubSub/SubscriberCore.cs index b9d3fa31f..8b998127f 100644 --- a/src/DataStreamSuite/PubSub/SubscriberCore.cs +++ b/src/DataStreamSuite/PubSub/SubscriberCore.cs @@ -1,76 +1,81 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Collections; +// using System; +// using System.Collections.Generic; +// using System.Linq; +// using System.Text; +// using System.Collections; -namespace BCG { - /* - * This class has been changed to be a thin pass-through shell around different subscriber core implementations. - * The specific implementation used is determined by the config. - * - * - * */ - public class SubscriberCore : ISubscriberCore { - ISubscriberCore mySubscriberCore = null; +// namespace BCG { +// /* +// * This class has been changed to be a thin pass-through shell around different subscriber core implementations. +// * The specific implementation used is determined by the config. +// * +// * +// * */ +// public class SubscriberCore : ISubscriberCore { +// ISubscriberCore mySubscriberCore = null; - public SubscriberCore() { - // TODOds - mySubscriberCore = new StaticSubscriberCore();// PubSubComponentFactory.getSubscriberCore(); - mySubscriberCore.onPubSubConnectionChange += myHandleConnectionChange; - } +// public SubscriberCore() { +// // TODOds +// mySubscriberCore = new StaticSubscriberCore();// PubSubComponentFactory.getSubscriberCore(); +// mySubscriberCore.onPubSubConnectionChange += myHandleConnectionChange; +// } - public SubscriberCore(string siteName) { - mySubscriberCore = new StaticSubscriberCore(siteName); - mySubscriberCore.onPubSubConnectionChange += myHandleConnectionChange; - } - public SubscriberCore(IPubSubRouter theRouter) { - // TODOds - mySubscriberCore = new StaticSubscriberCore(theRouter);// PubSubComponentFactory.getSubscriberCore(); - mySubscriberCore.onPubSubConnectionChange += myHandleConnectionChange; - } +// public SubscriberCore(string siteName) { +// mySubscriberCore = new StaticSubscriberCore(siteName); +// mySubscriberCore.onPubSubConnectionChange += myHandleConnectionChange; +// } +// public SubscriberCore(IPubSubRouter theRouter) { +// // TODOds +// mySubscriberCore = new StaticSubscriberCore(theRouter);// PubSubComponentFactory.getSubscriberCore(); +// mySubscriberCore.onPubSubConnectionChange += myHandleConnectionChange; +// } - public SubscriberCore(PubSubRoute[] routes) { - //this is always a static subscriber core - mySubscriberCore = new StaticSubscriberCore(routes); - mySubscriberCore.onPubSubConnectionChange += myHandleConnectionChange; - } +// public SubscriberCore(PubSubRoute[] routes) { +// //this is always a static subscriber core +// mySubscriberCore = new StaticSubscriberCore(routes); +// mySubscriberCore.onPubSubConnectionChange += myHandleConnectionChange; +// } - public IPubSubRouter getRouter() { - return mySubscriberCore.getRouter(); - } +// public IPubSubRouter get_router() { +// return mySubscriberCore.get_router(); +// } - public ArrayList getUpdates() { - return mySubscriberCore.getUpdates(10); - } +// // public ArrayList getUpdates() { +// // return mySubscriberCore.getUpdates(10); +// // } - public ArrayList getUpdates(TimeSpan timeout) { - return mySubscriberCore.getUpdates(Convert.ToInt32(timeout.TotalMilliseconds)); - } +// // public ArrayList getUpdates(TimeSpan timeout) { +// // return mySubscriberCore.getUpdates(Convert.ToInt32(timeout.TotalMilliseconds)); +// // } - public ArrayList getUpdates(int timeout) { - return mySubscriberCore.getUpdates(timeout); - } +// // public ArrayList getUpdates(int timeout) { +// // return mySubscriberCore.getUpdates(timeout); +// // } - public void subscribe(params string[] tags) { - mySubscriberCore.subscribe(tags); - } +// public IEnumerable get_updates(TimeSpan timeout) { +// return mySubscriberCore.get_updates(timeout); +// } - public void unsubscribe(params string[] tags) { - mySubscriberCore.unsubscribe(tags); - } - public void Dispose() { - mySubscriberCore.Dispose(); +// public void subscribe(params string[] tags) { +// mySubscriberCore.subscribe(tags); +// } - } - private void myHandleConnectionChange(bool isConnected, string connection) { - if (onPubSubConnectionChange != null) - onPubSubConnectionChange(isConnected, connection); - } +// public void unsubscribe(params string[] tags) { +// mySubscriberCore.unsubscribe(tags); +// } - public event PubSubConnectionChange onPubSubConnectionChange; +// public void Dispose() { +// mySubscriberCore.Dispose(); - } -} +// } +// private void myHandleConnectionChange(bool isConnected, string connection) { +// if (onPubSubConnectionChange != null) +// onPubSubConnectionChange(isConnected, connection); +// } + +// public event PubSubConnectionChange onPubSubConnectionChange; + +// } +// } diff --git a/src/DataStreamSuite/PubSub/Testing/TestSubscriber.cs b/src/DataStreamSuite/PubSub/Testing/TestSubscriber.cs index 5a7764e1e..359ac87f3 100644 --- a/src/DataStreamSuite/PubSub/Testing/TestSubscriber.cs +++ b/src/DataStreamSuite/PubSub/Testing/TestSubscriber.cs @@ -4,6 +4,7 @@ using bts; using System; using System.IO; +using System.Linq; using System.Runtime.Serialization; namespace BCG { @@ -17,9 +18,10 @@ namespace BCG { public void keep_polling(TimeSpan wait_per, int n_polls = System.Int32.MaxValue) { _sub_core.subscribe(TestPubItem.test_tag); for (int i = 0; i < n_polls; i++) { - var list = _sub_core.getUpdates(); - if (list.Count > 0) { - Console.WriteLine($"Received {list.Count} items"); + var list = _sub_core.get_updates(TimeSpan.Zero); + var count = list.Count(); + if (count > 0) { + Console.WriteLine($"Received {count} items"); } foreach (var p in list) { Console.WriteLine($"Received item: {p} iter: {i}"); diff --git a/src/DataStreamSuite/PubSub/documentation/readme.txt b/src/DataStreamSuite/PubSub/documentation/readme.txt index 5f1a6ae3c..9a376fc56 100644 --- a/src/DataStreamSuite/PubSub/documentation/readme.txt +++ b/src/DataStreamSuite/PubSub/documentation/readme.txt @@ -18,6 +18,15 @@ PubSubMessages: PubSubClientMessage is the only messages thats sent from client to pubsubserver. Its serialized on the client and sent over to the pubsubserver, where uits received ad deserialized +SubscriberCore:ISubscriberCore +| +V +StaticSubscriberCore +| +V +SingleServerSubscriberCore:ISingleServerSubscriberCore + + PubSubServer: PubSubMessageReactor (top level, called from main) ServerMessageHub : IPubsubMessageHub (just a wrapper so multiple ) diff --git a/src/DataStreamSuite/SharedStreams/System/PS3/Stats/PubSubServerTagStatsStream.cs b/src/DataStreamSuite/SharedStreams/System/PS3/Stats/PubSubServerTagStatsStream.cs index 3d982bc44..c243cf851 100644 --- a/src/DataStreamSuite/SharedStreams/System/PS3/Stats/PubSubServerTagStatsStream.cs +++ b/src/DataStreamSuite/SharedStreams/System/PS3/Stats/PubSubServerTagStatsStream.cs @@ -4,13 +4,11 @@ using System.Text; using System.IO; using BCG.Utilities.General; -namespace BCG -{ +namespace BCG { [DataStreamUserRespresentation("tagStats")] - public class PubSubServerTagStatsStream : ViewStream, IWorker - { + public class PubSubServerTagStatsStream : ViewStream, IWorker { private static Dictionary> myStreamMap = new Dictionary>(); @@ -29,8 +27,7 @@ namespace BCG new ColumnInfo("lastUpdateTime", 9, typeof(DateTime))), new string[] { "tag" }); - public static ViewStream getPubSubServerTagStatsStream(ViewStreamDatabase vsd, string serverURL) - { + public static ViewStream getPubSubServerTagStatsStream(ViewStreamDatabase vsd, string serverURL) { //you can also supply a service name and it should work, as long as substations are enabled. // if (PubSub3Config.instance.PS3_UseSubstations) // { @@ -46,11 +43,9 @@ namespace BCG #region constructors to be used by the static factory method public PubSubServerTagStatsStream(string serverURL) - : this(ViewStreamDatabase.instance, serverURL) - { } + : this(ViewStreamDatabase.instance, serverURL) { } - private PubSubServerTagStatsStream(ViewStreamDatabase vsd, string serverURL) - { + private PubSubServerTagStatsStream(ViewStreamDatabase vsd, string serverURL) { myVsd = vsd; mySubCore = new SubscriberCore(new PubSubRouter(new PubSubRoute[1] { new PubSubRoute(serverURL, ".*") })); } @@ -59,8 +54,7 @@ namespace BCG #region exposed constructors that use the static factory methods - public PubSubServerTagStatsStream() - { + public PubSubServerTagStatsStream() { // if (PubSub3Config.instance.PS3_UseSubstations) // mySetRealSource(new ThreadSafeStream(new SubstationTagStatsStream(ViewStreamDatabase.instance, false))); // else @@ -68,8 +62,7 @@ namespace BCG } - public PubSubServerTagStatsStream(ViewStreamDatabase vsd) - { + public PubSubServerTagStatsStream(ViewStreamDatabase vsd) { // if (PubSub3Config.instance.PS3_UseSubstations) // mySetRealSource(new ThreadSafeStream(new SubstationTagStatsStream(vsd, false))); // else @@ -77,8 +70,7 @@ namespace BCG } - public PubSubServerTagStatsStream(ViewStreamDatabase vsd, PubSubRoute[] routes) - { + public PubSubServerTagStatsStream(ViewStreamDatabase vsd, PubSubRoute[] routes) { List vss = new List(); foreach (string url in PubSub3Config.instance.getAllPubSubs()) vss.Add(getPubSubServerTagStatsStream(vsd, url)); @@ -87,43 +79,37 @@ namespace BCG #endregion - protected override void myOnFirstSubscriber() - { + protected override void myOnFirstSubscriber() { mySubCore.subscribe("System_AllStatistics"); myVsd.addWorker(this); } - protected override void myOnLastSubscriber() - { + protected override void myOnLastSubscriber() { mySubCore.unsubscribe("System_AllStatistics"); myVsd.removeWorker(this); } #region IWorker Members - public void doWork() - { - foreach (PubSubUpdate u in mySubCore.getUpdates(0)) - { - List tagStats = new List(); - BinaryReader br = new BinaryReader(u.body); + public void doWork() { + foreach (var u in mySubCore.get_updates(TimeSpan.Zero)) { + List tag_stats = new List(); + MemoryStream str = new MemoryStream(u.data); + BinaryReader br = new BinaryReader(str); int n = br.ReadInt32(); - for (int i = 0; i < n; i++) - { - tagStats.Add(new TagStatsInfo(u.body)); + for (int i = 0; i < n; i++) { + tag_stats.Add(new TagStatsInfo(str)); } - myHandleStats(tagStats); + myHandleStats(tag_stats); } } #endregion - private void myHandleStats(List tagStats) - { + private void myHandleStats(List tagStats) { BlueTable tagStatsRows = new BlueTable(myTable.schema); int id = 0; - foreach (TagStatsInfo t in tagStats) - { + foreach (TagStatsInfo t in tagStats) { tagStatsRows.addRow(new BlueRow(myTable.schema, id++, t.server, t.tag, t.totalUpdates, t.totalBytes, t.minSize, t.maxSize, t.lastUpdateSize, t.averageSize, new DateTime(t.lastUpdateTime))); diff --git a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/AllTagsStream.cs b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/AllTagsStream.cs index a5584d390..7677b6cec 100644 --- a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/AllTagsStream.cs +++ b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/AllTagsStream.cs @@ -5,37 +5,30 @@ using System.IO; using BCG.Utilities.General; using BCG.Utilities; -namespace BCG -{ +namespace BCG { - public class AllTagsStream : ViewStream, IWorker - { + public class AllTagsStream : ViewStream, IWorker { private IWorker myRealWorkerStream; public AllTagsStream() - : this ("") - { } + : this("") { } public AllTagsStream(string prefix) - : this (prefix, ViewStreamDatabase.instance) - { } + : this(prefix, ViewStreamDatabase.instance) { } - public AllTagsStream(ViewStreamDatabase vsd, string regExp) - { + public AllTagsStream(ViewStreamDatabase vsd, string regExp) { ViewStream rs; - mySetRealSource(rs = new TagSynopsisStream (vsd, regExp, true)); + mySetRealSource(rs = new TagSynopsisStream(vsd, regExp, true)); myRealWorkerStream = rs as IWorker; } public AllTagsStream(string prefix, ViewStreamDatabase db) - : this (prefix, db, db.subscriber.getRouter()) - { } + : this(prefix, db, db.subscriber.get_router()) { } - public AllTagsStream(string prefix, ViewStreamDatabase db, IPubSubRouter router) - { + public AllTagsStream(string prefix, ViewStreamDatabase db, IPubSubRouter router) { ViewStream rs = null; //if we're using substations, we don't care about the router if (PubSub3Config.instance.PS3_UseSubstations) - mySetRealSource(rs = new TagSynopsisStream(db,"^" + prefix + ".*",true)); + mySetRealSource(rs = new TagSynopsisStream(db, "^" + prefix + ".*", true)); else mySetRealSource(rs = new TagSynopsisStream(db, router.getAllPubSubSubURLs(), "^" + prefix + ".*", true)); myRealWorkerStream = rs as IWorker; @@ -43,9 +36,8 @@ namespace BCG #region IWorker Members - public void doWork() - { - if(myRealWorkerStream != null) + public void doWork() { + if (myRealWorkerStream != null) myRealWorkerStream.doWork(); } diff --git a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs index 94ddb2beb..436c379ac 100644 --- a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs +++ b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs @@ -76,16 +76,17 @@ namespace BCG { #region IWorker Members public void doWork() { - var updates = _sub_core.getUpdates(0); + var updates = _sub_core.get_updates(TimeSpan.Zero); // this is where the pubsub updates are converted to rows - if (updates.Count > 0) { + if (updates.Count() > 0) { int id = 0; BlueTable addedRows = new BlueTable(_table.schema); - foreach (PubSubUpdate u in updates) { - BinaryReader br = new BinaryReader(u.body); - int nUpdates = br.ReadInt32(); - for (int i = 0; i < nUpdates; i++) { - TagPubSubInfo tsi = new TagPubSubInfo(u.body); + foreach (var u in updates) { + BinaryReader br = new BinaryReader(new MemoryStream(u.data)); + // TODO: check this + int n_updates = br.ReadInt32(); + for (int i = 0; i < n_updates; i++) { + TagPubSubInfo tsi = new TagPubSubInfo(new MemoryStream(u.data)); addedRows.addRow(new BlueRow(_table.schema, id++, tsi.tag, tsi.server, tsi.subscribersInString, tsi.publishersInString, tsi.deadPublishersInString)); } } diff --git a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/TagSynopsisStream.cs b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/TagSynopsisStream.cs index c8a2c9602..6a2621965 100644 --- a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/TagSynopsisStream.cs +++ b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/TagSynopsisStream.cs @@ -5,11 +5,9 @@ using BCG.Utilities.General; using System.Collections; using System.IO; -namespace BCG -{ +namespace BCG { [DataStreamUserRespresentation("tagSynopsis")] - public class TagSynopsisStream : ViewStream, IStreamMapper, IWorker - { + public class TagSynopsisStream : ViewStream, IStreamMapper, IWorker { private List myWorkers = new List(); IBlueTableSchema mySchema = new BlueTableSchema("AllTags", new ColumnInfo("id", 0, typeof(int)), @@ -18,18 +16,15 @@ namespace BCG new ColumnInfo("pubSub", 3, typeof(string)), new ColumnInfo("dataPresent", 4, typeof(bool))); - public TagSynopsisStream() - { - mySetRealSource(new TagSynopsisStream(ViewStreamDatabase.instance, ViewStreamDatabase.instance.subscriber.getRouter().getAllPubSubSubURLs())); + public TagSynopsisStream() { + mySetRealSource(new TagSynopsisStream(ViewStreamDatabase.instance, ViewStreamDatabase.instance.subscriber.get_router().getAllPubSubSubURLs())); } - public TagSynopsisStream(string tagRegExp) - { - mySetRealSource(new TagSynopsisStream(ViewStreamDatabase.instance, ViewStreamDatabase.instance.subscriber.getRouter().getAllPubSubSubURLs(), tagRegExp)); + public TagSynopsisStream(string tagRegExp) { + mySetRealSource(new TagSynopsisStream(ViewStreamDatabase.instance, ViewStreamDatabase.instance.subscriber.get_router().getAllPubSubSubURLs(), tagRegExp)); } - public TagSynopsisStream(ViewStreamDatabase vsd, string route) - { + public TagSynopsisStream(ViewStreamDatabase vsd, string route) { ViewStream vs = new PubSubServerStateStream(route, vsd); vs = new MapStream(vs, this); @@ -40,15 +35,12 @@ namespace BCG public TagSynopsisStream(bool cons_overloader, string route) : - this(ViewStreamDatabase.instance, new string[] { route }) - { + this(ViewStreamDatabase.instance, new string[] { route }) { } - public TagSynopsisStream(ViewStreamDatabase vsd, ICollection routes) - { + public TagSynopsisStream(ViewStreamDatabase vsd, ICollection routes) { List vss = new List(); - foreach (string r in routes) - { + foreach (string r in routes) { ViewStream vs = new PubSubServerStateStream(r, vsd); vs = new MapStream(vs, this); vss.Add(vs); @@ -57,8 +49,7 @@ namespace BCG mySetRealSource(new AppendStream(vss.ToArray())); } - public TagSynopsisStream(ViewStreamDatabase vsd, string tagRegExp, bool filterOutNonPublished) - { + public TagSynopsisStream(ViewStreamDatabase vsd, string tagRegExp, bool filterOutNonPublished) { // if (PubSub3Config.instance.PS3_UseSubstations) // { // mySetRealSource(new ThreadSafeStream(new SubstationTagSynopsisStream(vsd, tagRegExp, filterOutNonPublished))); @@ -78,13 +69,11 @@ namespace BCG } - public TagSynopsisStream(ViewStreamDatabase vsd, ICollection routes, string tagRegExp) - { + public TagSynopsisStream(ViewStreamDatabase vsd, ICollection routes, string tagRegExp) { mySetRealSource(new FilterStream(new TagSynopsisStream(vsd, routes), "tag", tagRegExp)); } - public TagSynopsisStream(ViewStreamDatabase vsd, ICollection routes, string tagRegExp, bool filterOutNonPublished) - { + public TagSynopsisStream(ViewStreamDatabase vsd, ICollection routes, string tagRegExp, bool filterOutNonPublished) { ViewStream vs = new TagSynopsisStream(vsd, routes, tagRegExp); if (filterOutNonPublished) vs = new FilterStream(vs, "dataPresent=true"); @@ -94,8 +83,7 @@ namespace BCG #region IStreamMapper Members - public IBlueTableSchema getOutputSchema(IBlueTableSchema inputSchema) - { + public IBlueTableSchema getOutputSchema(IBlueTableSchema inputSchema) { return mySchema; } @@ -103,8 +91,7 @@ namespace BCG #region IDynamicStreamMapper Members - public IBlueRow map(IBlueRow row) - { + public IBlueRow map(IBlueRow row) { string subValue = row["subscribers"].ToString().Trim(); return new BlueRow(getOutputSchema(null), row["id"], @@ -118,8 +105,7 @@ namespace BCG #region IWorker Members - public void doWork() - { + public void doWork() { foreach (IWorker w in myWorkers) w.doWork(); }