fix: Ensure PubSubTagHandlerFactory uses correct config
* Add this service as part of the PubSubClient services for dep
injection (it is needed by PublisherCore)
* Get rid of PublisherCore's default constructor, so dep injection
treats the tag handler factory as a required param (fails if it isn't
available)
- Replace the default ctr with a static "Create" fn, so code that
hasn't been updated to use dependency injection can still use that.
- Use PubSubConfig.Instance (runtime) instead of compile time Default
* Fix compile time Default config
- In fallback handler config, change Tag from "" to ".*" and move it
from the beginning of the list to the end (it should be the last
resort, not the other way around).
This commit is contained in:
1 parent
a07e7ea6b8
commit
d09f22007e
8 files changed
+26
-30
No files matched your search
@@ -9,7 +9,7 @@ namespace BCG {
|
||||
[DataStreamUserRespresentation("remoteQuery")]
|
||||
public class RemoteQueryStream : ViewStream {
|
||||
private readonly string _name, _stream_exp;
|
||||
private PublisherCore _publisher_core = new PublisherCore();
|
||||
private PublisherCore _publisher_core = PublisherCore.Create();
|
||||
private ViewStream _source_str;
|
||||
|
||||
public RemoteQueryStream(params string[] lines) {
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace bts
|
||||
private readonly int _msg_size;
|
||||
private readonly TimeSpan _publish_period;
|
||||
private DateTime _last_publish_time = DateTime.MinValue;
|
||||
private PublisherCore _pub_core = new PublisherCore();
|
||||
private PublisherCore _pub_core = PublisherCore.Create();
|
||||
private BlueTable _table;
|
||||
private int _n_pubs = 0;
|
||||
private readonly int _max_pubs;
|
||||
@@ -224,4 +224,4 @@ namespace bts
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,7 +123,7 @@ namespace bts
|
||||
|
||||
protected override void myOnFirstSubscriber()
|
||||
{
|
||||
_pub_core = new PublisherCore(_router);
|
||||
_pub_core = PublisherCore.Create(_router);
|
||||
_sub_core = new SubscriberCore(_router);
|
||||
_sub_core.subscribe(_tag_name);
|
||||
_vsd.addWorker(this);
|
||||
|
||||
@@ -1,15 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
using BCG.Utilities;
|
||||
|
||||
using bts;
|
||||
|
||||
using Bts.DataStreamCore;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BCG {
|
||||
/// <summary>
|
||||
/// This class will be used by the clients to publish tabular data to the pubsub
|
||||
@@ -22,7 +17,7 @@ namespace BCG {
|
||||
protected bool myWaitingForFirstOp = false;
|
||||
|
||||
public PubTableBroker()
|
||||
: this(new PublisherCore()) { }
|
||||
: this(PublisherCore.Create()) { }
|
||||
|
||||
public PubTableBroker(IPublisherCore publisher) {
|
||||
_publisher_core = publisher;
|
||||
|
||||
@@ -17,11 +17,6 @@ public class PubSubTagHandlerFactoryConfig {
|
||||
public static PubSubTagHandlerFactoryConfig Default() {
|
||||
return new() {
|
||||
Handlers = new() {
|
||||
new() {
|
||||
TagType = string.Empty,
|
||||
Assembly = "DataStreamCore",
|
||||
Class = "bts.PubsubServerStreamTagHandler",
|
||||
},
|
||||
new() {
|
||||
TagType = DSTagManager.DataStreamTagType,
|
||||
Assembly = "DataStreamCore",
|
||||
@@ -36,7 +31,12 @@ public class PubSubTagHandlerFactoryConfig {
|
||||
TagType = "System_Stats",
|
||||
Assembly = "PubSub",
|
||||
Class = "BCG.SystemStatsPublisher",
|
||||
}
|
||||
},
|
||||
new() {
|
||||
TagType = ".*",
|
||||
Assembly = "DataStreamCore",
|
||||
Class = "bts.PubsubServerGenericDataHandler",
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -43,10 +43,7 @@ namespace BCG {
|
||||
|
||||
#region constructors
|
||||
|
||||
public PublisherCore(IPubSubRouter? router = null, IPubSubTagHandlerFactory? tagHandlerFactory = null, IServiceProvider? serviceProvider = null) {
|
||||
router ??= new PubSubRouter();
|
||||
serviceProvider ??= PubSubServices.ServiceProvider;
|
||||
tagHandlerFactory ??= new PubsubTagHandlerFactory(serviceProvider, PubSubTagHandlerFactoryConfig.Default());
|
||||
public PublisherCore(IPubSubRouter router, IPubSubTagHandlerFactory tagHandlerFactory) {
|
||||
_router = router;
|
||||
_state = new(tagHandlerFactory);
|
||||
Thread pump_thread = new Thread(new ThreadStart(_message_pump));
|
||||
@@ -54,6 +51,14 @@ namespace BCG {
|
||||
pump_thread.Start();
|
||||
}
|
||||
|
||||
public static PublisherCore Create(IPubSubRouter? router = null, IPubSubTagHandlerFactory? tagHandlerFactory = null, IServiceProvider? serviceProvider = null) {
|
||||
router ??= new PubSubRouter();
|
||||
tagHandlerFactory ??= new PubsubTagHandlerFactory(
|
||||
serviceProvider ?? PubSubServices.ServiceProvider,
|
||||
PubSubConfig.Instance.TagHandlerFactory ?? PubSubTagHandlerFactoryConfig.Default());
|
||||
return new(router, tagHandlerFactory);
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -114,6 +114,7 @@ public static class PubSubServices {
|
||||
PubSubConfig.SetGlobalConfig(configurationSection.Get<PubSubConfig>() ?? PubSubConfig.Default());
|
||||
return services.AddGlobalServiceProvider()
|
||||
.AddPubSubRouter(configurationSection.GetSection(nameof(PubSubConfig.Routing)))
|
||||
.AddTagHandlerFactory(configurationSection.GetSection(nameof(PubSubConfig.TagHandlerFactory)))
|
||||
.AddPublisherCore()
|
||||
.AddSubscriberCore()
|
||||
.AddManagedSubscriber();
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
using BCG;
|
||||
|
||||
using bts;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BCG {
|
||||
public class TestPubItem : IPubItem {
|
||||
@@ -24,7 +19,7 @@ namespace BCG {
|
||||
}
|
||||
public class TestPublisher {
|
||||
TestPubItem _tbi = new TestPubItem();
|
||||
IPublisherCore pcore = new PublisherCore();
|
||||
IPublisherCore pcore = PublisherCore.Create();
|
||||
bool _hit_key_to_send = false;
|
||||
public TestPublisher(bool hit_key_to_send) {
|
||||
_hit_key_to_send = hit_key_to_send;
|
||||
@@ -50,4 +45,4 @@ namespace BCG {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user