コード例 #1
0
 private static Task deleteNode(string path)
 {
     return(ZooKeeper.Using(hostPort, CONNECTION_TIMEOUT, NullWatcher.Instance, zk =>
     {
         return ZKUtil.deleteRecursiveAsync(zk, path);
     }));
 }
コード例 #2
0
 public static void Delete(string path)
 {
     ZooKeeper.Using(zkEndpoint, 1000, new NScrapyConfigWatcher(), async zk =>
     {
         await zk.deleteAsync(path);
     });
 }
コード例 #3
0
 public async static void SetAsync(string path, string value)
 {
     await ZooKeeper.Using(zkEndpoint, 1000, new NScrapyConfigWatcher(), async zk =>
     {
         await zk.setDataAsync(path, Encoding.UTF8.GetBytes(value));
     });
 }
コード例 #4
0
 private static Task <string> createNode()
 {
     return(ZooKeeper.Using(hostPort, CONNECTION_TIMEOUT, NullWatcher.Instance, async zk =>
     {
         string newNode = await zk.createAsync("/", null, ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL);
         return newNode;
     }));
 }
コード例 #5
0
 public static bool Exists(string path)
 {
     return(ZooKeeper.Using(zkEndpoint, 1000, new NScrapyConfigWatcher(), async zk =>
     {
         var stat = await zk.existsAsync(path, true);
         return stat != null;
     }).Result);
 }
コード例 #6
0
ファイル: ClientBase.cs プロジェクト: jjg0519/zookeeper
 internal static Task deleteNode(string path)
 {
     return(ZooKeeper.Using(hostPort, 10000, new NullWatcher(), async zk =>
     {
         await ZKUtil.deleteRecursiveAsync(zk, path);
         await zk.sync("/");
     }));
 }
コード例 #7
0
        public async Task testOnlyOneAvailable()
        {
            log.debug("START - testOnlyOneAvailable");
            var connectionString = Enumerable.Range(0, 9).Select(i => Guid.NewGuid().ToString("N")).ToCommaDelimited() +
                                   ",localhost";
            await ZooKeeper.Using(connectionString, ClientBase.CONNECTION_TIMEOUT, ClientBase.NullWatcher.Instance, zk => zk.existsAsync("/"));

            log.debug("END - testOnlyOneAvailable");
        }
コード例 #8
0
 internal static Task <string> createNode(string path, CreateMode createMode)
 {
     return(ZooKeeper.Using(hostPort, CONNECTION_TIMEOUT, NullWatcher.Instance, async zk =>
     {
         string newNode = await zk.createAsync(path, null, ZooDefs.Ids.OPEN_ACL_UNSAFE, createMode);
         await zk.sync("/");
         return newNode;
     }));
 }
コード例 #9
0
        public async static Task <string> GetAsync(string path)
        {
            DataResult result = null;
            await ZooKeeper.Using(zkEndpoint, 1000, new NScrapyConfigWatcher(), async zk =>
            {
                result = await zk.getDataAsync(path, true);
            });

            return(Encoding.UTF8.GetString(result.Data));
        }
コード例 #10
0
        public static async Task <bool> EnsureZooKeeperAsync()
        {
            var connectionString = TestDefaultConfiguration.ZooKeeperConnectionString;

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                return(false);
            }
            return(await ZooKeeper.Using(connectionString, 2000, null, async zk =>
            {
                try
                {
                    await zk.existsAsync("/test", false);
                    return true;
                }
                catch (KeeperException.ConnectionLossException)
                {
                    return false;
                }
            }));
        }
コード例 #11
0
        public static void Create(string path, string data, CreateMode createMode)
        {
            var bytes = data != null?Encoding.UTF8.GetBytes(data) : null;

            var subPathes = path.Split("/", StringSplitOptions.RemoveEmptyEntries).ToList();

            if (subPathes.Count > 1)
            {
                Create(string.Join("/", subPathes.Take(subPathes.Count - 1)), string.Empty, createMode);
            }
            //Since each path node need to be created by their sequence in the path, we should not run the task in async way,
            //have to wait until the create is done for current path node
            ZooKeeper.Using(zkEndpoint, 1000, new NScrapyConfigWatcher(), async zk =>
            {
                if (path[0] != '/')
                {
                    path = "/" + path;
                }
                if (await zk.existsAsync(path) == null)
                {
                    await zk.createAsync(path, bytes, Ids.OPEN_ACL_UNSAFE, createMode);
                }
            }).Wait();
        }
コード例 #12
0
        protected override async Task <string> GetConnectionString()
        {
            var connectionString = TestDefaultConfiguration.ZooKeeperConnectionString;

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                return(null);
            }

            bool isReachable = false;
            await ZooKeeper.Using(connectionString, 2000, null, async zk =>
            {
                try
                {
                    await zk.existsAsync("/test", false);
                    isReachable = true;
                }
                catch (KeeperException.ConnectionLossException)
                {
                }
            });

            return(isReachable ? connectionString : null);
        }
コード例 #13
0
 private Task UsingZookeeper(string connectString, Func <ZooKeeper, Task> zkMethod)
 {
     return(ZooKeeper.Using(connectString, ZOOKEEPER_CONNECTION_TIMEOUT, watcher, zkMethod));
 }
コード例 #14
0
 private Task <T> UsingZookeeper <T>(Func <ZooKeeper, Task <T> > zkMethod, bool canBeReadOnly = false)
 {
     return(ZooKeeper.Using(deploymentConnectionString, ZOOKEEPER_CONNECTION_TIMEOUT, watcher, zkMethod, canBeReadOnly));
 }
コード例 #15
0
 //-------------------------------------------------------------------------
 public Task UsingZk(string connect_string, Func <ZooKeeper, Task> zk_method)
 {
     return(ZooKeeper.Using(connect_string, ZOOKEEPER_CONNECTION_TIMEOUT, Watcher, zk_method));
 }