예제 #1
0
        // Prints the tree without changing the tree view state
        public static String PrintTree(ZooKeeperWrapper zk, String machinesPath, String sellersPath, String stamp)
        {
            StringBuilder sb       = new StringBuilder();
            List <String> machines = zk.GetChildren(machinesPath, true);

            sb.AppendLine("[" + stamp + "] Machines Tree: ");
            foreach (var machine in machines)
            {
                var machineRecord = zk.GetData <ZNodesDataStructures.MachineNode>(machinesPath + "/" + machine, true);
                sb.AppendLine("[" + stamp + "] \\-" + machine);
                sb.AppendLine("[" + stamp + "]       \\-P: " + String.Join(" ", machineRecord.primaryOf));
                sb.AppendLine("[" + stamp + "]       \\-B: " + String.Join(" ", machineRecord.backsUp));
            }
            sb.AppendLine("[" + stamp + "] Sellers Tree: ");
            List <String> sellers = zk.GetChildren(sellersPath, true);

            foreach (var seller in sellers)
            {
                sb.AppendLine("[" + stamp + "] \\-" + seller);
                var sellerMachines = zk.GetChildren(sellersPath + "/" + seller, true);
                foreach (var sellerMachine in sellerMachines)
                {
                    var machineSellerRecord = zk.GetData <ZNodesDataStructures.SellerNode>(sellersPath + "/" + seller + "/" + sellerMachine, true);
                    sb.AppendLine("[" + stamp + "]       \\-" + machineSellerRecord.role + ": " + sellerMachine + " " + machineSellerRecord.uri);
                }
            }
            return(sb.ToString());
        }
 /// <summary>
 /// Sets a watcher on the Sellers node, event will call the children changed evend
 /// </summary>
 private void setSellersChildrenWatcher()
 {
     if (zk.Connected)
     {
         try
         {
             zk.GetChildren(SellersPath, new SellersNodeWatch(this)); // Register creation/deletion of children
         }
         catch (Exception ex)
         {
             Console.WriteLine("Failed setting Sellers Node watch due to " + ex.Message);
             throw ex;
         }
     }
 }
예제 #3
0
        public TreeView(ZooKeeperWrapper zk, String machinesPath, String sellersPath)
        {
            this.machinesPath = machinesPath;
            this.sellersPath  = sellersPath;
            this.zk           = zk;

            var newMachinesView = zk.GetChildren(machinesPath, false);
            var newSellersView  = zk.GetChildren(sellersPath, false);

            // Build machines tree from ZK
            machinesData.Clear();
            foreach (var machine in newMachinesView)
            {
                var machineData = zk.GetData <ZNodesDataStructures.MachineNode>(machinesPath + "/" + machine, false);
                machinesData.Add(machine, machineData);
            }

            // Build sellers tree from ZK
            sellersData.Clear();
            foreach (var seller in newSellersView)
            {
                var sellerMachines = zk.GetChildren(sellersPath + "/" + seller, false);
                if (sellerMachines.Count > 2)
                {
                    throw new Exception("Seller " + seller + " has too many machines: " + String.Join(" ", sellerMachines));
                }

                Dictionary <ZNodesDataStructures.SellerNode.NodeRole, ZNodesDataStructures.SellerNode> nodeRoles = new Dictionary <ZNodesDataStructures.SellerNode.NodeRole, ZNodesDataStructures.SellerNode>();
                foreach (var machine in sellerMachines)
                {
                    var machineSellerNode = zk.GetData <ZNodesDataStructures.SellerNode>(sellersPath + "/" + seller + "/" + machine, false);
                    nodeRoles[machineSellerNode.role] = machineSellerNode;
                }

                //if (nodeRoles.Count != 2)
                //{
                //    throw new Exception("Seller " + seller + "doesn't have needed roles " + String.Join(" ", nodeRoles.Keys.ToArray()));
                //}

                sellersData[seller] = new Dictionary <ZNodesDataStructures.SellerNode.NodeRole, ZNodesDataStructures.SellerNode>(nodeRoles);
            }
        }