Initial import of the CBDDC codebase with docs and tests. Add a .NET-focused gitignore to keep generated artifacts out of source control.
Some checks failed
CI / verify (push) Has been cancelled
Some checks failed
CI / verify (push) Has been cancelled
This commit is contained in:
65
src/ZB.MOM.WW.CBDDC.Network/Leadership/ILeaderElectionService.cs
Executable file
65
src/ZB.MOM.WW.CBDDC.Network/Leadership/ILeaderElectionService.cs
Executable file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZB.MOM.WW.CBDDC.Network.Leadership;
|
||||
|
||||
/// <summary>
|
||||
/// Event arguments for leadership change events.
|
||||
/// </summary>
|
||||
public class LeadershipChangedEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the NodeId of the current cloud gateway (leader).
|
||||
/// Null if no leader is elected.
|
||||
/// </summary>
|
||||
public string? CurrentGatewayNodeId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the local node is now the cloud gateway.
|
||||
/// </summary>
|
||||
public bool IsLocalNodeGateway { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the LeadershipChangedEventArgs class.
|
||||
/// </summary>
|
||||
/// <param name="currentGatewayNodeId">The NodeId of the current gateway node, or <see langword="null"/> when none is elected.</param>
|
||||
/// <param name="isLocalNodeGateway">A value indicating whether the local node is the gateway.</param>
|
||||
public LeadershipChangedEventArgs(string? currentGatewayNodeId, bool isLocalNodeGateway)
|
||||
{
|
||||
CurrentGatewayNodeId = currentGatewayNodeId;
|
||||
IsLocalNodeGateway = isLocalNodeGateway;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public interface ILeaderElectionService
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets whether the local node is currently the cloud gateway (leader).
|
||||
/// </summary>
|
||||
bool IsCloudGateway { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the NodeId of the current cloud gateway, or null if no gateway is elected.
|
||||
/// </summary>
|
||||
string? CurrentGatewayNodeId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when leadership changes.
|
||||
/// </summary>
|
||||
event EventHandler<LeadershipChangedEventArgs>? LeadershipChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Starts the leader election service.
|
||||
/// </summary>
|
||||
Task Start();
|
||||
|
||||
/// <summary>
|
||||
/// Stops the leader election service.
|
||||
/// </summary>
|
||||
Task Stop();
|
||||
}
|
||||
Reference in New Issue
Block a user