Skip to content

Instantly share code, notes, and snippets.

@definitelyMVP
definitelyMVP / LeaderLatchExample.java
Created February 19, 2013 10:33
a curator LeaderLatch example
import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.CuratorFrameworkFactory;
import com.netflix.curator.framework.recipes.leader.LeaderLatch;
import com.netflix.curator.framework.recipes.leader.Participant;
import com.netflix.curator.retry.ExponentialBackoffRetry;
import java.io.IOException;
/**
* @author yl
@definitelyMVP
definitelyMVP / ConnectionStateListenerExample.java
Last active November 5, 2019 15:12
a curator ConnectionStateListener example
import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.CuratorFrameworkFactory;
import com.netflix.curator.framework.state.ConnectionState;
import com.netflix.curator.framework.state.ConnectionStateListener;
import com.netflix.curator.retry.ExponentialBackoffRetry;
/**
* 1.run this, you will see output "** STATE CHANGED TO : CONNECTED";
* 2.kill your zk server, you will see output "** STATE CHANGED TO : SUSPENDED";
* 3.start your zk server, you will see output "** STATE CHANGED TO : RECONNECTED".
@definitelyMVP
definitelyMVP / CuratorListenerExample.java
Last active September 5, 2018 05:53
a CuratorListener Example
import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.CuratorFrameworkFactory;
import com.netflix.curator.framework.api.CuratorEvent;
import com.netflix.curator.framework.api.CuratorListener;
import com.netflix.curator.retry.ExponentialBackoffRetry;
/**
* run this and change the data of "/yl", then you should see output like
* "WatchedEvent state:SyncConnected type:NodeDataChanged path:/yl watched"
*
@definitelyMVP
definitelyMVP / CuratorAsyncGetDataExample.java
Created February 19, 2013 05:52
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
*/
@definitelyMVP
definitelyMVP / OneTimeWatcherExample.java
Created February 19, 2013 05:42
curator one-time watcher examper
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
@definitelyMVP
definitelyMVP / PersistantWatcherExample.java
Last active July 1, 2016 10:39
curator node cache example
import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.CuratorFrameworkFactory;
import com.netflix.curator.framework.recipes.cache.ChildData;
import com.netflix.curator.framework.recipes.cache.NodeCache;
import com.netflix.curator.framework.recipes.cache.NodeCacheListener;
import com.netflix.curator.retry.ExponentialBackoffRetry;
/**
* @author yl
* @date 2013-02-19