/// <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; }); }
/// <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; }); }
/// <summary> /// 监控一个地址。 /// </summary> /// <param name="address">地址模型。</param> /// <returns>一个任务。</returns> public Task Monitor(AddressModel address) { return Task.Run(() => { _dictionary.GetOrAdd(address.ToString(), k => new MonitorEntry(address)); }); }
public MonitorEntry(AddressModel addressModel, bool health = true) { EndPoint = addressModel.CreateEndPoint(); Health = health; }