Exemplo n.º 1
0
 public DataServerStruct(Address addr, int weight, SystemInfo info)
 {
     this.addr = addr;
     this.weight = weight;
     this.info = info;
     this.regions = new HashSet<Region>();
 }
Exemplo n.º 2
0
 public void AddMasterAddr(Address addr)
 {
     masterAddrs.Add(addr);
 }
Exemplo n.º 3
0
 public void addRegion(Region region, Address addr)
 {
     map.Add(region, addr);
     regions.Add(region);
     sorted = false;
 }
Exemplo n.º 4
0
 public KVClient(ClientOption option)
 {
     this.option = option;
     this.connections = new Dictionary<Address, Socket>();
     activeMaster = null;
 }
Exemplo n.º 5
0
 protected Socket getMasterConnection()
 {
     Socket socket = null;
     if (activeMaster != null)
     {
         try
         {
             socket = getConnection(activeMaster);
         }
         catch (Exception e)
         {
             Console.Error.WriteLine("Fail to connect to master " + activeMaster);
         }
     }
     if (socket == null)
     {
         ICollection<Address> masters = option.MasterAddrs;
         foreach (Address master in masters)
         {
             try
             {
                 socket = getConnection(master);
                 if (socket != null)
                 {
                     activeMaster = master;
                     return socket;
                 }
             }
             catch (Exception e)
             {
                 Console.Error.WriteLine("Fail to connect to master " + activeMaster + " try next");
             }
         }
     }
     if (socket != null)
     {
         return socket;
     }
     else
     {
         throw new KVException(
                 "No active master found in cluster, please check the configuration.");
     }
 }
Exemplo n.º 6
0
 protected Socket getConnection(Address addr)
 {
     Socket socket = null;
     connections.TryGetValue(addr, out socket);
     if (socket == null || !socket.Connected)
     {
         socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         socket.Connect(new IPEndPoint(IPAddress.Parse(addr.Ip), addr.Port));
         connections.Add(addr, socket);
     }
     return socket;
 }