using Akka.Actor;
using Akka.Cluster;
using Akka.Cluster.Tools.PublishSubscribe;
using Akka.Event;
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Redundancy;
using ZB.MOM.WW.OtOpcUa.Commons.Types;
using CommonsRedundancyRole = ZB.MOM.WW.OtOpcUa.Commons.Messages.Redundancy.RedundancyRole;
namespace ZB.MOM.WW.OtOpcUa.ControlPlane.Redundancy;
///
/// Admin-role cluster singleton that aggregates per-node cluster events into a
/// snapshot and publishes it on the redundancy-state
/// DistributedPubSub topic. Subscribers (notably the OPC UA host's ServiceLevel calc) react to
/// topology changes without polling.
///
/// Recomputation is debounced by — a burst of cluster events from
/// a rolling restart should produce one published snapshot, not one per event.
///
public sealed class RedundancyStateActor : ReceiveActor, IWithTimers
{
public const string Topic = "redundancy-state";
public static readonly TimeSpan DebounceWindow = TimeSpan.FromMilliseconds(250);
private readonly ILoggingAdapter _log = Context.GetLogger();
private readonly Akka.Cluster.Cluster _cluster;
private readonly Action