Esempio n. 1
0
        public T GetData <T>(string nodePath, Boolean watch) where T : new()
        {
            T   data  = default(T);
            int tries = retries;

            while ((tries--) > 0)
            {
                try
                {
                    byte[] readData = zk.GetData(nodePath, watch, null);
                    data = ZNodesDataStructures.deserialize <T>(readData);
                    break;
                }
                catch (Exception ex)
                {
                    if (tries == 0)
                    {
                        Console.WriteLine("GetData exception after #" + retries + " retries :\n" + ex.Message);
                        Console.WriteLine("Last retry, throwing exception");
                        throw ex;
                    }
                }
            }
            return(data);
        }
Esempio n. 2
0
        public Stat SetData <T>(string nodePath, T data, int version) where T : new()
        {
            Stat stat = null;

            byte[] serializedData = ZNodesDataStructures.serialize <T>(data);
            int    tries          = retries;

            while ((tries--) > 0)
            {
                try
                {
                    stat = zk.SetData(nodePath, serializedData, version);
                    break;
                }
                catch (Exception ex)
                {
                    if (tries == 0)
                    {
                        Console.WriteLine("SetData exception after #" + retries + " retries :\n" + ex.Message);
                        Console.WriteLine("Last retry, throwing exception");
                        throw ex;
                    }
                }
            }
            return(stat);
        }
 /// <summary>
 /// Create a node under /cluster/MACHINES for this
 /// </summary>
 private void registerMachinesNode()
 {
     try
     {
         var node = new ZNodesDataStructures.MachineNode();
         node.uri = intraClusterService;
         node.originalSellerName = originalSeller;
         node.primaryOf.Add(originalSeller);
         byte[] serializedNode = ZNodesDataStructures.serialize(node);
         id = zk.Create(MachinesPath + "/" + MACHINE_PREFIX, serializedNode, Ids.OPEN_ACL_UNSAFE, CreateMode.EphemeralSequential);
         gotName.Set();
     }
     catch (KeeperException e)
     {
         Console.WriteLine("Registering machine node failed\n" + e.Message);
         throw e;
     }
 }
Esempio n. 4
0
 public String Create <T>(string path, T data, IEnumerable <Org.Apache.Zookeeper.Data.ACL> acl, CreateMode mode)
 {
     return(Create(path, ZNodesDataStructures.serialize(data), acl, mode));
 }