Database Reference
In-Depth Information
Adding Curator to a Maven Project
The Curator library has been broken into several different components,
all of which are available from Maven Central. Adding the curator-recipes
artifact to the project includes all of the relevant components:
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-recipes</artifactId>
<version>2.3.0</version>
</dependency>
Most users will only ever need to use this artifact because it also includes
in-depth implementations of recipes provided in the last section. If the
recipes should not be included, the framework can be imported by itself via
the curator-framework artifact:
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>2.3.0</version>
</dependency>
Connecting to ZooKeeper
The Curator ZooKeeper client class is CuratorFramework , which is
created by calling the newClient static method of the
CuratorFrameworkFactory class. For example, connecting to a local
ZooKeeper instance would look like this:
CuratorFramework client =
CuratorFrameworkFactory. newClient (
"localhost:2181",
new ExponentialBackoffRetry(1000,3)
);
Thefirstargument istheusualZooKeeperconnection string. Asusual,itcan
contain a comma-separated list of available hosts, one of which is selected
for connection. The second argument is a retry policy, which is unique
to Curator. In this case the ExponentialBackoffRetry policy is used
Search WWH ::




Custom Search