Exemple #1
0
      public static async Task <T> GetDataOverTCPAsync <T>(string dbName, string key)
      {
          if (!TcpConnectionPool.Initialized)
          {
              TcpConnectionPool.InitializeConnectionPool(_tcpHostAddress, _port, _minPoolSize, _maxPoolSize, _socketRecycleAgeAsMinute);
          }

          var CustomSocket = TcpConnectionPool.GetSocket();

          try
          {
              byte[] sendData = Encoding.ASCII.GetBytes($"get {dbName} {key}");
              string response;
              using (NetworkStream stream = CustomSocket.GetStream())
              {
                  await stream.WriteAsync(sendData, 0, sendData.Length);

                  using (MemoryStream buffer = new MemoryStream())
                  {
                      int b;
                      while ((b = stream.ReadByte()) != -1)
                      {
                          buffer.WriteByte((byte)b);
                      }
                      response = Encoding.UTF8.GetString(buffer.GetBuffer());
                  }
              }
              return(JsonConvert.DeserializeObject <T>(response));
          }
          finally
          {
              TcpConnectionPool.PutSocket(CustomSocket);
          }
      }
Exemple #2
0
      public static T GetDataOverTCP <T>(string dbName, string key)
      {
          var CustomSocket = TcpConnectionPool.GetSocket();

          try
          {
              byte[] sendData = Encoding.ASCII.GetBytes($"get {dbName} {key}");
              string response;
              using (NetworkStream stream = CustomSocket.GetStream())
              {
                  stream.Write(sendData, 0, sendData.Length);

                  using (MemoryStream buffer = new MemoryStream())
                  {
                      int b;
                      while ((b = stream.ReadByte()) != -1)
                      {
                          buffer.WriteByte((byte)b);
                      }
                      response = Encoding.UTF8.GetString(buffer.GetBuffer());
                  }
              }
              return(JsonConvert.DeserializeObject <T>(response));
          }
          finally
          {
              TcpConnectionPool.PutSocket(CustomSocket);
          }
      }
Exemple #3
0
      public RocksDBClient(string tcpHostAdress = "127.0.0.1", int port = 38670, int minPoolSize = 20, int maxPoolSize = 5000, int socketRecycleAgeAsMinute = 15)
      {
          if (client.BaseAddress == null)
          {
              client.BaseAddress = new Uri("http://" + tcpHostAdress + ":3800/");
              client.DefaultRequestHeaders.Accept.Clear();
          }

          TcpConnectionPool.InitializeConnectionPool(tcpHostAdress, port, minPoolSize, maxPoolSize, socketRecycleAgeAsMinute);
      }
Exemple #4
0
        private void InitConnectionPool()
        {
            connectionPool = new TcpConnectionPool();

            foreach (var dest in Config.Global.TcpDests)
            {
                try { connectionPool.Add(dest); }
                catch (Exception e)
                {
                    logger.Error("Adding TCP destination '{0}' to connection pool failed!\n{1}", dest.Id, e);
                }
            }
        }
Exemple #5
0
 public TcpAction(ActionParameter param, TcpConnectionPool conPool)
     : base(param)
 {
     connections = conPool;
     data        = Encoding.ASCII.GetBytes(Param.Message + DELIMITER);
 }