Exemplo n.º 1
0
        public DHTNodeI(string nodeName, bool isMaster, Communicator communicator)
        {
            IsDisconnecting = false;
            _communicator = communicator;
            _nodeName = nodeName;

            if (isMaster)
            {
                subtreeRange = new range(int.MinValue, int.MaxValue);
                _parent = null;
                ranges.Add(new range(int.MinValue, int.MaxValue));
                Console.WriteLine(describe());
                return;
            }

            while (true)
            {
                ObjectPrx oprx = communicator.stringToProxy(Constants.SERVICE_NAME);
                DHTNodePrx nprx =  DHTNodePrxHelper.checkedCast(oprx);
                if (nprx != null)
                {
                    try
                    {
                        nodeConf my_node = nprx.newConnected(nodeName);
                        subtreeRange = new range(my_node.min, my_node.max);
                        ranges.Add(new range(my_node.min, my_node.max));
                        _parent = my_node.parentNode;
                        Console.WriteLine(describe());
                        return;
                    }
                    catch (Ice.Exception e)
                    {
                        Console.WriteLine(e.StackTrace);
                    }
                }
                else
                {
                    Console.WriteLine("Wait for master");
                    Thread.Sleep(500);
                }
            }
        }
Exemplo n.º 2
0
 public override void slaveDisconnected(string id, range[] newRanges, nodeConf[] childRanges, Ice.Current current__)
 {
     lock (ranges)
     {
         Console.WriteLine("Slave disconected "+id);
         nodeConf removedNode = null;
         foreach (nodeConf nc in childs)
         {
             if (nc.nodeId == id)
             {
                 removedNode = nc;
             }
         }
         if (removedNode != null)
         {
             childs.Remove(removedNode);
             foreach (range r in newRanges)
             {
                 ranges.Add(r);
             }
             reduceRanges();
             foreach (nodeConf nc in childRanges)
             {
                 childs.Add(nc);
             }
         }
         else
         {
             Console.WriteLine("Struct fail: {0} is not a child of {1}", id, _nodeName);
         }
         Console.WriteLine(describe());
     }
 }
Exemplo n.º 3
0
 public override void masterDisconnected(string connectTo, range subtree, range[] newRanges, nodeConf[] childRanges, Ice.Current current__)
 {
     lock (ranges)
     {
         Console.WriteLine("Master disconnected");
         _parent = connectTo;
         if (_parent == null || _parent.Equals("")) // jestem nowy rootem dla tego poddrzewa
         {
             Console.WriteLine("setting subtree range: "+subtree.min + " : " + subtree.max);
             _parent = null;
             subtreeRange = subtree;
         }
         ranges.AddRange(newRanges);
         foreach (nodeConf nc in childRanges)
         {
             nc.parentNode = _nodeName;
         }
         childs.AddRange(childRanges);
         reduceRanges();
         Console.WriteLine(describe());
     }
 }