public class ZooKeeperConnection
extends java.lang.Object
implements org.springframework.context.SmartLifecycle
CuratorFramework
instance whose lifecycle is managed as a Spring bean. Accepts
ZooKeeperConnectionListener
s to be notified when connection or disconnection events are received.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_CLIENT_CONNECT_STRING
The default client connect string.
|
Constructor and Description |
---|
ZooKeeperConnection()
Establish a ZooKeeper connection with the default client connect string: "localhost:2181"
|
ZooKeeperConnection(java.lang.String clientConnectString)
Establish a ZooKeeper connection with the provided client connect string.
|
ZooKeeperConnection(java.lang.String clientConnectString,
java.lang.String namespace)
Establish a ZooKeeper connection with the provided client connect string and namespace.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addListener(ZooKeeperConnectionListener listener)
Add a
ZooKeeperConnectionListener . |
org.apache.curator.framework.CuratorFramework |
getClient()
Provides access to the underlying
CuratorFramework instance. |
int |
getPhase() |
org.apache.curator.RetryPolicy |
getRetryPolicy()
Return the Curator retry policy.
|
boolean |
isAutoStartup() |
boolean |
isConnected()
Checks whether the underlying connection is established.
|
boolean |
isRunning()
Check whether this client is running.
|
boolean |
removeListener(ZooKeeperConnectionListener listener)
Remove a
ZooKeeperConnectionListener . |
void |
setAutoStartup(boolean autoStartup)
Set the flag that indicates whether this connection
should be started automatically.
|
void |
setRetryPolicy(org.apache.curator.RetryPolicy retryPolicy)
Set the Curator retry policy.
|
void |
start()
Starts the underlying
CuratorFramework instance. |
void |
stop()
Closes the underlying
CuratorFramework instance. |
void |
stop(java.lang.Runnable callback)
Closes the underlying
CuratorFramework instance and then invokes the callback. |
public static final java.lang.String DEFAULT_CLIENT_CONNECT_STRING
public ZooKeeperConnection()
public ZooKeeperConnection(java.lang.String clientConnectString)
clientConnectString
- one or more host:port
strings, comma-delimited if more than onepublic ZooKeeperConnection(java.lang.String clientConnectString, java.lang.String namespace)
clientConnectString
- one or more host:port
strings, comma-delimited if more than onenamespace
- the root path namespace in ZooKeeper (or default namespace if null)public boolean isConnected()
public org.apache.curator.framework.CuratorFramework getClient()
CuratorFramework
instance.CuratorFramework
instancepublic boolean addListener(ZooKeeperConnectionListener listener)
ZooKeeperConnectionListener
.listener
- the listener to addpublic boolean removeListener(ZooKeeperConnectionListener listener)
ZooKeeperConnectionListener
.listener
- the listener to removepublic boolean isAutoStartup()
isAutoStartup
in interface org.springframework.context.SmartLifecycle
public void setAutoStartup(boolean autoStartup)
autoStartup
- if true, indicates this connection should
be started automaticallypublic void setRetryPolicy(org.apache.curator.RetryPolicy retryPolicy)
retryPolicy
- Curator client RetryPolicy
public org.apache.curator.RetryPolicy getRetryPolicy()
public int getPhase()
getPhase
in interface org.springframework.context.Phased
public boolean isRunning()
isRunning
in interface org.springframework.context.Lifecycle
public void start()
CuratorFramework
instance.start
in interface org.springframework.context.Lifecycle
public void stop()
CuratorFramework
instance.stop
in interface org.springframework.context.Lifecycle
public void stop(java.lang.Runnable callback)
CuratorFramework
instance and then invokes the callback.stop
in interface org.springframework.context.SmartLifecycle