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

This commit is contained in:
Joseph Doherty
2026-02-20 13:03:21 -05:00
commit 08bfc17218
218 changed files with 33910 additions and 0 deletions

View 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();
}