예제 #1
0
 /// <summary>
 /// 标记一个地址为失败的。
 /// </summary>
 /// <param name="address">地址模型。</param>
 /// <returns>一个任务。</returns>
 public Task MarkFailure(AddressModel address)
 {
     return Task.Run(() =>
     {
         var key = address.ToString();
         var entry = _dictionary.GetOrAdd(key, k => new MonitorEntry(address, false));
         entry.Health = false;
     });
 }
예제 #2
0
        /// <summary>
        /// 判断一个地址是否健康。
        /// </summary>
        /// <param name="address">地址模型。</param>
        /// <returns>健康返回true,否则返回false。</returns>
        public Task<bool> IsHealth(AddressModel address)
        {
            return Task.Run(() =>
            {
                var key = address.ToString();
                MonitorEntry entry;

                return !_dictionary.TryGetValue(key, out entry) || entry.Health;
            });
        }
예제 #3
0
 /// <summary>
 /// 监控一个地址。
 /// </summary>
 /// <param name="address">地址模型。</param>
 /// <returns>一个任务。</returns>
 public Task Monitor(AddressModel address)
 {
     return Task.Run(() => { _dictionary.GetOrAdd(address.ToString(), k => new MonitorEntry(address)); });
 }
예제 #4
0
 public MonitorEntry(AddressModel addressModel, bool health = true)
 {
     EndPoint = addressModel.CreateEndPoint();
     Health = health;
 }