feat(GWC-37,WRK-32): refresh live alarm watch lists
This commit is contained in:
@@ -45,6 +45,7 @@ public sealed class AlarmCommandHandler : IAlarmCommandHandler
|
||||
private FailoverAlarmConsumer? failoverConsumer;
|
||||
private EventHandler<AlarmProviderModeChange>? providerModeChangedHandler;
|
||||
private string subscribeSessionId = string.Empty;
|
||||
private string subscriptionExpression = string.Empty;
|
||||
private bool disposed;
|
||||
|
||||
/// <summary>Initializes a new alarm command handler with the given event queue.</summary>
|
||||
@@ -153,6 +154,7 @@ public sealed class AlarmCommandHandler : IAlarmCommandHandler
|
||||
}
|
||||
|
||||
subscribeSessionId = sessionId ?? string.Empty;
|
||||
subscriptionExpression = command.SubscriptionExpression ?? string.Empty;
|
||||
IMxAccessAlarmConsumer consumer = BuildConsumer(command)
|
||||
?? throw new InvalidOperationException("Alarm consumer factory returned null.");
|
||||
|
||||
@@ -171,7 +173,7 @@ public sealed class AlarmCommandHandler : IAlarmCommandHandler
|
||||
dispatcher = new AlarmDispatcher(consumer, sink, subscribeSessionId);
|
||||
try
|
||||
{
|
||||
dispatcher.Subscribe(command.SubscriptionExpression ?? string.Empty);
|
||||
dispatcher.Subscribe(subscriptionExpression);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -212,7 +214,8 @@ public sealed class AlarmCommandHandler : IAlarmCommandHandler
|
||||
return BuildStandby(watchList);
|
||||
}
|
||||
|
||||
if (command.ForcedMode == AlarmProviderMode.Unspecified && watchList.Count > 0)
|
||||
if (command.ForcedMode == AlarmProviderMode.Unspecified
|
||||
&& (command.FallbackEnabled || watchList.Count > 0))
|
||||
{
|
||||
IMxAccessAlarmConsumer primary = consumerFactory()
|
||||
?? throw new InvalidOperationException("Alarm consumer factory returned null.");
|
||||
@@ -230,6 +233,26 @@ public sealed class AlarmCommandHandler : IAlarmCommandHandler
|
||||
?? throw new InvalidOperationException("Alarm consumer factory returned null.");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void UpdateWatchList(IReadOnlyList<AlarmSubtagTarget> watchList)
|
||||
{
|
||||
if (disposed) throw new ObjectDisposedException(nameof(AlarmCommandHandler));
|
||||
if (watchList is null) throw new ArgumentNullException(nameof(watchList));
|
||||
threadAffinityCheck?.Invoke();
|
||||
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (dispatcher is null || failoverConsumer is null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"UpdateAlarmWatchList requires an active fallback-capable alarm subscription.");
|
||||
}
|
||||
|
||||
IMxAccessAlarmConsumer replacement = BuildStandby(watchList);
|
||||
failoverConsumer.ReplaceStandby(replacement, subscriptionExpression);
|
||||
}
|
||||
}
|
||||
|
||||
private IMxAccessAlarmConsumer BuildStandby(IReadOnlyList<AlarmSubtagTarget> watchList)
|
||||
{
|
||||
if (standbyFactory is not null)
|
||||
@@ -276,6 +299,7 @@ public sealed class AlarmCommandHandler : IAlarmCommandHandler
|
||||
DetachProviderModeChanged();
|
||||
toDispose = dispatcher;
|
||||
dispatcher = null;
|
||||
subscriptionExpression = string.Empty;
|
||||
}
|
||||
toDispose?.Dispose();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user