using System; using System.Threading.Tasks; namespace ZB.MOM.WW.CBDDC.Network.Leadership; /// /// Event arguments for leadership change events. /// public class LeadershipChangedEventArgs : EventArgs { /// /// Gets the NodeId of the current cloud gateway (leader). /// Null if no leader is elected. /// public string? CurrentGatewayNodeId { get; } /// /// Gets whether the local node is now the cloud gateway. /// public bool IsLocalNodeGateway { get; } /// /// Initializes a new instance of the LeadershipChangedEventArgs class. /// /// The NodeId of the current gateway node, or when none is elected. /// A value indicating whether the local node is the gateway. public LeadershipChangedEventArgs(string? currentGatewayNodeId, bool isLocalNodeGateway) { CurrentGatewayNodeId = currentGatewayNodeId; IsLocalNodeGateway = isLocalNodeGateway; } } /// /// Service for managing leader election in a distributed cluster. /// Uses the Bully algorithm where the node with the lexicographically smallest NodeId becomes the leader. /// Only the leader (Cloud Gateway) synchronizes with remote cloud nodes. /// public interface ILeaderElectionService { /// /// Gets whether the local node is currently the cloud gateway (leader). /// bool IsCloudGateway { get; } /// /// Gets the NodeId of the current cloud gateway, or null if no gateway is elected. /// string? CurrentGatewayNodeId { get; } /// /// Event raised when leadership changes. /// event EventHandler? LeadershipChanged; /// /// Starts the leader election service. /// Task Start(); /// /// Stops the leader election service. /// Task Stop(); }