Brunet.Services.Coordinate.NCService.TrialState.GetLatencySample C# (CSharp) Метод

GetLatencySample() защищенный Метод

protected GetLatencySample ( ) : void
Результат void
      protected void GetLatencySample() {
#if NC_DEBUG        
        Console.Error.WriteLine("[NCService] {0} Requesting latency sample from: {1}.", _node.Address, _target.Address);
#endif
        DateTime start = DateTime.UtcNow;
        Channel q = new Channel(1);
        q.CloseEvent += delegate(object o, EventArgs args) {
          Channel res_q = (Channel) o;
          DateTime stop = DateTime.UtcNow;
          bool do_consider = false;
          if (res_q.Count > 0 ) {
            try {
              RpcResult res = res_q.Dequeue() as RpcResult;
              if (res.Statistics.SendCount == 1) {
                do_consider = true;
              }
              else {
#if NC_DEBUG
                Console.Error.WriteLine("[NCService] {0} multiple sends for: {1}.", _node.Address, _target.Address);
#endif
              }
            } catch(Exception) {}
          }
          
          if (do_consider) {
            double elapsed = (stop - start).TotalMilliseconds;
            int count = Interlocked.Increment(ref _num_samples);
#if NC_DEBUG        
            Console.Error.WriteLine("[NCService] {0} Got latency sample from: {1}, sample #: {2}.", 
                                    _node.Address, 
                                    _target.Address,
                                    count);
#endif
            
            if (count >= TrialState.MIN_LATENCY_SAMPLES) {
              _callback(this, DateTime.UtcNow, _target.Address, _state_result.Value, elapsed);
              //termination
            }
            else {
              // take another latency sample
              GetLatencySample();
            }
          }
          else {
            //do nothing, looks like things are not going well with this trial
            //termination
#if NC_DEBUG        
            Console.Error.WriteLine("[NCService] {0} Rpc (GetLatencySample) failed: {1}.", _node.Address, _target.Address);
#endif
          }
        };
        
        try {
          _node.Rpc.Invoke(_target.State.Edge, q, "ncserver.Echo", new object[]{});
        } catch (Exception) {}
      }
    }