using Akka.Actor;
using Akka.Cluster.Tools.PublishSubscribe;
using Akka.Event;
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Drivers;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Hubs;
///
/// Akka actor that subscribes to the driver-resilience-status DistributedPubSub topic and
/// upserts every snapshot into the in-process
/// . The driver status panel's resilience section reads
/// that store directly (per the house ban on server-side self-targeted SignalR connections), so —
/// unlike — there is no SignalR hub here; resilience has no
/// browser-JS consumer. Spawned per admin-role node by WithOtOpcUaSignalRBridges.
///
public sealed class DriverResilienceStatusBridge : ReceiveActor
{
public const string TopicName = DriverResilienceStatusChanged.TopicName;
private readonly IDriverResilienceStatusStore _store;
private readonly ILoggingAdapter _log = Context.GetLogger();
/// Creates actor props for a .
/// Resilience status store updated on every forwarded snapshot.
/// An Akka.NET instance for spawning the bridge actor.
public static Props Props(IDriverResilienceStatusStore store) =>
Akka.Actor.Props.Create(() => new DriverResilienceStatusBridge(store));
/// Initializes a new instance of .
/// Resilience status store updated on every forwarded snapshot.
public DriverResilienceStatusBridge(IDriverResilienceStatusStore store)
{
_store = store;
Receive(msg =>
{
// A store failure must not restart the bridge (a restart re-subscribes DPS and drops messages).
try { _store.Upsert(msg); }
catch (Exception ex) { _log.Warning(ex, "DriverResilienceStatusBridge: upsert failed for {0}", msg.DriverInstanceId); }
});
Receive(_ => { /* DPS confirmation */ });
}
///
protected override void PreStart() =>
DistributedPubSub.Get(Context.System).Mediator.Tell(new Subscribe(TopicName, Self));
}