Re: Zookeeper.sync() behavior

2022-09-22 Thread Enrico Olivelli
Keith

Il Gio 22 Set 2022, 15:03 Keith Turner  ha scritto:

> I have read some documentation about Zookeeper.sync() that makes me
> think there is no need to wait on its callback before reading data,
> but its not explicitly stated in what I have read. I am wondering if
> the following code is a reasonable way to get the latest data for
> '/a/b'?
>
>   ZooKeeper zooKeeper = null;
>
>   AsyncCallback.VoidCallback cb;
>   CompletableFuture returnCode = new CompletableFuture<>();
>   zooKeeper.sync("/a/b", (rc, path, ctx) -> returnCode.complete(rc), null);
>   zooKeeper.getData("/a/b",false, null);
>   if(returnCode.get() != 0) {
> //handle problem with sync
>   }
>
> Thanks
>

I think that generally you have to wait for 'sync' to complete
successfully, then you can call getData()

Otherwise  for instance if the error is ConnectionLoss you haven't really
sent the sync command to the server

I hope that helps

Enrico


> Keith
>


Zookeeper.sync() behavior

2022-09-22 Thread Keith Turner
I have read some documentation about Zookeeper.sync() that makes me
think there is no need to wait on its callback before reading data,
but its not explicitly stated in what I have read. I am wondering if
the following code is a reasonable way to get the latest data for
'/a/b'?

  ZooKeeper zooKeeper = null;

  AsyncCallback.VoidCallback cb;
  CompletableFuture returnCode = new CompletableFuture<>();
  zooKeeper.sync("/a/b", (rc, path, ctx) -> returnCode.complete(rc), null);
  zooKeeper.getData("/a/b",false, null);
  if(returnCode.get() != 0) {
//handle problem with sync
  }

Thanks

Keith