From 970555d2a1a5f5b6f1442efd7195b647ee3be4dc Mon Sep 17 00:00:00 2001 From: John Colvin Date: Sat, 27 Jul 2024 16:59:59 +0000 Subject: [PATCH] diag: Assert ViewStreamDatabase.instance is only created once The instance must be initialized via ViewStreamDatabase.SetGlobalInstance --- .../DataStreamCore/ViewStreamDatabase.cs | 33 ++++++++----------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/DataStreamSuite/DataStreamCore/ViewStreamDatabase.cs b/src/DataStreamSuite/DataStreamCore/ViewStreamDatabase.cs index f869cd50a..3ed02d435 100644 --- a/src/DataStreamSuite/DataStreamCore/ViewStreamDatabase.cs +++ b/src/DataStreamSuite/DataStreamCore/ViewStreamDatabase.cs @@ -1,5 +1,7 @@ using BCG.Utilities.General; +using bts; + using Bts.PubSub; using System; @@ -30,30 +32,19 @@ namespace BCG { public ViewStreamDatabase(ISubscriberCoreFactory subscriberCoreFactory) : this(subscriberCoreFactory.Create()) { } - // This ctr is private to ensure the ISubscriberCore is created by ISubscriberCoreFactory - // (we'll temporarily continue to use it internally to create ViewStreamDatabase.instance, - // but new code should use the factory). The factory itself is created via dependency - // injection so it has the correct runtime config (for pubsub routing, etc.). + // This ctr is private to ensure the ISubscriberCore is created by ISubscriberCoreFactory. The + // factory itself is created via dependency injection so it has the correct runtime config + // (for pubsub routing, etc.). ViewStreamDatabase(ISubscriberCore subscriberCore) { mySubscriberCore = subscriberCore; } public static ViewStreamDatabase instance { get { - if (mySelf == null || mySelf.myIsDisposed) - lock (myInstanceLockObject) { - if (mySelf == null || mySelf.myIsDisposed) { - mySelf = new ViewStreamDatabase(new SubscriberCore()); - } - } - return mySelf; - } - set { - lock (myInstanceLockObject) { - if (mySelf != null) - mySelf.mySubscriberCore.Dispose(); - mySelf = value; - } + var rv = mySelf; + Log.notnull(rv); + Log.assert(!rv.myIsDisposed); + return rv; } } @@ -197,8 +188,10 @@ namespace BCG { } internal static void SetGlobalInstance(ViewStreamDatabase vsd) { - Log.isnull(mySelf); - mySelf = vsd; + lock (myInstanceLockObject) { + Log.isnull(mySelf); + mySelf = vsd; + } } private List _pending_worker_ops = new List();