コード例 #1
0
ファイル: RaftNode.cs プロジェクト: xiaoxiongnpu/CaliDiagram
        public RaftEventResult OnMessageReceived(RaftMessageBase raftMessage)
        {
            RaftEventResult raftResult = null;
            /* Append entries */
            var appEntries = raftMessage as AppendEntriesRPC <T>;

            if (appEntries != null)
            {
                raftResult = StateObject.ReceiveAppendEntries(appEntries);
            }

            /* Append entries response */
            var appEntriesResponse = raftMessage as AppendEntriesResponse;

            if (appEntriesResponse != null)
            {
                raftResult = StateObject.ReceiveAppendEntriesResponse(appEntriesResponse);
            }

            /* Request vote */
            var requestVote = raftMessage as RequestVote;

            if (requestVote != null)
            {
                raftResult = StateObject.ReceiveRequestVote(requestVote);
            }

            /* Request vote response */
            var requestVoteResponse = raftMessage as RequestVoteResponse;

            if (requestVoteResponse != null)
            {
                raftResult = StateObject.ReceiveRequestVoteResponse(requestVoteResponse);
            }

            /* client rpc */
            var clientRequest = raftMessage as ClientRequestRPC <T>;

            if (clientRequest != null)
            {
                PersistedState.AddEntry(clientRequest.Message);
                raftResult = RaftEventResult.Empty;
            }

            if (raftResult == null)
            {
                throw new InvalidOperationException("Raft message processing returned null");
            }

            return(raftResult);
        }
コード例 #2
0
ファイル: RaftNode.cs プロジェクト: xiaoxiongnpu/CaliDiagram
        public RaftNode(IRaftEventListener raftEventListener, IRaftNodeSettings raftSettings, string id)
        {
            if (raftEventListener == null)
            {
                throw new ArgumentNullException("raftWorld");
            }
            if (id == null)
            {
                throw new ArgumentException("id");
            }
            this.Id = id;

            RaftEventListener = raftEventListener;
            RaftSettings      = raftSettings;
            PersistedState    = new PersistedState <T>();
        }