Example #1
0
 public HartbeatTimer(RaftOptions options,
     ILoggerFactory loggerFactory, 
     ServerIdentifier serverIdentifier)
 {
     _options = options;
     _logger = loggerFactory.CreateLogger(nameof(HartbeatTimer) + " " + serverIdentifier);
     _serverIdentifier = serverIdentifier;
     _random = new Random();
 }
Example #2
0
        public RaftClient(ServerIdentifier serverIdentifier,
            IObserver<ClientMessage> changeMessage,
            IObservable<ClientResultMessage> clientResult,
            RaftOptions options,
            ILoggerFactory loggerFactory)
        {
            _serverIdentifier = serverIdentifier;
            _changeMessage = changeMessage;
            _clientResult = clientResult;
            _options = options;
            _logger = loggerFactory.CreateLogger<RaftClient>();

        }
Example #3
0
 public VoteReceived(IObserver<RequestVoteResultMessage> voteReply,
     ServerIdentifier serverIdentifier,
     IObservable<RequestVoteMessage> requestVote, 
     Election election,
     ILoggerFactory loggerFactory,
     Nodes nodes,
     RaftOptions options, 
     ILogReplication logReplication)
 {
     _voteReply = voteReply;
     _election = election;
     _nodes = nodes;
     _options = options;
     _logReplication = logReplication;
     _serverIdentifier = serverIdentifier;
     _voteReceivedDisposable = requestVote.Subscribe(VoteRequestReceived);
     _logger = loggerFactory.CreateLogger(nameof(VoteReceived) + " " + serverIdentifier);
 }
Example #4
0
 public AppendEntry(IObserver<AppendEntryResultMessage> entryReply,
    IObservable<AppendEntryMessage> receivedAppendEntryMessage,
    IHartbeatTimer hartbeat,
    ILogReplication logReplication, 
    Election election,
    ILoggerFactory loggerFactory,
    RaftOptions options, 
    ServerIdentifier serverIdentifier,
    IEnumerable<IRaftService> services)
 {
     _entryReply = entryReply;
     _hartbeat = hartbeat;
     _receivedDisposable =  receivedAppendEntryMessage.Subscribe(RaciveHartbeat);
     _logReplication = logReplication;
     _election = election;
     _options = options;
     _serverIdentifier = serverIdentifier;
     _services = services;
     _logger = loggerFactory.CreateLogger(nameof(AppendEntry) + " " + serverIdentifier);
 }
Example #5
0
        public Node(IVoteReceived voteReceived, 
            IAppendEntry appendEntry, 
            IHartbeatTimer hartbeat, 
            ILoggerFactory loggerFactory, 
            IObservableProvider observableProvider,
            ILogReplication logReplication,
            ServerIdentifier serverIdentifier)
        {
            _logReplication = logReplication;
            _serverIdentifier = serverIdentifier;
            _hartbeatTimer = hartbeat;

            _stateMachine = new Machine<ServerStateType, ServerStateType>(ServerStateType.Candidate,
                loggerFactory, observableProvider);

            _stateMachine.On(ServerStateType.Follower)
                .OnEntry(() =>
                {
                    hartbeat.Subscribe(_stateMachine);
                })
                .OnEntrySubscribe<Follower>()
                .Permit(ServerStateType.Candidate, ServerStateType.Candidate);

            _stateMachine.On(ServerStateType.Candidate)
                .OnEntrySubscribe<Candidate>()
                .OnEntry(hartbeat.Reset)
                .Permit(ServerStateType.Follower, ServerStateType.Follower)
                .Permit(ServerStateType.Leader, ServerStateType.Leader)
                .Permit(ServerStateType.Candidate, ServerStateType.Candidate);

            _stateMachine.On(ServerStateType.Leader)
                .OnEntrySubscribe<Leader>()
                .Permit(ServerStateType.Follower, ServerStateType.Follower);

            _voteReceivedeDispose = voteReceived.Subscribe(_stateMachine);
            _appendEntryDispose = appendEntry.Subscribe(_stateMachine);
            _stateMachine.OnNext(ServerStateType.Follower);
        }
 public void AddVote(ServerIdentifier @from, ServerIdentifier candidate)
 {
     if (!_voteBox.ContainsKey(from))
         _voteBox.TryAdd(from, candidate);
 }
 public FirstPastThePost(ServerIdentifier serverIdentifier)
 {
     _serverIdentifier = serverIdentifier;
     _voteBox = new ConcurrentDictionary<ServerIdentifier, ServerIdentifier>();
 }
 public bool Equals(ServerIdentifier other)
 {
     return Id.Equals(other.Id);
 }