public void updateState(string state, int term, string url) { if (state == "follower") { Console.WriteLine("I am now a Follower"); _state = new FollowerState(this, term); } else if (state == "candidate") { Console.WriteLine("I am now a Candidate"); _state = new CandidateState(this, term); } else if (state == "leader") { _state.stopClock(); Console.WriteLine("I am now a Leader"); _state = new LeaderState(this, term); } _state.startClock(term, url); }
private void selfPrepare(int min_delay, int max_delay) { serverRemoteObjects = new Dictionary <string, IServerService>(); matchIndexMap = new Dictionary <string, int>(); channel = new TcpChannel(_port); Console.WriteLine(_port.ToString()); ChannelServices.RegisterChannel(channel, false); myRemoteObject = new ServerService(this, min_delay, max_delay); RemotingServices.Marshal(myRemoteObject, _name, typeof(ServerService)); //TODO remote object name fd = new FailureDetector(); Console.WriteLine("Hello! I'm a Server at port " + _port); foreach (string url in ConfigurationManager.AppSettings.AllKeys) { string[] urlSplit = url.Split(new Char[] { '/', ':' }, StringSplitOptions.RemoveEmptyEntries); int portOut; Int32.TryParse(urlSplit[2], out portOut); //not to connect to himself if (portOut != _port) { serverRemoteObjects.Add(url, (ServerService)Activator.GetObject(typeof(ServerService), url)); matchIndexMap.Add(url, 0); } } _numServers = serverRemoteObjects.Count; List <string> view = fd.getView(); while (view == null || view.Count == 0) { Thread.Sleep(100); view = fd.getView(); } _state = new FollowerState(this, 0);; Console.WriteLine("Finished constructing server " + _port + " with thread " + Thread.CurrentThread.ManagedThreadId); }