Package org.apache.zookeeper.client
Class ZooKeeperBuilder
java.lang.Object
org.apache.zookeeper.client.ZooKeeperBuilder
Builder to construct
ZooKeeper and ZooKeeperAdmin.-
Constructor Summary
ConstructorsConstructorDescriptionZooKeeperBuilder(String connectString, Duration sessionTimeout) This is private and export for internal usage. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Constructs an instance ofZooKeeper.Constructs an instance ofZooKeeperAdmin.Creates aZooKeeperOptionswith configured options.withCanBeReadOnly(boolean canBeReadOnly) Specifies whether the created client is allowed to go to read-only mode in case of partitioning.withClientConfig(ZKClientConfig clientConfig) Specifies the client config used to construct ZooKeeper instances.withDefaultWatcher(Watcher watcher) Specified watcher to receive state changes, and node events if attached later.withHostProvider(Function<Collection<InetSocketAddress>, HostProvider> hostProvider) Specifies a function to construct aHostProviderwith initial server addresses from connect string.withNewSessionTimeout(Duration timeout) Specifies timeout to establish a brand-new session.withSession(long sessionId, byte[] sessionPasswd) Specifies session id and password in session reestablishment.
-
Constructor Details
-
ZooKeeperBuilder
This is private and export for internal usage. UseZooKeeper.builder(String, Duration)instead.
-
-
Method Details
-
withDefaultWatcher
Specified watcher to receive state changes, and node events if attached later.- Parameters:
watcher- a watcher object which will be notified of state changes, may also be notified for node events- Returns:
- this
-
withHostProvider
public ZooKeeperBuilder withHostProvider(Function<Collection<InetSocketAddress>, HostProvider> hostProvider) Specifies a function to construct aHostProviderwith initial server addresses from connect string.- Parameters:
hostProvider- use this as HostProvider to enable custom behaviour.- Returns:
- this
-
withCanBeReadOnly
Specifies whether the created client is allowed to go to read-only mode in case of partitioning.- Parameters:
canBeReadOnly- whether the created client is allowed to go to read-only mode in case of partitioning. Read-only mode basically means that if the client can't find any majority servers but there's partitioned server it could reach, it connects to one in read-only mode, i.e. read requests are allowed while write requests are not. It continues seeking for majority in the background.- Returns:
- this
- Since:
- 3.4
-
withSession
Specifies session id and password in session reestablishment.- Parameters:
sessionId- session id to use if reconnecting, otherwise 0 to open new sessionsessionPasswd- password for this session- Returns:
- this
- See Also:
-
withNewSessionTimeout
Specifies timeout to establish a brand-new session.- Parameters:
timeout- timeout to getWatcher.Event.KeeperState.Expiredin establishing a brand-new session.Duration.ofSeconds(Long.MAX_VALUE, 999_999_999L), which is the default, means endless retry until connected.Duration.ZEROmeans a sensible value deduced from specified session timeout, currently, it is approximatesessionTimeout * 4 / 3.- Returns:
- this
- Since:
- 3.10.0
-
withClientConfig
Specifies the client config used to construct ZooKeeper instances.- Parameters:
clientConfig- passing this conf object gives each client the flexibility of configuring properties differently compared to other instances- Returns:
- this
- Since:
- 3.5.2
-
toOptions
Creates aZooKeeperOptionswith configured options.This is private and export for internal usage.
-
build
Constructs an instance ofZooKeeper.- Returns:
- an instance of
ZooKeeper - Throws:
IOException- from constructor ofZooKeeper
-
buildAdmin
Constructs an instance ofZooKeeperAdmin.- Returns:
- an instance of
ZooKeeperAdmin - Throws:
IOException- from constructor ofZooKeeperAdmin
-