feat(grpc-data): A1 initial-alarm-state signal in DriverInstanceActor/DriverHostActor — ordered forward, MarkConditionsKnown routing, OpcUaClient backstop, F5 signal timeout + diagnostic
This commit is contained in:
@@ -232,6 +232,12 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
/// to the materialised Part 9 condition. Parallels <see cref="AttributeValueBatchPublished"/>.</summary>
|
||||
public sealed record AttributeAlarmPublished(string DriverInstanceId, AlarmEventArgs Args);
|
||||
private sealed record NativeAlarmRaised(AlarmEventArgs Args);
|
||||
/// <summary>A1 (plan §5.1 F2): published to the parent when the driver raises
|
||||
/// <see cref="IAlarmInitialStateSignal.InitialAlarmStateDelivered"/>. It travels the SAME self-Tell → parent path as
|
||||
/// <see cref="AttributeAlarmPublished"/>, so it reaches <see cref="DriverHostActor"/> after every alarm event the
|
||||
/// driver raised before it.</summary>
|
||||
public sealed record AlarmInitialStatePublished(string DriverInstanceId, AlarmInitialStateEventArgs Args);
|
||||
private sealed record NativeAlarmInitialState(AlarmInitialStateEventArgs Args);
|
||||
/// <summary>Self-sent on Connected entry / when alarm refs are (re)pushed, to establish the native-alarm
|
||||
/// subscription that un-gates an <see cref="IAlarmSource"/> driver's feed. Handled async so the
|
||||
/// <see cref="IAlarmSource.SubscribeAlarmsAsync"/> call is bounded + off the synchronous handlers.</summary>
|
||||
@@ -496,6 +502,9 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
private sealed record ResumeDeferredLegacy;
|
||||
private const int SourceBindingBatchSize = 128;
|
||||
private EventHandler<AlarmEventArgs>? _alarmEventHandler;
|
||||
// A1 (plan §5.1 G5): attached and detached WITH the alarm handler, so the signal obeys exactly the gate
|
||||
// OnAlarmEvent obeys.
|
||||
private EventHandler<AlarmInitialStateEventArgs>? _alarmInitialStateHandler;
|
||||
private EventHandler<RediscoveryEventArgs>? _rediscoveryHandler;
|
||||
private EventHandler<HostStatusChangedEventArgs>? _hostStatusHandler;
|
||||
private EventHandler<DriverConnectionLossEventArgs>? _connectionLossHandler;
|
||||
@@ -873,6 +882,9 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
// own thread); drop it — the feed re-delivers active alarms once Connected. Trace only.
|
||||
Receive<NativeAlarmRaised>(_ =>
|
||||
_log.Debug("DriverInstance {Id}: native alarm arrived during connect — dropped (feed re-delivers)", _driverInstanceId));
|
||||
// Its initial-state signal is dropped with it: a signal must never outlive the alarm events it covers.
|
||||
Receive<NativeAlarmInitialState>(_ =>
|
||||
_log.Debug("DriverInstance {Id}: initial alarm-state signal arrived during connect — dropped", _driverInstanceId));
|
||||
// A SubscribeAlarms self-tell (from Connected) can be overtaken by an already-queued disconnect into
|
||||
// this state; swallow it so it doesn't dead-letter — the next Connected entry re-subscribes.
|
||||
Receive<SubscribeAlarms>(_ => { });
|
||||
@@ -987,6 +999,8 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
// Native alarm transition marshaled onto the actor thread from the driver's OnAlarmEvent;
|
||||
// project it to the parent the same way DataChangeForward projects AttributeValueBatchPublished.
|
||||
Receive<NativeAlarmRaised>(m => Context.Parent.Tell(new AttributeAlarmPublished(_driverInstanceId, m.Args)));
|
||||
// A1 F2: the same mailbox and the same forward, so the signal follows every alarm event raised before it.
|
||||
Receive<NativeAlarmInitialState>(m => Context.Parent.Tell(new AlarmInitialStatePublished(_driverInstanceId, m.Args)));
|
||||
// ResubscribeDesired self-Tells Subscribe; HandleSubscribeAsync replies SubscriptionEstablished to the
|
||||
// sender, which on the self-resubscribe path is Self. Swallow it (trace only) so it doesn't dead-letter.
|
||||
Receive<SubscriptionEstablished>(msg =>
|
||||
@@ -1235,6 +1249,8 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
// own thread); drop it — the feed re-delivers active alarms once Connected. Trace only.
|
||||
Receive<NativeAlarmRaised>(_ =>
|
||||
_log.Debug("DriverInstance {Id}: native alarm arrived during reconnect — dropped (feed re-delivers)", _driverInstanceId));
|
||||
Receive<NativeAlarmInitialState>(_ =>
|
||||
_log.Debug("DriverInstance {Id}: initial alarm-state signal arrived during reconnect — dropped", _driverInstanceId));
|
||||
// A SubscribeAlarms self-tell (from Connected) can be overtaken by an already-queued disconnect into
|
||||
// this state; swallow it so it doesn't dead-letter — the next Connected entry re-subscribes.
|
||||
Receive<SubscribeAlarms>(_ => { });
|
||||
@@ -2539,6 +2555,11 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
var self = Self;
|
||||
_alarmEventHandler = (_, e) => self.Tell(new NativeAlarmRaised(e));
|
||||
src.OnAlarmEvent += _alarmEventHandler;
|
||||
if (_driver is IAlarmInitialStateSignal signal)
|
||||
{
|
||||
_alarmInitialStateHandler = (_, e) => self.Tell(new NativeAlarmInitialState(e));
|
||||
signal.InitialAlarmStateDelivered += _alarmInitialStateHandler;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Subscribe the driver's <see cref="IRediscoverable.OnRediscoveryNeeded"/> (if it is one),
|
||||
@@ -2716,6 +2737,9 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
if (_driver is IAlarmSource src && _alarmEventHandler is not null)
|
||||
src.OnAlarmEvent -= _alarmEventHandler;
|
||||
_alarmEventHandler = null;
|
||||
if (_driver is IAlarmInitialStateSignal signal && _alarmInitialStateHandler is not null)
|
||||
signal.InitialAlarmStateDelivered -= _alarmInitialStateHandler;
|
||||
_alarmInitialStateHandler = null;
|
||||
// Drop our handle so the next Connected entry re-subscribes; the desired alarm refs persist across
|
||||
// reconnects. NOTE: this does NOT tear down the driver-side subscription. For a session-bound
|
||||
// IAlarmSource the old subscription dies with the session (no accumulation). For a session-less feed
|
||||
|
||||
Reference in New Issue
Block a user