Created
February 19, 2013 05:42
-
-
Save definitelyMVP/4983389 to your computer and use it in GitHub Desktop.
curator one-time watcher examper
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.CuratorWatcher; | |
import com.netflix.curator.retry.ExponentialBackoffRetry; | |
import org.apache.zookeeper.WatchedEvent; | |
import org.apache.zookeeper.Watcher; | |
/** | |
* @author yl | |
* @date 2013-02-19 | |
*/ | |
public class OneTimeWatcherExample { | |
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().usingWatcher(new CuratorWatcher() { | |
@Override | |
public void process(WatchedEvent event) throws Exception { | |
if (event.getType().equals(Watcher.Event.EventType.NodeDataChanged)) { | |
System.out.println(path + " data change watched."); | |
} | |
} | |
}).forPath(path); | |
Thread.sleep(Integer.MAX_VALUE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment