예제 #1
0
        public bool Unuse(ServiceAddressNode node)
        {
            if (Remove(node))
            {
                node.AccessCount = 0;
                return(this.unAvaliableSerivces.TryAdd(node));
            }

            return(false);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
 public bool Match(ServiceAddressNode another)
 {
     return(MatchAddress(another.Address));
     //return MatchIp(another.ClientIp) || MatchAddress(another.Address);
 }
예제 #5
0
        public bool Remove(ServiceAddressNode node)
        {
            var removed = this.avaliableSerivces.TryRemove(node);

            return(removed);
        }
예제 #6
0
 public bool Get(int index, out ServiceAddressNode node)
 {
     return(this.avaliableSerivces.TryGet(index, out node));
 }
예제 #7
0
 public bool IsNotAlive(ServiceAddressNode node)
 {
     return(!IsAlive(node));
 }