Example #1
0
        public AgentActor()
        {
            Become(new Behavior <IPeerActor <TKey, TValue> >(
                       a =>
            {
                IFuture <IEnumerable <TKey> > keys = a.AskKeys();
                IFuture <IEnumerable <IPeerActor <TKey> > > peers = a.AskPeers();
                // peek key out of centroid
                TKey key = CenterKey.Calc(keys.Result());
                // calc nearest peer
                IOrderedEnumerable <IPeerActor <TKey> > orderedPeers = peers.Result().OrderBy(n => n.GetPeerHashKey().ToString());
                HashKey hashKey = HashKey.ComputeHash(key.ToString());

                foreach (IPeerActor <TKey> peer in orderedPeers)
                {
                    if (hashKey.CompareTo(peer.GetPeerHashKey()) > 0)
                    {
                        // deposit
                        // get current K V
                        TValue result = a.GetNode(key).Result();
                        if (result != null)
                        {
                            // set current K V
                            (peer as IPeerActor <TKey, TValue>).StoreNode(key, result);
                        }
                        break;
                    }
                }
            }));
        }
Example #2
0
 public static int Compare(HashKey left, HashKey right)
 {
     if (object.ReferenceEquals(left, right))
     {
         return(0);
     }
     if (object.ReferenceEquals(left, null))
     {
         return(-1);
     }
     return(left.CompareTo(right));
 }