com.netflix.curator
Class CuratorZookeeperClient

java.lang.Object
  extended by com.netflix.curator.CuratorZookeeperClient
All Implemented Interfaces:
Closeable

public class CuratorZookeeperClient
extends Object
implements Closeable

A wrapper around Zookeeper that takes care of some low-level housekeeping


Constructor Summary
CuratorZookeeperClient(String connectString, int sessionTimeoutMs, int connectionTimeoutMs, org.apache.zookeeper.Watcher watcher, RetryPolicy retryPolicy)
           
 
Method Summary
 boolean blockUntilConnectedOrTimedOut()
          This method blocks until the connection to ZK succeeds.
 void close()
          Close the client
 RetryPolicy getRetryPolicy()
          Return the current retry policy
 TracerDriver getTracerDriver()
          Return the current tracing driver
 org.apache.zookeeper.ZooKeeper getZooKeeper()
          Return the managed ZK instance.
 boolean isConnected()
          Returns true if the client is current connected
 RetryLoop newRetryLoop()
          Return a new retry loop.
 void setRetryPolicy(RetryPolicy policy)
          Change the retry policy
 void setTracerDriver(TracerDriver tracer)
          Change the tracing driver
 void start()
          Must be called after construction
 TimeTrace startTracer(String name)
          Start a new tracer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CuratorZookeeperClient

public CuratorZookeeperClient(String connectString,
                              int sessionTimeoutMs,
                              int connectionTimeoutMs,
                              org.apache.zookeeper.Watcher watcher,
                              RetryPolicy retryPolicy)
                       throws IOException
Parameters:
connectString - list of servers to connect to
sessionTimeoutMs - session timeout
connectionTimeoutMs - connection timeout
watcher - default watcher or null
retryPolicy - the retry policy to use
Throws:
IOException - ZooKeeper creation errors
Method Detail

getZooKeeper

public org.apache.zookeeper.ZooKeeper getZooKeeper()
                                            throws Exception
Return the managed ZK instance.

Returns:
client the client
Throws:
Exception - if the connection timeout has elapsed or an exception occurs in a background process

newRetryLoop

public RetryLoop newRetryLoop()
Return a new retry loop. All operations should be performed in a retry loop

Returns:
new retry loop

isConnected

public boolean isConnected()
Returns true if the client is current connected

Returns:
true/false

blockUntilConnectedOrTimedOut

public boolean blockUntilConnectedOrTimedOut()
                                      throws InterruptedException
This method blocks until the connection to ZK succeeds. Use with caution. The block will timeout after the connection timeout (as passed to the constructor) has elapsed

Returns:
true if the connection succeeded, false if not
Throws:
InterruptedException - interrupted while waiting

start

public void start()
           throws Exception
Must be called after construction

Throws:
IOException - errors
Exception

close

public void close()
Close the client

Specified by:
close in interface Closeable

setRetryPolicy

public void setRetryPolicy(RetryPolicy policy)
Change the retry policy

Parameters:
policy - new policy

getRetryPolicy

public RetryPolicy getRetryPolicy()
Return the current retry policy

Returns:
policy

startTracer

public TimeTrace startTracer(String name)
Start a new tracer

Parameters:
name - name of the event
Returns:
the new tracer (TimeTrace.commit() must be called)

getTracerDriver

public TracerDriver getTracerDriver()
Return the current tracing driver

Returns:
tracing driver

setTracerDriver

public void setTracerDriver(TracerDriver tracer)
Change the tracing driver

Parameters:
tracer - new tracing driver


Copyright © 2012. All Rights Reserved.