Beispiel #1
0
 public void Send(IActorId to, string name, params object[] args)
 {
     node.Send(to, id, name, args);
 }
Beispiel #2
0
 public RpcSender(Node node, IActorId id)
 {
     this.id = id;
     this.node = node;
 }
Beispiel #3
0
 public void Reply(IActorId to, IMessageId msg, string name, params object[] args)
 {
     node.Reply(to, id, msg, name, args);
 }
Beispiel #4
0
 IActorId[] GetClosest(string key, int count)
 {
     var hash = HashAlgorithm.ComputeHash(key.ToString());
     var array = new IActorId[count];
     lock (actors)
     {
         var index = this.actors.BinarySearch(KeyValuePair.New(hash, (IActorId)null), n => n.Key);
         if (index < 0) index = ~index - 1;
         if (index < 0) index = actors.Count - 1;
         for (int i = 0; i < array.Length; i++)
             array[i] = actors[(index + i) % actors.Count].Value;
     }
     return array;
 }
Beispiel #5
0
 public DhtRing(IActorId self)
 {
     this.HashAlgorithm = new SHA1Managed();
     this.SelfId = self;
     this.actors.Add(KeyValuePair.New(HashAlgorithm.ComputeHash(self.ToString()), self));
 }
Beispiel #6
0
 void AddInternal(IActorId id)
 {
     var hash = HashAlgorithm.ComputeHash(id.ToString());
     lock (actors)
     {
         var index = actors.BinarySearch(KeyValuePair.New(hash, (IActorId)null), n => n.Key);
         if (index >= 0) return;
         actors.Insert(~index, KeyValuePair.New(hash, id));
     }
 }
Beispiel #7
0
 public void Remove(IActorId id)
 {
     lock (actors)
     {
         actors.RemoveWhere(n => n.Value.Equals(id));
     }
 }
Beispiel #8
0
 public IActorId[] FindAll(int ttl, IActorId originator = null)
 {
     if (ttl < 0) return new IActorId[0];
     lock (actors)
         return Enumerable.Range(0, ttl)
             .Select(n => Find(n))
             .Where(n => n != null)
             .ToArray();
 }
Beispiel #9
0
 public IActorId Find(int ttl, IActorId originator = null)
 {
     lock (actors)
     {
         if (ttl < 0) return null;
         int selfIndex = SelfIndex;
         if (selfIndex < 0) return null;
         int distance = (int)Math.Pow(2, ttl);
         if (distance >= actors.Count) return null;
         int endPoint = selfIndex + distance;
         if (endPoint >= actors.Count)
             endPoint -= actors.Count;
         var destination = actors[endPoint];
         if (destination.Equals(SelfId)) return null;
         if (originator == null) originator = SelfId;
         var hash = HashAlgorithm.ComputeHash(originator.ToString());
         var originatorIndex = actors.BinarySearch(KeyValuePair.New(hash,(IActorId) null), n => n.Key);
         if (IsBetween(originatorIndex, selfIndex, endPoint))
         {
             // if the originator is between us and the endpoint it means
             // if we send this message it will have wrapped completely around
             // the ring. if we do that nodes will receive the same message twice
             // so stop this message instead.
             return null;
         }
         return destination.Value;
     }
 }
Beispiel #10
0
 public void Add(IActorId id)
 {
     AddInternal(id);
 }