public class CuratorZookeeperClient
extends java.lang.Object
implements java.io.Closeable
Constructor and Description |
---|
CuratorZookeeperClient(EnsembleProvider ensembleProvider,
int sessionTimeoutMs,
int connectionTimeoutMs,
org.apache.zookeeper.Watcher watcher,
RetryPolicy retryPolicy) |
CuratorZookeeperClient(java.lang.String connectString,
int sessionTimeoutMs,
int connectionTimeoutMs,
org.apache.zookeeper.Watcher watcher,
RetryPolicy retryPolicy) |
CuratorZookeeperClient(ZookeeperFactory zookeeperFactory,
EnsembleProvider ensembleProvider,
int sessionTimeoutMs,
int connectionTimeoutMs,
org.apache.zookeeper.Watcher watcher,
RetryPolicy retryPolicy) |
Modifier and Type | Method and Description |
---|---|
boolean |
blockUntilConnectedOrTimedOut()
This method blocks until the connection to ZK succeeds.
|
void |
close()
Close the client
|
java.lang.String |
getCurrentConnectionString()
Returns the current known connection string - not guaranteed to be correct
value at any point in the future.
|
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.
|
SessionFailRetryLoop |
newSessionFailRetryLoop(SessionFailRetryLoop.Mode mode)
Return a new "session fail" 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(java.lang.String name)
Start a new tracer
|
public CuratorZookeeperClient(java.lang.String connectString, int sessionTimeoutMs, int connectionTimeoutMs, org.apache.zookeeper.Watcher watcher, RetryPolicy retryPolicy)
connectString
- list of servers to connect tosessionTimeoutMs
- session timeoutconnectionTimeoutMs
- connection timeoutwatcher
- default watcher or nullretryPolicy
- the retry policy to usepublic CuratorZookeeperClient(EnsembleProvider ensembleProvider, int sessionTimeoutMs, int connectionTimeoutMs, org.apache.zookeeper.Watcher watcher, RetryPolicy retryPolicy) throws java.io.IOException
ensembleProvider
- the ensemble providersessionTimeoutMs
- session timeoutconnectionTimeoutMs
- connection timeoutwatcher
- default watcher or nullretryPolicy
- the retry policy to usejava.io.IOException
- ZooKeeper creation errorspublic CuratorZookeeperClient(ZookeeperFactory zookeeperFactory, EnsembleProvider ensembleProvider, int sessionTimeoutMs, int connectionTimeoutMs, org.apache.zookeeper.Watcher watcher, RetryPolicy retryPolicy)
zookeeperFactory
- factory for creating ZooKeeper
instancesensembleProvider
- the ensemble providersessionTimeoutMs
- session timeoutconnectionTimeoutMs
- connection timeoutwatcher
- default watcher or nullretryPolicy
- the retry policy to usejava.io.IOException
- ZooKeeper creation errorspublic org.apache.zookeeper.ZooKeeper getZooKeeper() throws java.lang.Exception
java.lang.Exception
- if the connection timeout has elapsed or an exception occurs in a background processpublic RetryLoop newRetryLoop()
public SessionFailRetryLoop newSessionFailRetryLoop(SessionFailRetryLoop.Mode mode)
SessionFailRetryLoop
for details
on when to use it.mode
- failure modepublic boolean isConnected()
public boolean blockUntilConnectedOrTimedOut() throws java.lang.InterruptedException
java.lang.InterruptedException
- interrupted while waitingpublic void start() throws java.lang.Exception
java.io.IOException
- errorsjava.lang.Exception
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public void setRetryPolicy(RetryPolicy policy)
policy
- new policypublic RetryPolicy getRetryPolicy()
public TimeTrace startTracer(java.lang.String name)
name
- name of the eventTimeTrace.commit()
must be called)public TracerDriver getTracerDriver()
public void setTracerDriver(TracerDriver tracer)
tracer
- new tracing driverpublic java.lang.String getCurrentConnectionString()