feat(grpc-data): A1 — Galaxy raises InitialAlarmStateDelivered on every snapshot_complete sentinel
This commit is contained in:
@@ -38,7 +38,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy;
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class GalaxyDriver
|
||||
: IDriver, ITagDiscovery, IReadable, IWritable, ISubscribable, IRediscoverable, IHostConnectivityProbe, IAlarmSource, IAlarmAcknowledgePreflight, IAlarmAcknowledgeConfirmation, ISkippedTagReporter, IDisposable, IAsyncDisposable
|
||||
: IDriver, ITagDiscovery, IReadable, IWritable, ISubscribable, IRediscoverable, IHostConnectivityProbe, IAlarmSource, IAlarmInitialStateSignal, IAlarmAcknowledgePreflight, IAlarmAcknowledgeConfirmation, ISkippedTagReporter, IDisposable, IAsyncDisposable
|
||||
{
|
||||
/// <summary>Authored tags this driver could not dial — a TagConfig with no usable
|
||||
/// <c>attributeRef</c> has no MXAccess address to bind.</summary>
|
||||
@@ -162,6 +162,10 @@ public sealed class GalaxyDriver
|
||||
// handles are added/removed (HashSet.First() is unstable).
|
||||
private readonly List<GalaxyAlarmSubscriptionHandle> _alarmSubscriptions = new();
|
||||
|
||||
// grpc-data A1: the alarm refs (RawPaths) of the live subscription — what a sentinel signal covers. Under
|
||||
// _alarmHandlersLock, replaced with the handle.
|
||||
private IReadOnlyList<string> _alarmSubscriptionRefs = Array.Empty<string>();
|
||||
|
||||
// Production runtime owned by InitializeAsync (BuildProductionRuntimeAsync). The
|
||||
// driver builds these when it opens a real gw session; tests bypass them by
|
||||
// injecting seams via the internal ctor, which leaves both fields null and skips
|
||||
@@ -300,6 +304,15 @@ public sealed class GalaxyDriver
|
||||
/// <summary>Raised when the gateway reports an alarm event for a subscribed Galaxy attribute.</summary>
|
||||
public event EventHandler<AlarmEventArgs>? OnAlarmEvent;
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <remarks>
|
||||
/// grpc-data A1 (§5.1): raised on the feed thread for every <c>snapshot_complete</c> sentinel — after the
|
||||
/// snapshot entries were bridged to <see cref="OnAlarmEvent"/> — covering every alarm ref of the live
|
||||
/// subscription. Suppressed exactly like <see cref="OnAlarmEvent"/> (G5): nothing while no alarm
|
||||
/// subscription is live.
|
||||
/// </remarks>
|
||||
public event EventHandler<AlarmInitialStateEventArgs>? InitialAlarmStateDelivered;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="GalaxyDriver"/> class.</summary>
|
||||
/// <param name="driverInstanceId">The unique identifier for this driver instance.</param>
|
||||
/// <param name="options">The Galaxy driver configuration options.</param>
|
||||
@@ -1069,6 +1082,7 @@ public sealed class GalaxyDriver
|
||||
if (alarmFeed is not null && _alarmFeedWired)
|
||||
{
|
||||
alarmFeed.OnAlarmTransition -= OnAlarmFeedTransition;
|
||||
alarmFeed.SnapshotDelivered -= OnAlarmFeedSnapshotDelivered;
|
||||
_alarmFeedWired = false;
|
||||
}
|
||||
if (releaseFeed) _alarmFeed = null;
|
||||
@@ -2725,6 +2739,7 @@ public sealed class GalaxyDriver
|
||||
}
|
||||
if (_alarmFeedWired) return;
|
||||
_alarmFeed.OnAlarmTransition += OnAlarmFeedTransition;
|
||||
_alarmFeed.SnapshotDelivered += OnAlarmFeedSnapshotDelivered;
|
||||
_alarmFeed.Start();
|
||||
_alarmFeedWired = true;
|
||||
}
|
||||
@@ -2756,6 +2771,7 @@ public sealed class GalaxyDriver
|
||||
// replacing the set with the latest handle is semantically faithful and bounds it at 1.
|
||||
_alarmSubscriptions.Clear();
|
||||
_alarmSubscriptions.Add(handle);
|
||||
_alarmSubscriptionRefs = sourceNodeIds.ToArray();
|
||||
}
|
||||
return Task.FromResult<IAlarmSubscriptionHandle>(handle);
|
||||
}
|
||||
@@ -2774,6 +2790,7 @@ public sealed class GalaxyDriver
|
||||
lock (_alarmHandlersLock)
|
||||
{
|
||||
_alarmSubscriptions.Remove(gash);
|
||||
if (_alarmSubscriptions.Count == 0) _alarmSubscriptionRefs = Array.Empty<string>();
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
@@ -3003,6 +3020,30 @@ public sealed class GalaxyDriver
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// grpc-data A1 (§5.1, Galaxy row): the feed's <c>snapshot_complete</c> sentinel, on the feed thread after
|
||||
/// the snapshot entries were bridged. Signals the live subscription's refs; nothing while unsubscribed (G5).
|
||||
/// </summary>
|
||||
private void OnAlarmFeedSnapshotDelivered(object? sender, EventArgs e)
|
||||
{
|
||||
IReadOnlyList<string> refs;
|
||||
lock (_alarmHandlersLock)
|
||||
{
|
||||
if (_alarmSubscriptions.Count == 0) return;
|
||||
refs = _alarmSubscriptionRefs;
|
||||
}
|
||||
|
||||
if (refs.Count == 0) return;
|
||||
try
|
||||
{
|
||||
InitialAlarmStateDelivered?.Invoke(this, new AlarmInitialStateEventArgs(refs));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "GalaxyDriver InitialAlarmStateDelivered handler threw — continuing.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Forwards every fan-out event to the public <see cref="OnDataChange"/> for
|
||||
/// ISubscribable consumers, AND routes ScanState changes to the per-platform
|
||||
|
||||
@@ -74,6 +74,9 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
/// <summary>Occurs when an alarm transition (raise, acknowledge, clear) is received from the Galaxy feed.</summary>
|
||||
public event EventHandler<GalaxyAlarmTransition>? OnAlarmTransition;
|
||||
|
||||
/// <inheritdoc />
|
||||
public event EventHandler? SnapshotDelivered;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="GatewayGalaxyAlarmFeed"/> class.</summary>
|
||||
/// <param name="streamFactory">A factory delegate that opens the alarm stream.</param>
|
||||
/// <param name="logger">An optional logger for diagnostic output.</param>
|
||||
@@ -166,6 +169,9 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
case AlarmFeedMessage.PayloadOneofCase.SnapshotComplete:
|
||||
_logger.LogDebug("Galaxy alarm feed active-alarm snapshot complete.");
|
||||
_initialSnapshot.TrySetResult();
|
||||
// grpc-data A1: the ordered per-sentinel signal — on THIS thread, after the snapshot entries above
|
||||
// were raised; every reopened stream's sentinel raises it again.
|
||||
RaiseSnapshotDelivered();
|
||||
break;
|
||||
default:
|
||||
// Empty oneof — worker / gateway version skew. Count and drop.
|
||||
@@ -272,6 +278,18 @@ internal sealed class GatewayGalaxyAlarmFeed : IGalaxyAlarmFeed
|
||||
}
|
||||
}
|
||||
|
||||
private void RaiseSnapshotDelivered()
|
||||
{
|
||||
try
|
||||
{
|
||||
SnapshotDelivered?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(ex, "Galaxy alarm feed SnapshotDelivered handler threw — continuing.");
|
||||
}
|
||||
}
|
||||
|
||||
private static GalaxyAlarmTransitionKind MapTransitionKind(AlarmTransitionKind kind) => kind switch
|
||||
{
|
||||
AlarmTransitionKind.Raise => GalaxyAlarmTransitionKind.Raise,
|
||||
|
||||
@@ -36,4 +36,14 @@ internal interface IGalaxyAlarmFeed : IAsyncDisposable
|
||||
/// task, for feeds with no snapshot phase (the test fakes raise synchronously).
|
||||
/// </summary>
|
||||
Task InitialSnapshotCompleted => Task.CompletedTask;
|
||||
|
||||
/// <summary>
|
||||
/// Raised synchronously on the feed thread for <b>every</b> <c>snapshot_complete</c> sentinel — the first
|
||||
/// one and the one after each stream reopen — after every snapshot entry of that stream was raised on
|
||||
/// <see cref="OnAlarmTransition"/>. The ordered "standing alarms delivered" point the driver turns into
|
||||
/// <c>IAlarmInitialStateSignal.InitialAlarmStateDelivered</c> (grpc-data plan §5.1, A1). Unlike
|
||||
/// <see cref="InitialSnapshotCompleted"/> it is not one-shot and never runs as a task continuation (F2).
|
||||
/// The default accessors make it a no-op for feeds with no snapshot phase.
|
||||
/// </summary>
|
||||
event EventHandler? SnapshotDelivered { add { } remove { } }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user