Skip to content

Instantly share code, notes, and snippets.

@definitelyMVP
Created February 19, 2013 05:52
Show Gist options
  • Save definitelyMVP/4983429 to your computer and use it in GitHub Desktop.
Save definitelyMVP/4983429 to your computer and use it in GitHub Desktop.
Curator async getData example
import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.CuratorFrameworkFactory;
import com.netflix.curator.framework.api.BackgroundCallback;
import com.netflix.curator.framework.api.CuratorEvent;
import com.netflix.curator.retry.ExponentialBackoffRetry;
/**
* @author yl
* @date 2013-02-19
*/
public class CuratorAsyncGetDataExample {
public static void main(String[] args) throws Exception {
ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, Integer.MAX_VALUE);
CuratorFramework curator = CuratorFrameworkFactory.newClient("10.12.136.235:2181", retryPolicy);
curator.start();
curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
final String path = "/yl";
curator.getData().inBackground(new BackgroundCallback() {
@Override
public void processResult(CuratorFramework client, CuratorEvent event) throws Exception {
System.out.println("get data in background : " + new String(event.getData()));
}
}).forPath(path);
Thread.sleep(5000);
curator.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment