コード例 #1
0
 private void judge_Timeout()
 {
     if (ServerHandler_.role == NodeRole.Candidate)
     {
         lock (this)
         {
             StopThread();
             SwitchThread();
             StartThread();
             ServerHandler_.ToBeRunning();
         }
     }
     else
     {
         ServerHandler_.LOG(String.Format("get Timeout state"));
     }
 }
コード例 #2
0
 private void judge_FindLeader()
 {
     if (ServerHandler_.role == NodeRole.Follower)
     {
         lock (this)
         {
             StopThread();
             SwitchThread();
             StartThread();
             ServerHandler_.ToBeRunning();
         }
     }
     else
     {
         ServerHandler_.LOG(String.Format("get FindLeader state"));
     }
 }
コード例 #3
0
        private void state_checker()
        {
            Console.WriteLine("state checker thread running...");
            while (!node_should_stop_)
            {
                if (ServerHandler_.is_election_done_)
                {
                    lock (this)
                    {
                        judge_Election();
                    }
                }
                lock (this)
                {
                    switch (ServerHandler_.state) //judge internal state(state can be verify in heartbeat and vote)
                    {
                    case ServerState.Running:
                        // everything is ok!
                        break;

                    case ServerState.FindLeader:
                        judge_FindLeader();
                        break;

                    case ServerState.Timeout:
                        judge_Timeout();
                        break;

                    case ServerState.HigherTerm:
                        judge_HigherTerm();
                        break;

                    default:
                        ServerHandler_.LOG(String.Format("Unknown state {0}", ServerHandler_.state));
                        break;
                    }
                }
            }
            Console.WriteLine("{0} state checker thread existed!", ServerHandler_.id);
        }