Пример #1
0
 public ClientResponse ClientInvoke(ClientReqeust request)
 {
     lock (this)
     {
         if (_node.CurrentRole.Type == RoleType.Follower)
         {
             Follower follower = (Follower)_node.CurrentRole;
             //todo rediret request to leader node
             IHost _host = _node.Peers[0].RemoteClient;
             return(_host.ClientInvoke(request));
         }
         return((_node.CurrentRole as Leader).Command(request));
     }
 }
Пример #2
0
        public Node(Config config)
        {
            _config          = config;
            _stateController = new StateController(config, new FileStateMachine(config.NodeId));
            Peers            = new List <Peer>();
            foreach (string address in config.JoinAddresses)
            {
                if (address == config.LocalAddress)
                {
                    continue;
                }
                string[]    segments = address.Split(':');
                GrpcChannel channel  = new GrpcChannel(segments[0], int.Parse(segments[1]), config.ClusterToken, new DebugConsole());
                Peers.Add(new Peer(address, channel.GetClient <IHost>()));
            }

            _host       = new Host(_stateController, this);
            CurrentRole = new Follower(_stateController, this);
        }