Beispiel #1
0
 public void SetLock()
 {
     if (zk.Exists("/custom/lock", true) == null)
     {
         zk.Create("/custom/lock", serverHost.GetBytes(), Ids.OPEN_ACL_UNSAFE, CreateMode.Ephemeral);
     }
     else
     {
         zk.SetData("/custom/lock", serverHost.GetBytes(), 0);
     }
 }
Beispiel #2
0
        public static void StartConfig()
        {
            ZooKeeperNet.ZooKeeper zk = new ZooKeeperNet.ZooKeeper("127.0.0.1:2181", new TimeSpan(1, 0, 0), new Watch());

            zk.AddAuthInfo(auth_type, auth_passwd.GetBytes());

            if (zk.Exists(config_root, true) == null)
            {
                //设置Auth后,创建Node需要使用acl访问控制列表
                zk.Create(config_root, "config".GetBytes(), Ids.CREATOR_ALL_ACL, CreateMode.Persistent);
            }
            if (zk.Exists(config_user, true) == null)
            {
                zk.Create(config_user, "admin".GetBytes(), Ids.CREATOR_ALL_ACL, CreateMode.Persistent);
            }
            if (zk.Exists(config_passwd, true) == null)
            {
                zk.Create(config_passwd, "admin".GetBytes(), Ids.CREATOR_ALL_ACL, CreateMode.Persistent);
            }
        }