Created
February 19, 2013 05:52
-
-
Save definitelyMVP/4983429 to your computer and use it in GitHub Desktop.
Curator async getData example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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