2697af31d1
SdkServiceLevelPublisher writes Server.ServiceLevel through the SDK's ServerObjectState — the standard OPC UA non-transparent-redundancy signal clients use to pick a primary. Writes are guarded by DiagnosticsLock so concurrent SDK diagnostics scans don't fight with our updates. DeferredServiceLevelPublisher mirrors the DeferredAddressSpaceSink late- binding pattern: Akka actors resolve IServiceLevelPublisher at construction, hosted service swaps the SDK publisher in after StandardServer.Start. Host Program.cs registers DeferredServiceLevelPublisher as the singleton bound to IServiceLevelPublisher; OtOpcUaServerHostedService gets it injected and fills it once IServerInternal is available. Tests boot a real StandardServer on a free port (cross-platform), call Publish, then verify ServerObject.ServiceLevel.Value reflects the write. 5 new tests; OpcUaServer suite now 45/45 green (was 40, +5). Closes #81 residual. Unblocks Task 60 (OPC UA dual-endpoint + ServiceLevel tests).
20 lines
994 B
C#
20 lines
994 B
C#
namespace ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
|
|
|
/// <summary>
|
|
/// Late-binding adapter that holds an inner <see cref="IServiceLevelPublisher"/> reference
|
|
/// swappable at runtime. Mirrors <see cref="DeferredAddressSpaceSink"/>: Akka actors resolve
|
|
/// the publisher at DI time, but the production <c>SdkServiceLevelPublisher</c> only exists
|
|
/// after <c>StandardServer.Start</c>. The Host's hosted service swaps the inner once the SDK
|
|
/// is up; until then writes route through <see cref="NullServiceLevelPublisher"/>.
|
|
/// </summary>
|
|
public sealed class DeferredServiceLevelPublisher : IServiceLevelPublisher
|
|
{
|
|
private volatile IServiceLevelPublisher _inner = NullServiceLevelPublisher.Instance;
|
|
|
|
/// <summary>Swap the underlying publisher. Pass null to revert to the Null no-op.</summary>
|
|
public void SetInner(IServiceLevelPublisher? inner) =>
|
|
_inner = inner ?? NullServiceLevelPublisher.Instance;
|
|
|
|
public void Publish(byte serviceLevel) => _inner.Publish(serviceLevel);
|
|
}
|