Files
spark/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerSubscriptionInfoStream.cs
T

174 lines
7.7 KiB
C#

// using System;
// using System.Collections.Generic;
// using System.Text;
// using BCG.Utilities.General;
// using System.Collections;
// using System.IO;
// namespace BCG
// {
// [DataStreamUserRespresentation("subInfo")]
// public class PubSubServerSubscriptionInfoStream : ViewStream
// {
// internal static string wildCard = ".*";
// internal static PubSubRoute[] defaultRoutes = PubSub3Config.instance.getSubRouting();
// private ViewStream myBaseStream;
// private IBlueTableSchema mySchema = new BlueTableSchema("SubInfo",
// new ColumnInfo("id", 0, typeof(int)),
// new ColumnInfo("machine", 1, typeof(string)),
// new ColumnInfo("app", 2, typeof(string)),
// new ColumnInfo("kq", 3, typeof(string)),
// new ColumnInfo("pid", 4, typeof(int)),
// new ColumnInfo("tag", 5, typeof(string)),
// new ColumnInfo("connection", 6, typeof(string)),
// new ColumnInfo("publishers", 7, typeof(string)),
// new ColumnInfo("deadPublishers", 8, typeof(string)),
// new ColumnInfo("server", 9, typeof(string)));
// private Hashtable myServerStateIdToSubInfoIdMap;
// private BlueTable myOutputRows;
// private int myIdToUse;
// public PubSubServerSubscriptionInfoStream(string serverURL, ViewStreamDatabase vsd)
// {
// myBaseStream = PubSubServerStateStream.getPubSubServerStateStream(vsd, serverURL);
// myServerStateIdToSubInfoIdMap = new Hashtable();
// myOutputRows = new BlueTable(mySchema);
// myIdToUse = 0;
// }
// public PubSubServerSubscriptionInfoStream(string machine, string app, string kq, PubSubRoute[] routes, ViewStreamDatabase vsd)
// {
// // if (PubSub3Config.instance.PS3_UseSubstations)
// // {
// // //if we're using substations, we want to subscribe to each of these things by their service names.
// // //That means we ignore the routes coming in and just subscribe to all of the pubsub services advertised in bluepages
// // SubstationServerBaseStream theRealSource = new SubstationServerBaseStream( (service,url) =>
// // {
// // ViewStream vs = new PubSubServerSubscriptionInfoStream(url, vsd);
// // vs = new FilterStream(vs, new RegExpFilter(new string[] { "machine", "app", "kq" },
// // new string[] { machine, app, kq }));
// // return vs;
// // }
// // );
// // theRealSource.addAllSubstations(false);
// // mySetRealSource(new ThreadSafeStream(vsd, new FilterStream(theRealSource)));
// // }
// // else
// {
// List<ViewStream> vss = new List<ViewStream>();
// foreach (string url in PubSub3Config.instance.getAllPubSubs())
// {
// ViewStream vs = new PubSubServerSubscriptionInfoStream(url, vsd);
// vs = new FilterStream(vs, new RegExpFilter(new string[] { "machine", "app", "kq" },
// new string[] { machine, app, kq }));
// vss.Add(vs);
// }
// mySetRealSource(new AppendStream(vss.ToArray()));
// }
// }
// public PubSubServerSubscriptionInfoStream(string machine, string app, string kq, PubSubRoute[] routes)
// : this(machine, app, kq, routes, ViewStreamDatabase.instance)
// { }
// public PubSubServerSubscriptionInfoStream(string machine, string app, string kq, ViewStreamDatabase vsd)
// : this(machine, app, kq, defaultRoutes, vsd)
// { }
// public PubSubServerSubscriptionInfoStream(string machine, string app, string kq)
// : this(machine, app, kq, defaultRoutes, ViewStreamDatabase.instance)
// { }
// public PubSubServerSubscriptionInfoStream()
// : this(wildCard, wildCard, wildCard)
// { }
// protected override void myOnFirstSubscriber()
// {
// myBaseStream.onChange += new ChangeDelegate(myHandleCallbacks);
// }
// void myHandleCallbacks(object newValue)
// {
// DataPacket dp = newValue as DataPacket;
// BlueTable outDeletedRows = new BlueTable(mySchema);
// BlueTable outAddedRows = new BlueTable(mySchema);
// foreach (IBlueRow dr in dp.deletedRows)
// {
// //find out which rows in the output table correspond to the deleted row
// int[] outputRows = (int[])myServerStateIdToSubInfoIdMap[(int)dr["id"]];
// //if this thing wasn't deleted, just ignore it
// if (outputRows == null)
// continue;
// //delete all of those rows from the output table
// foreach (int deletedId in outputRows)
// {
// IBlueRow thisRow = myOutputRows[deletedId];
// myOutputRows.deleteRow(thisRow);
// outDeletedRows.addRow(thisRow);
// }
// }
// foreach (IBlueRow nr in dp.addedRows)
// {
// List<IBlueRow> outputRows = myTransFormToRows(nr);
// int[] outputRowIds = new int[outputRows.Count];
// int i = 0;
// foreach (IBlueRow r in outputRows)
// {
// myOutputRows.addRow(r);
// outputRowIds[i] = (int)r["id"];
// outAddedRows.addRow(r);
// ++i;
// }
// myServerStateIdToSubInfoIdMap[(int)nr["id"]] = outputRowIds;
// }
// if (myLastValue == null)
// myFireEvent(new DataPacket(myOutputRows, outAddedRows, outDeletedRows));
// else
// myFireEvent(new DataPacket(myOutputRows, outAddedRows, outDeletedRows));
// }
// private List<IBlueRow> myTransFormToRows(IBlueRow r)
// {
// List<IBlueRow> rv = new List<IBlueRow>();
// string tag = r["tag"].ToString();
// string server = r["server"].ToString();
// string publishers = r["publishers"].ToString();
// string deadPublishers = r["deadPublishers"].ToString();
// string[] subscribers = r["subscribers"].ToString().Split(',');
// if (r["subscribers"].ToString().Trim() != "")
// {
// foreach (string sub in subscribers)
// {
// string[] toks = sub.Split(';');
// IBlueRow nr = new BlueRow(mySchema, myIdToUse++, toks[0], toks[1], toks[2], Convert.ToInt64(toks[3]),
// tag, toks[4], publishers, deadPublishers, server);
// rv.Add(nr);
// }
// }
// else
// {
// //publisher but no subscriber
// IBlueRow nr = new BlueRow(mySchema, myIdToUse++, "", "", "", DBNull.Value,
// tag, "", publishers, deadPublishers, server);
// rv.Add(nr);
// }
// return rv;
// }
// protected override void myOnLastSubscriber()
// {
// myBaseStream.onChange -= new ChangeDelegate(myHandleCallbacks);
// }
// }
// }