static void Main(string[] args) { var client = new org.apache.zookeeper.ZooKeeper( "10.217.9.184:2181,10.217.6.124:2181,10.217.6.140:2181,10.217.6.222:2181,10.217.9.47:2181", 5000, null); Thread.Sleep(1000); var path = "/LinuxMustDie"; var data = "LINUX IS ALIVE!!"; var createResult = client.createAsync(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); Console.WriteLine($"Create result = {createResult}"); var setDataResult = client.setDataAsync(path, Encoding.UTF8.GetBytes(data)).GetAwaiter().GetResult(); Console.WriteLine($"SetData result version = {setDataResult.getVersion()}"); var getDataResult = client.getDataAsync(path).GetAwaiter().GetResult(); Console.WriteLine($"GetData result = {Encoding.UTF8.GetString(getDataResult.Data)}"); Console.ReadKey(); client.deleteAsync(path).Wait(); }
public async Task ChangeValue(string path, string value) { var zk = new org.apache.zookeeper.ZooKeeper("127.0.0.1:2181", 60000, null); await zk.setDataAsync(path, Encoding.UTF8.GetBytes(value)); await zk.closeAsync(); }
public async Task <int> IncrementAndWatchEpochAsync(int currentEpoch, Watcher watcher) { string actionToPerform = "increment epoch"; while (true) { await BlockUntilConnected(actionToPerform); try { byte[] data = Encoding.UTF8.GetBytes("0"); Stat stat = await zookeeper.setDataAsync(epochPath, data, currentEpoch); DataResult dataRes = await zookeeper.getDataAsync(epochPath, watcher); if (dataRes.Stat.getVersion() == stat.getVersion()) { return(dataRes.Stat.getVersion()); } throw new ZkStaleVersionException( "Between incrementing the epoch and setting a watch the epoch was incremented"); } catch (KeeperException.BadVersionException e) { throw new ZkStaleVersionException( $"Could not {actionToPerform} as the current epoch was incremented already.", e); } catch (KeeperException.NoNodeException e) { throw new ZkInvalidOperationException($"Could not {actionToPerform} as the node does not exist.", e); } catch (KeeperException.ConnectionLossException) { // do nothing, the next iteration will try again } catch (KeeperException.SessionExpiredException e) { throw new ZkSessionExpiredException($"Could not {actionToPerform} as the session has expired: ", e); } catch (Exception e) { throw new ZkInvalidOperationException($"Could not {actionToPerform} due to an unexpected error", e); } } }
protected static void SetData(string path, string data, org.apache.zookeeper.ZooKeeper client) { var setDataResult = client.setDataAsync(path, Encoding.UTF8.GetBytes(data)).GetAwaiter().GetResult(); setDataResult.Should().NotBeNull(); //setDataResult.EnsureSuccess(); //setDataResult.Status.Should().Be(ZooKeeperStatus.Ok); //setDataResult.Path.Should().Be(path); }
public async Task SetDataAsync(string path, byte[] data, int version) { await _zooKeeper.setDataAsync(path, data, version); }