public bool Unuse(ServiceAddressNode node) { if (Remove(node)) { node.AccessCount = 0; return(this.unAvaliableSerivces.TryAdd(node)); } return(false); }
public bool IsAlive(ServiceAddressNode node) { var host = GetHost(node.Address); var tcpProbe = new TcpProbe(); var alive = tcpProbe.CanConnect(host.Host, host.Port, _30seconds); return(alive); }
public ServiceAddressNode GetOne(string serviceIdentity) { if (string.IsNullOrWhiteSpace(serviceIdentity)) { return(null); } ServiceAddressBucket bucket; if (!_buckets.TryGetValue(serviceIdentity, out bucket)) { return(null); } var head = Volatile.Read(ref bucket.Head); ServiceAddressNode node = null; while (true) { if (!bucket.Get(head, out node)) { break; } if (node.TryAccess()) { break; } node.EnsureNextAccess(); var count = bucket.AvaliableCount; var nexthead = (head + 1) % count; if (IncrementHead(ref bucket.Head, head, nexthead)) { head = bucket.Head; } else { head = Volatile.Read(ref bucket.Head); } } return(node); }
public bool Match(ServiceAddressNode another) { return(MatchAddress(another.Address)); //return MatchIp(another.ClientIp) || MatchAddress(another.Address); }
public bool Remove(ServiceAddressNode node) { var removed = this.avaliableSerivces.TryRemove(node); return(removed); }
public bool Get(int index, out ServiceAddressNode node) { return(this.avaliableSerivces.TryGet(index, out node)); }
public bool IsNotAlive(ServiceAddressNode node) { return(!IsAlive(node)); }