Пример #1
0
        public PeerInfo AddPeer(int peerId, string address = "http://localhost:30140/api/cluster")
        {
            if (peerId == 0)
            {
                throw new System.ArgumentOutOfRangeException("peerId must be greater than 0.");
            }

            PeerInfo p = new PeerInfo(peerId, address);

            peers.Add(peerId, p);
            return(p);
        }
Пример #2
0
        public async Task <ResponseMessage> SendMessage(PeerInfo peer, RequestMessage msg)
        {
            var request = new HttpRequestMessage(HttpMethod.Post, peer.address + "/cluster");

            request.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(msg), Encoding.UTF8, "application/json");
            var response = await client.SendAsync(request);

            if (!response.IsSuccessStatusCode)
            {
                return(null);
            }

            var content = await response.Content.ReadAsStringAsync();

            return(Newtonsoft.Json.JsonConvert.DeserializeObject <ResponseMessage>(content));
        }
Пример #3
0
 public PeerInfo AddPeer(string address, bool bootstrap, int peerId = 0)
 {
     lock (peers)
     {
         if (bootstrap)
         {
             peers.Clear();
         }
         if (peerId == 0)
         {
             // find first available peerId
             while (peers.ContainsKey(peerId))
             {
                 peerId++;
             }
         }
         PeerInfo p = new PeerInfo(peerId, address);
         peers.Add(peerId, p);
         return(p);
     }
 }
Пример #4
0
        void IStateMachine.LoadState(BinaryReader reader)
        {
            this.ClusterName                 = reader.ReadString();
            this.DeleteOldFiles              = reader.ReadBoolean();
            this.ElectionTimeoutFixedMillis  = reader.ReadInt32();
            this.ElectionTimeoutRandomMillis = reader.ReadInt32();
            this.EntriesPerFile              = reader.ReadInt32();
            this.EntriesPerSnapshot          = reader.ReadInt32();
            this.HeartbeatMillis             = reader.ReadInt32();
            this.LogDirectory                = reader.ReadString();
            this.MaxEntriesPerRequest        = reader.ReadInt32();
            this.PeerId           = reader.ReadInt32();
            this.SnapshotPartSize = reader.ReadInt32();
            var cx = reader.ReadInt32();

            peers.Clear();
            for (var i = 0; i < cx; i++)
            {
                var peer = new PeerInfo(reader);
                peers.Add(peer.peerId, peer);
            }
        }