From 6604eaaea724b3644d5ddacd44edc620fc173e7f Mon Sep 17 00:00:00 2001 From: Taha Date: Wed, 26 Jun 2024 00:23:19 -0400 Subject: [PATCH] some buf gixes + cleanup --- .../Primitives/Time/MillisecondStream.cs | 40 ++++----- .../BlueData/BlueDataUtility.cs | 7 ++ .../Subscription/TableAccumulator2.cs | 6 +- .../PubSub/Client/Routing/IPubSubRouter.cs | 3 +- .../PubSub/Client/Routing/PubSubRouter.cs | 4 + .../AsyncTCPConnection_AsyncWrapper.cs | 13 ++- .../PubSub/ManagedTCP/ITCPConnection.cs | 1 + .../ManagedTCP/ManagedTCPMessageHub.cs | 83 +++++++++---------- .../PubSub/Server/PubSubMessageReactor.cs | 1 + .../SharedStreams/System/PS3/Config | 0 .../PS3/Health/DeadPublisherTagsStream.cs | 15 ++-- .../System/PS3/PubsubRouteStream.cs | 28 +++++++ .../PS3/Stats/PubSubServerTagStatsStream.cs | 4 +- .../Subscription/PubSubServerStateStream.cs | 10 +-- 14 files changed, 121 insertions(+), 94 deletions(-) create mode 100644 src/DataStreamSuite/SharedStreams/System/PS3/Config create mode 100644 src/DataStreamSuite/SharedStreams/System/PS3/PubsubRouteStream.cs diff --git a/src/DataStreamSuite/DataStream/Primitives/Time/MillisecondStream.cs b/src/DataStreamSuite/DataStream/Primitives/Time/MillisecondStream.cs index 1dcb3d2e3..fcb8214cc 100644 --- a/src/DataStreamSuite/DataStream/Primitives/Time/MillisecondStream.cs +++ b/src/DataStreamSuite/DataStream/Primitives/Time/MillisecondStream.cs @@ -1,29 +1,23 @@ using System; -namespace BCG -{ - public class MSecondStream : TimeUnitStream - { - public MSecondStream (int intervalInms, int size) - : base (DateTime.Now, new TimeSpan (0, 0, 0, 0, intervalInms), size, ViewStreamDatabase.instance) - {} +namespace BCG { + public class MSecondStream : TimeUnitStream { + public MSecondStream(int intervalInms, int size) + : base(DateTime.Now, new TimeSpan(0, 0, 0, 0, intervalInms), size, ViewStreamDatabase.instance) { } - protected override DateTime myRoundTime (DateTime dt) {return dt;} + protected override DateTime myRoundTime(DateTime dt) { return dt; } } - public class DisplayableMillisecondStream : ViewStream, IStreamMapper - { - private IBlueTableSchema mySchema = new BlueTableSchema ("ms", - new ColumnInfo ("id", 0, typeof(int)), - new ColumnInfo ("time", 1, typeof(string))); - public DisplayableMillisecondStream (int intervalInMs, int sz) - { - mySetRealSource (new MapStream (new MSecondStream (intervalInMs, sz), this)); + public class DisplayableMillisecondStream : ViewStream, IStreamMapper { + private IBlueTableSchema mySchema = new BlueTableSchema("ms", + new ColumnInfo("id", 0, typeof(int)), + new ColumnInfo("time", 1, typeof(string))); + public DisplayableMillisecondStream(int intervalInMs, int sz) { + mySetRealSource(new MapStream(new MSecondStream(intervalInMs, sz), this)); } #region IStreamMapper Members - public IBlueTableSchema getOutputSchema(IBlueTableSchema inputSchema) - { + public IBlueTableSchema getOutputSchema(IBlueTableSchema inputSchema) { return mySchema; } @@ -31,15 +25,15 @@ namespace BCG #region IDynamicStreamMapper Members - public IBlueRow map (IBlueRow row) - { - return new BlueRow (mySchema, row["id"], myToString ((DateTime)row["time"])); + public IBlueRow map(IBlueRow row) { + DateTime time = row.get_datetime("time"); + var time_txt = time.ToString("yyyy-MM-dd HH:mm:ss.fff"); + return new BlueRow(mySchema, row["id"], time_txt); } #endregion - private string myToString (DateTime dt) - { + private string myToString(DateTime dt) { string sep = ":"; return dt.Hour + sep + dt.Minute + sep + dt.Second + sep + dt.Millisecond; } diff --git a/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs b/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs index aa09e83bb..5a1072853 100644 --- a/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs +++ b/src/DataStreamSuite/DataStreamCore/BlueData/BlueDataUtility.cs @@ -1628,6 +1628,13 @@ namespace BCG { return sb.ToString(); } + public static string id_string(IBlueRowCollection table) { + string rv = String.Empty; + foreach (IBlueRow r in table) + rv += $"{r["id"]} "; + return rv; + } + public static IDictionary> group_together(IBlueRowCollection rows, string[] group_by_col_names) { BlueRowHasher hasher = new BlueRowHasher(group_by_col_names.Length); return group_together(rows, BlueDataUtility.get_column_indices(rows.schema, group_by_col_names), ref hasher); diff --git a/src/DataStreamSuite/DataStreamCore/Messaging/Subscription/TableAccumulator2.cs b/src/DataStreamSuite/DataStreamCore/Messaging/Subscription/TableAccumulator2.cs index 0f44e6c00..fea7e8570 100644 --- a/src/DataStreamSuite/DataStreamCore/Messaging/Subscription/TableAccumulator2.cs +++ b/src/DataStreamSuite/DataStreamCore/Messaging/Subscription/TableAccumulator2.cs @@ -54,15 +54,15 @@ namespace BCG { } } - + private int _update_no = 0; public void handle_updates(IEnumerable msgs) { if (msgs == null || msgs.Count() == 0) return; - Log.Gen.info($"TableAccumulator2.handle_updates msgs: {msgs.Count()} msg_0: {msgs.ElementAt(0).Length}"); + Log.Gen.info($"TableAccumulator2.handle_updates _update_no: {_update_no++} msgs: {msgs.Count()} msg_0: {msgs.ElementAt(0).Length}"); IBlueRowCollection table_0 = _table == null ? null : new BlueTable(_table); foreach (var msg in msgs) { bts.StreamIOMessage str_msg = _deser.deserialize(msg); - var state_txt = _table == null ? "NULL" : _table.Count.ToString(); + var state_txt = _table == null ? "NULL" : BlueDataUtility.id_string(_table); Log.Gen.info($"TableAccumulator2.handle_update tag: {_tag} sz: {msg.Length} str_msg: {str_msg} _state: {state_txt}"); switch (str_msg.op) { case bts.StreamIOMessage.StreamOp.CREATE: diff --git a/src/DataStreamSuite/PubSub/Client/Routing/IPubSubRouter.cs b/src/DataStreamSuite/PubSub/Client/Routing/IPubSubRouter.cs index 4c8fdbd55..2d26d22ba 100644 --- a/src/DataStreamSuite/PubSub/Client/Routing/IPubSubRouter.cs +++ b/src/DataStreamSuite/PubSub/Client/Routing/IPubSubRouter.cs @@ -10,8 +10,7 @@ namespace BCG { // event PubSubTagURLChangeDelegate onSubURLTagRouteChange; // event PubSubTagURLChangeDelegate onPubURLTagRouteChange; - // List get_all_pubsub_sub_urls(); - // List get_all_pubsub_pub_urlss(); + IEnumerable sub_routes(); RemoteConnectionInfo get_sub_route_for_tag(string tag); RemoteConnectionInfo get_pub_route_for_tag(string tag); diff --git a/src/DataStreamSuite/PubSub/Client/Routing/PubSubRouter.cs b/src/DataStreamSuite/PubSub/Client/Routing/PubSubRouter.cs index 71552effb..fbd7062d8 100644 --- a/src/DataStreamSuite/PubSub/Client/Routing/PubSubRouter.cs +++ b/src/DataStreamSuite/PubSub/Client/Routing/PubSubRouter.cs @@ -39,6 +39,10 @@ namespace BCG { #region IPubSubRouter methods + public IEnumerable sub_routes() { + return _sub_routes; + } + public RemoteConnectionInfo get_pub_route_for_tag(string tag) { if (!_pub_routes.TryGetFirst(r => r?.IsMatch(tag) ?? false, out var route)) { throw new ArgumentException($"Failed to find route for tag '{tag}'", nameof(tag)); diff --git a/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection_AsyncWrapper.cs b/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection_AsyncWrapper.cs index 56a271da4..24bbb0323 100644 --- a/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection_AsyncWrapper.cs +++ b/src/DataStreamSuite/PubSub/ManagedTCP/AsyncTCPConnection_AsyncWrapper.cs @@ -45,7 +45,7 @@ namespace bts { _peer_conn_info = get_peer_address(); _self_conn_info = get_self_address(); Log.Gen.info("AsyncTCPConnection_AsyncWrapper.cons _peer_conn_info: {_peer_conn_info} _self_conn_info: {_self_conn_info}"); - _detect_connection_status_change(); + //_detect_connection_status_change(); } private void _detect_connection_status_change() { @@ -75,7 +75,7 @@ namespace bts { int n_bytes = buffer.Length; int n_transfers = 0; - while (total_bytes_sent < n_bytes) { + while (_is_alive && total_bytes_sent < n_bytes) { int remaining_bytes = n_bytes - total_bytes_sent; _nw_stream.Write(buffer, total_bytes_sent, remaining_bytes); total_bytes_sent += remaining_bytes; @@ -141,7 +141,7 @@ namespace bts { byte[] buffer = new byte[n_bytes]; int total_bytes_read = 0; int n_transfers = 0; - while (total_bytes_read < n_bytes) { + while (_is_alive && total_bytes_read < n_bytes) { int bytes_read = _nw_stream.Read(buffer, total_bytes_read, n_bytes - total_bytes_read); if (bytes_read <= 0) { throw new IOException("Read 0 bytes, the connection was closed before all data could be read."); @@ -201,6 +201,7 @@ namespace bts { if (one_msg.msg_type == DATA_MSG_SIGNAL) { _msg_handler.onData(new RemoteMessage(one_msg.data, RemoteMessageType.Data, _peer_conn_info)); } else if (one_msg.msg_type == HB_MSG_SIGNAL) { + // keep a last hb time an dudpate it here atomically _msg_handler.onData(new RemoteMessage(null, RemoteMessageType.Heartbeat, _peer_conn_info)); } else { throw new ApplicationException($"Unknown message type: {one_msg.msg_type}"); @@ -265,5 +266,11 @@ namespace bts { Dispose(); } } + + public override string ToString() { + RemoteConnectionInfo self = get_self_address(), + peer = get_peer_address(); + return $"type: {GetType().ToString()} self: {self} peer: {peer} is_disposed: {isDisposed}"; + } } } \ No newline at end of file diff --git a/src/DataStreamSuite/PubSub/ManagedTCP/ITCPConnection.cs b/src/DataStreamSuite/PubSub/ManagedTCP/ITCPConnection.cs index 8a1511ecc..9eff4ab4d 100644 --- a/src/DataStreamSuite/PubSub/ManagedTCP/ITCPConnection.cs +++ b/src/DataStreamSuite/PubSub/ManagedTCP/ITCPConnection.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using System.Text; namespace BCG { diff --git a/src/DataStreamSuite/PubSub/Server/Communication/ManagedTCP/ManagedTCPMessageHub.cs b/src/DataStreamSuite/PubSub/Server/Communication/ManagedTCP/ManagedTCPMessageHub.cs index a4d3d8216..19fab973d 100644 --- a/src/DataStreamSuite/PubSub/Server/Communication/ManagedTCP/ManagedTCPMessageHub.cs +++ b/src/DataStreamSuite/PubSub/Server/Communication/ManagedTCP/ManagedTCPMessageHub.cs @@ -15,13 +15,13 @@ using bts; namespace BCG { - // this is the main TCP message exchange in the pubsub server. It accepts connections, + // this is the main TCP message exchange in the pubsub server. It accepts connections, data, as well as send data public class ManagedTCPMessageHub : IPubsubMessageHub, // external facing interface to be used by PubSubMesage Reactor ITCPConnectionHandler, // interface to receive connections when calling ServerToClientManagedTCPConnectionAcceptor.accept_connections ITCPMessageHandler { // interface to receive data from ITCPConnection - private int _port; + private readonly int _port; private bool _is_disposed = false; - + // class used internally to queue messages from one trhead ot another private class ConnectionStatusInfo { public readonly string client_url; public readonly PubSubCallbacks.ConnectionStatus status; @@ -35,16 +35,16 @@ namespace BCG { private PubSubServerDataDelegate _data_cb; /// - /// client to connection + /// client to connection map /// private Dictionary _connection_map = new Dictionary(); /// /// data that is received from the client (on the onData thread) is queued in this - /// to be fetched by the client of this class in the getUpdates. + /// to be fetched by the client of this class in the get_updates. /// private SyncQueue> _received_data_queue; /// - /// data to be sent to the client is stored here and is fetched by the + /// data to be sent to the client is enqueued here and is fetched by the /// myDoItAll thread to be sent to the clients. the send is not directly sent out /// since there is some state management needed, so we do it on the main message /// pump thread @@ -58,26 +58,24 @@ namespace BCG { // _connection_cb arguments are queued here private ThreadSafeQueue _conn_callback_queue = new ThreadSafeQueue(); /// - /// new connections received (on the onConnection thread) is queued + /// new connections received (on the onConnection thread) are queued /// in this and will be fetched by the message_pump thread /// private ThreadSafeQueue _new_connections = new ThreadSafeQueue(); - /// - /// clients that sent heartbeats are stored in here - /// - private ThreadSafeQueue _received_hbs = new ThreadSafeQueue(); private readonly int _read_send_queue_timeout = 100;// just used to pass it on private readonly TimeSpan _hb_send_interval; private TimeSpan _subscriber_drop_threshold; - private TimeSpan _collect_disposed_connections_period = new TimeSpan(0, 0, 0, 0, 1000); + private TimeSpan _collect_disposed_connections_period = TimeSpan.FromMilliseconds(500); private DateTime _last_HB_collection_time = DateTime.Now; private DateTime _last_disposed_dead_collection_time = DateTime.Now; + // this si always active, accepting new client connections private AsyncTCPConnectionAcceptor_AsyncWrapper _connection_acceptor; // TODO, get public ManagedTCPMessageHub(int port, TimeSpan hb_send_interval, int missing_HBs_for_gc, TimeSpan collect_disposed_connections_period) { _port = port; + // what kind of connection_acceptor is controlled here _connection_acceptor = new AsyncTCPConnectionAcceptor_AsyncWrapper(_port, this); _hb_send_interval = hb_send_interval; _subscriber_drop_threshold = new TimeSpan(0, 0, 0, 0, Convert.ToInt32(hb_send_interval.TotalMilliseconds * missing_HBs_for_gc)); @@ -87,6 +85,7 @@ namespace BCG { #region IPubsubMessageHub Members + // this is unused right now, since the get_updates on a polling thread is called to by the client of this class to get messages public void register_data_callback(PubSubServerDataDelegate del) { bts.Log.assert_d(!_activated, "connection callbacks should be registered before the call to activate"); bts.Log.Gen.info("ManagedTCPMessageHub.register_data_callback called"); @@ -103,34 +102,34 @@ namespace BCG { _connection_acceptor.start(); bts.Log.Gen.info($"ManagedTCPMessageHub.activate TCP Component is ready, listening on port {_port} for incoming connections"); _activated = true; + // as the name says, all messages hand-off happen here Thread do_it_all_thread = new Thread(new ThreadStart(_main_message_pump)); do_it_all_thread.IsBackground = true; + do_it_all_thread.Priority = ThreadPriority.Highest; do_it_all_thread.Start(); } - public List> get_updates(TimeSpan timeout, int maxElements) { - return _received_data_queue.dequeueMultipleElements(timeout, maxElements); + // retutns the incoming either when timeout expires or n_elems are dequeued + public List> get_updates(TimeSpan timeout, int max_n_elems) { + return _received_data_queue.dequeueMultipleElements(timeout, max_n_elems); } + // similiar to above, but returns all the elements that have been received since the last time this function was called public List> get_all_updates() { return _received_data_queue.dequeue_all(); } - private bool _enqueue_send(string receiver, byte[] data) { - bts.Log.Gen.info($"ManagedTCPMessageHub._enqueue_send receiver: {receiver} data len: {data.Length}"); - _send_data_queue.enqueue(new Pair(receiver, data)); - return true; - } - - // public bool send(string receiver, System.IO.Stream str) { - // BinaryReader br = new BinaryReader(str); - // return send(receiver, br.ReadBytes(Convert.ToInt32(str.Length - str.Position))); + // private bool _enqueue_send(string receiver, byte[] data) { + // bts.Log.Gen.info($"ManagedTCPMessageHub._enqueue_send receiver: {receiver} data len: {data.Length}"); + // _send_data_queue.enqueue(new Pair(receiver, data)); + // return true; // } public bool send(string receiver, bts.PubSubServerMessage ps_msg) { - bts.Log.Gen.info($"ManagedTCPMessageHub.send receiver: {receiver} ps_msg: {ps_msg}"); var ps_msg_bytes = ps_msg.serialize_into_bytes(); - return _enqueue_send(receiver, ps_msg_bytes); + bts.Log.Gen.info($"ManagedTCPMessageHub.send receiver: {receiver} ps_msg: {ps_msg} serialized msg sz: {ps_msg_bytes.Length}"); + _send_data_queue.enqueue(new Pair(receiver, ps_msg_bytes)); + return true; } #endregion @@ -155,16 +154,13 @@ namespace BCG { #region ITCPConnectionHandler Members /// - /// Enqeues both the connection name (to be reported back - /// via ConnectionStatusChange) and connection (to be - /// stored in the hashtable and used for later communication). - /// This is called on an arbitrary thread. This is the only place where - /// clients connect to the pubsubserver + /// This is the only place where + /// clients connect to the pubsubserver. + /// The connection in qneueued, so we can report it back in the same thread /// /// public void onConnection(ITCPConnection connection) { - var client_rci = connection.get_peer_address(); - bts.Log.Gen.info($"ManagedTCPMessageHub.onConnection client_rci: {client_rci} connection_type: {connection.GetType()}"); + bts.Log.Gen.info($"ManagedTCPMessageHub.onConnection connection: {connection}"); _new_connections.enqueue(connection); } @@ -173,7 +169,7 @@ namespace BCG { #region ITCPMessageHandler Members // called by ITCPConnection on an arbitrary thread public void onData(RemoteMessage message) { - bts.Log.Gen.info($"ManagedTCPMessgageHub.onData recv msg: {message}"); + bts.Log.Gen.info($"ManagedTCPMessgageHub.onData message: {message}"); var sender_rci = message.remoteConnectionInfo; switch (message.messageType) { case RemoteMessageType.Data: @@ -184,12 +180,14 @@ namespace BCG { _received_data_queue.enqueue(new Pair(sender_rci.ToString(), message.message)); break; case RemoteMessageType.Connection: - // wont happen + // this conditional will never hit, because onData is ITCPConnection's callback, and ITCPConnection + // will not report a connection, connections are reported through ConnectionAcceptor break; case RemoteMessageType.Disconnection: + // we ignore this here, since in the pump thread function, we poll the connection and GC it if its disconnected break; case RemoteMessageType.Heartbeat: - // dont care about, if it goes missing, we'll get a disconnection message + // we dont need this either, since the HB time can be queried from the conneciton and GC'ed there and then break; default: bts.Log.assert_d(false, "Unknown message type"); @@ -203,10 +201,9 @@ namespace BCG { while (true) { try { while (true) { - // these are the connections that were received on onConnection + // these are the connections that were received on onConnection, written to _conn_callback_queue _handle_new_connections(); - - ///dead connections that are disposed + ///dead connections that are disposed, writtent to _conn_callback_queue _collect_disposed_connections(); Pair p = _send_data_queue.dequeue(_read_send_queue_timeout); @@ -248,8 +245,7 @@ namespace BCG { disposed_urls.Add(url); } foreach (string url in disposed_urls) { - string dispose_msg = $"Collecting disposed connections : {url} is disposed by the connection itself, " + - $"connection count before deleting this: {_connection_map.Count}"; + string dispose_msg = $"Collecting disposed connection: {url} connection count before deleting this: {_connection_map.Count}"; bts.Log.Gen.warn(dispose_msg); _connection_map.Remove(url); _conn_callback_queue.enqueue(new ConnectionStatusInfo(url, PubSubCallbacks.ConnectionStatus.DISCONNECTED)); @@ -257,18 +253,19 @@ namespace BCG { } } - // these are the connections that were added to _new_connections, on on_connect + // these are the connections that were added to _new_connections on onConnection // (which gets called in another thread) private void _handle_new_connections() { var new_conns = _new_connections.dequeueAll(); foreach (ITCPConnection conn in new_conns) { var peer_rci = conn.get_peer_address(); - bts.Log.Gen.info($"ManagedTCPMessageHub._handle_new_connections peer_rci: {peer_rci}"); + bts.Log.Gen.info($"ManagedTCPMessageHub._handle_new_connections conn: {conn}"); ///to stop it from being garbabge collected immediatly - _received_hbs.enqueue(peer_rci.ToString()); + // ot get data conn.register(this); _connection_map.Add(peer_rci.ToString(), conn); // enqueued here to call the user sub in doWork + // why not fire the handler here ? _conn_callback_queue.enqueue(new ConnectionStatusInfo(peer_rci.ToString(), PubSubCallbacks.ConnectionStatus.CONNECTED)); } } diff --git a/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs b/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs index 8d58808cc..805543fa0 100644 --- a/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs +++ b/src/DataStreamSuite/PubSub/Server/PubSubMessageReactor.cs @@ -59,6 +59,7 @@ namespace BCG { } + // the connection callback is the only event we get back from the message_hub. private void _handle_client_connection(string client, PubSubCallbacks.ConnectionStatus conn_status) { bts.Log.Gen.info($"PubsubMessageReactor._handle_client_connection client: {client} conn_status: {conn_status}"); ///interested in disconnections only, as connections of no diff --git a/src/DataStreamSuite/SharedStreams/System/PS3/Config b/src/DataStreamSuite/SharedStreams/System/PS3/Config new file mode 100644 index 000000000..e69de29bb diff --git a/src/DataStreamSuite/SharedStreams/System/PS3/Health/DeadPublisherTagsStream.cs b/src/DataStreamSuite/SharedStreams/System/PS3/Health/DeadPublisherTagsStream.cs index ccad30c47..63e89efba 100644 --- a/src/DataStreamSuite/SharedStreams/System/PS3/Health/DeadPublisherTagsStream.cs +++ b/src/DataStreamSuite/SharedStreams/System/PS3/Health/DeadPublisherTagsStream.cs @@ -1,19 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Text; +using bts; -namespace BCG -{ +namespace BCG { /// /// List of all the tags that result from a /// dead publisher, ie tags that have data /// but no active publisher /// - [DataStreamUserRespresentation ("deadPublisherTags")] - public class DeadPublisherTagsStream : ViewStream - { - public DeadPublisherTagsStream() - { + [DataStreamUserRespresentation("deadPublisherTags")] + public class DeadPublisherTagsStream : ViewStream { + public DeadPublisherTagsStream() { ViewStream serverState = new PubSubServerStateStream(); serverState = new FilterStream(serverState, "publishers='' and deadPublishers<>''"); serverState = new ProjectStream(serverState, "!subscribers publishers deadPublishers"); diff --git a/src/DataStreamSuite/SharedStreams/System/PS3/PubsubRouteStream.cs b/src/DataStreamSuite/SharedStreams/System/PS3/PubsubRouteStream.cs new file mode 100644 index 000000000..f1a69dcb0 --- /dev/null +++ b/src/DataStreamSuite/SharedStreams/System/PS3/PubsubRouteStream.cs @@ -0,0 +1,28 @@ +namespace BCG { + [DataStreamUserRespresentation("pss_routes")] + public class PubsubRouteStream : ViewStream { + private ViewStreamDatabase _vsd; + private IPubSubRouter _router = new PubSubRouter(); + + public PubsubRouteStream() + : this(ViewStreamDatabase.instance) { } + + public PubsubRouteStream(ViewStreamDatabase vsd) { + _vsd = vsd; + } + + protected override void myOnFirstSubscriber() { + IBlueTableSchema schema = BlueDataUtility.form_schema("PubSubRoutes", + Tuple.Create("id", TypeCode.Int32), + Tuple.Create("tag_regexp", TypeCode.String), + Tuple.Create("server_url", TypeCode.String)); + BlueTable rows = new BlueTable(schema); + var routes = _router.sub_routes(); + foreach (var route in routes) { + IBlueRow nr = new BlueRow(schema, rows.Count, route.tag_reg_exp, route.server_address); + rows.addRow(nr); + } + myFireEvent(new DataPacket(rows, rows, new BlueTable(schema))); + } + } +} \ No newline at end of file diff --git a/src/DataStreamSuite/SharedStreams/System/PS3/Stats/PubSubServerTagStatsStream.cs b/src/DataStreamSuite/SharedStreams/System/PS3/Stats/PubSubServerTagStatsStream.cs index 2f2acabcb..17e5a172a 100644 --- a/src/DataStreamSuite/SharedStreams/System/PS3/Stats/PubSubServerTagStatsStream.cs +++ b/src/DataStreamSuite/SharedStreams/System/PS3/Stats/PubSubServerTagStatsStream.cs @@ -5,9 +5,7 @@ using BCG.Utilities.General; using MathNet.Numerics.RootFinding; namespace bts { - - - [DataStreamUserRespresentation("tagStats")] + [DataStreamUserRespresentation("pss_stats")] public class PubSubServerTagStatsStream : ViewStream, IWorker { private SubscriberCore _sub_core; private ViewStreamDatabase _vsd; diff --git a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs index 6ec046d62..f395cfbfb 100644 --- a/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs +++ b/src/DataStreamSuite/SharedStreams/System/PS3/Subscription/PubSubServerStateStream.cs @@ -1,16 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Text; using BCG.Utilities.General; -using System.Collections; -using System.IO; -using MongoDB.Driver.Core.WireProtocol.Messages; +using BCG; -namespace BCG { +namespace bts { /// /// Gets the subscription and publication state for one /// server. /// + [DataStreamUserRespresentation("pss_state")] public class PubSubServerStateStream : ViewStream, IWorker { private IDictionary _tag_map = new Dictionary(); private readonly string _tag = "System_AllSubscriptions";