private static Task deleteNode(string path) { return(ZooKeeper.Using(hostPort, CONNECTION_TIMEOUT, NullWatcher.Instance, zk => { return ZKUtil.deleteRecursiveAsync(zk, path); })); }
public static void Delete(string path) { ZooKeeper.Using(zkEndpoint, 1000, new NScrapyConfigWatcher(), async zk => { await zk.deleteAsync(path); }); }
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)); }); }
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; })); }
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); }
internal static Task deleteNode(string path) { return(ZooKeeper.Using(hostPort, 10000, new NullWatcher(), async zk => { await ZKUtil.deleteRecursiveAsync(zk, path); await zk.sync("/"); })); }
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"); }
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; })); }
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)); }
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; } })); }
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(); }
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); }
private Task UsingZookeeper(string connectString, Func <ZooKeeper, Task> zkMethod) { return(ZooKeeper.Using(connectString, ZOOKEEPER_CONNECTION_TIMEOUT, watcher, zkMethod)); }
private Task <T> UsingZookeeper <T>(Func <ZooKeeper, Task <T> > zkMethod, bool canBeReadOnly = false) { return(ZooKeeper.Using(deploymentConnectionString, ZOOKEEPER_CONNECTION_TIMEOUT, watcher, zkMethod, canBeReadOnly)); }
//------------------------------------------------------------------------- public Task UsingZk(string connect_string, Func <ZooKeeper, Task> zk_method) { return(ZooKeeper.Using(connect_string, ZOOKEEPER_CONNECTION_TIMEOUT, Watcher, zk_method)); }