コード例 #1
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);
 }
コード例 #2
0
ファイル: Node.cs プロジェクト: RossMerr/Caudex.Rafting
        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);
        }
コード例 #3
-1
ファイル: Leader.cs プロジェクト: RossMerr/Caudex.Rafting
        public Leader(IElection election, 
            IHartbeatTimer hartbeat,
            IObservable<AppendEntryResultMessage> reply,
            IObserver<AppendEntryMessage> append,
            IObserver<ClientResultMessage> clientReply,
            IObservable<ClientMessage> client,
            ILogReplication logReplication, 
            Nodes nodes,
            ILoggerFactory loggerFactory,
            RaftOptions options, 
            ServerIdentifier serverIdentifier)
        {
            _isDispose = false;
            _hartbeat = hartbeat;
            _append = append;
            _clientReply = clientReply;
            _client = client;
            _logReplication = logReplication;
            _nodes = nodes;
            _options = options;
            _serverIdentifier = serverIdentifier;
            _election = election;
            _logger = loggerFactory.CreateLogger(nameof(Leader) + " " + serverIdentifier);

            if (_options.UseLogging)
                _logger.LogInformation($"{nameof(ServerStateType.Leader)}");

            // Reinitialized after election
            NextIndex = new ConcurrentDictionary<ServerIdentifier, int>();
            MatchIndex = new ConcurrentDictionary<ServerIdentifier, int>();
            _hartbeat.Leader(SendHartbeat);
            _replyDispose = reply.Subscribe(EntryReplyMessageRecived);
            _clientReplyDispose = client.Subscribe(ClientMessageRecived);
        }