@@ -419,6 +419,25 @@ public boolean isConnected() {
419419 }
420420 }
421421
422+ /**
423+ * Creates a builder with given connect string and session timeout.
424+ *
425+ * @param connectString
426+ * comma separated host:port pairs, each corresponding to a zk
427+ * server. e.g. "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002"
428+ * If the optional chroot suffix is used the example would look
429+ * like: "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002/app/a"
430+ * where the client would be rooted at "/app/a" and all paths
431+ * would be relative to this root - ie getting/setting/etc...
432+ * "/foo/bar" would result in operations being run on
433+ * "/app/a/foo/bar" (from the server perspective).
434+ * @param sessionTimeout
435+ * session timeout
436+ */
437+ public static ZooKeeperBuilder builder (String connectString , Duration sessionTimeout ) {
438+ return new ZooKeeperBuilder (connectString , sessionTimeout );
439+ }
440+
422441 /**
423442 * To create a ZooKeeper client object, the application needs to pass a
424443 * connection string containing a comma separated list of host:port pairs,
@@ -461,9 +480,11 @@ public boolean isConnected() {
461480 * in cases of network failure
462481 * @throws IllegalArgumentException
463482 * if an invalid chroot path is specified
483+ *
484+ * @see #builder(String, Duration) for builder style construction
464485 */
465486 public ZooKeeper (String connectString , int sessionTimeout , Watcher watcher ) throws IOException {
466- this (new ZooKeeperBuilder (connectString , Duration .ofMillis (sessionTimeout ))
487+ this (builder (connectString , Duration .ofMillis (sessionTimeout ))
467488 .withDefaultWatcher (watcher )
468489 .toOptions ());
469490 }
@@ -512,13 +533,15 @@ public ZooKeeper(String connectString, int sessionTimeout, Watcher watcher) thro
512533 * in cases of network failure
513534 * @throws IllegalArgumentException
514535 * if an invalid chroot path is specified
536+ *
537+ * @see #builder(String, Duration) for builder style construction
515538 */
516539 public ZooKeeper (
517540 String connectString ,
518541 int sessionTimeout ,
519542 Watcher watcher ,
520543 ZKClientConfig conf ) throws IOException {
521- this (new ZooKeeperBuilder (connectString , Duration .ofMillis (sessionTimeout ))
544+ this (builder (connectString , Duration .ofMillis (sessionTimeout ))
522545 .withDefaultWatcher (watcher )
523546 .withClientConfig (conf )
524547 .toOptions ());
@@ -580,14 +603,16 @@ public ZooKeeper(
580603 * in cases of network failure
581604 * @throws IllegalArgumentException
582605 * if an invalid chroot path is specified
606+ *
607+ * @see #builder(String, Duration) for builder style construction
583608 */
584609 public ZooKeeper (
585610 String connectString ,
586611 int sessionTimeout ,
587612 Watcher watcher ,
588613 boolean canBeReadOnly ,
589614 HostProvider aHostProvider ) throws IOException {
590- this (new ZooKeeperBuilder (connectString , Duration .ofMillis (sessionTimeout ))
615+ this (builder (connectString , Duration .ofMillis (sessionTimeout ))
591616 .withDefaultWatcher (watcher )
592617 .withCanBeReadOnly (canBeReadOnly )
593618 .withHostProvider (ignored -> aHostProvider )
@@ -652,6 +677,8 @@ public ZooKeeper(
652677 * in cases of network failure
653678 * @throws IllegalArgumentException
654679 * if an invalid chroot path is specified
680+ *
681+ * @see #builder(String, Duration) for builder style construction
655682 */
656683 public ZooKeeper (
657684 String connectString ,
@@ -661,7 +688,7 @@ public ZooKeeper(
661688 HostProvider hostProvider ,
662689 ZKClientConfig clientConfig
663690 ) throws IOException {
664- this (new ZooKeeperBuilder (connectString , Duration .ofMillis (sessionTimeout ))
691+ this (builder (connectString , Duration .ofMillis (sessionTimeout ))
665692 .withDefaultWatcher (watcher )
666693 .withCanBeReadOnly (canBeReadOnly )
667694 .withHostProvider (ignored -> hostProvider )
@@ -741,13 +768,15 @@ ClientCnxn createConnection(
741768 * in cases of network failure
742769 * @throws IllegalArgumentException
743770 * if an invalid chroot path is specified
771+ *
772+ * @see #builder(String, Duration) for builder style construction
744773 */
745774 public ZooKeeper (
746775 String connectString ,
747776 int sessionTimeout ,
748777 Watcher watcher ,
749778 boolean canBeReadOnly ) throws IOException {
750- this (new ZooKeeperBuilder (connectString , Duration .ofMillis (sessionTimeout ))
779+ this (builder (connectString , Duration .ofMillis (sessionTimeout ))
751780 .withDefaultWatcher (watcher )
752781 .withCanBeReadOnly (canBeReadOnly )
753782 .toOptions ());
@@ -806,14 +835,16 @@ public ZooKeeper(
806835 * in cases of network failure
807836 * @throws IllegalArgumentException
808837 * if an invalid chroot path is specified
838+ *
839+ * @see #builder(String, Duration) for builder style construction
809840 */
810841 public ZooKeeper (
811842 String connectString ,
812843 int sessionTimeout ,
813844 Watcher watcher ,
814845 boolean canBeReadOnly ,
815846 ZKClientConfig conf ) throws IOException {
816- this (new ZooKeeperBuilder (connectString , Duration .ofMillis (sessionTimeout ))
847+ this (builder (connectString , Duration .ofMillis (sessionTimeout ))
817848 .withDefaultWatcher (watcher )
818849 .withCanBeReadOnly (canBeReadOnly )
819850 .withClientConfig (conf )
@@ -871,14 +902,16 @@ public ZooKeeper(
871902 * @throws IOException in cases of network failure
872903 * @throws IllegalArgumentException if an invalid chroot path is specified
873904 * @throws IllegalArgumentException for an invalid list of ZooKeeper hosts
905+ *
906+ * @see #builder(String, Duration) for builder style construction
874907 */
875908 public ZooKeeper (
876909 String connectString ,
877910 int sessionTimeout ,
878911 Watcher watcher ,
879912 long sessionId ,
880913 byte [] sessionPasswd ) throws IOException {
881- this (new ZooKeeperBuilder (connectString , Duration .ofMillis (sessionTimeout ))
914+ this (builder (connectString , Duration .ofMillis (sessionTimeout ))
882915 .withDefaultWatcher (watcher )
883916 .withSession (sessionId , sessionPasswd )
884917 .toOptions ());
@@ -947,6 +980,8 @@ public ZooKeeper(
947980 * use this as HostProvider to enable custom behaviour.
948981 * @throws IOException in cases of network failure
949982 * @throws IllegalArgumentException if an invalid chroot path is specified
983+ *
984+ * @see #builder(String, Duration) for builder style construction
950985 */
951986 public ZooKeeper (
952987 String connectString ,
@@ -956,7 +991,7 @@ public ZooKeeper(
956991 byte [] sessionPasswd ,
957992 boolean canBeReadOnly ,
958993 HostProvider aHostProvider ) throws IOException {
959- this (new ZooKeeperBuilder (connectString , Duration .ofMillis (sessionTimeout ))
994+ this (builder (connectString , Duration .ofMillis (sessionTimeout ))
960995 .withDefaultWatcher (watcher )
961996 .withSession (sessionId , sessionPasswd )
962997 .withCanBeReadOnly (canBeReadOnly )
@@ -1032,6 +1067,8 @@ public ZooKeeper(
10321067 * @throws IllegalArgumentException if an invalid chroot path is specified
10331068 *
10341069 * @since 3.5.5
1070+ *
1071+ * @see #builder(String, Duration) for builder style construction
10351072 */
10361073 public ZooKeeper (
10371074 String connectString ,
@@ -1042,7 +1079,7 @@ public ZooKeeper(
10421079 boolean canBeReadOnly ,
10431080 HostProvider hostProvider ,
10441081 ZKClientConfig clientConfig ) throws IOException {
1045- this (new ZooKeeperBuilder (connectString , Duration .ofMillis (sessionTimeout ))
1082+ this (builder (connectString , Duration .ofMillis (sessionTimeout ))
10461083 .withSession (sessionId , sessionPasswd )
10471084 .withDefaultWatcher (watcher )
10481085 .withCanBeReadOnly (canBeReadOnly )
@@ -1054,6 +1091,8 @@ public ZooKeeper(
10541091 /**
10551092 * Create a ZooKeeper client and establish session asynchronously.
10561093 *
1094+ * <p>This is private and export for internal usage.
1095+ *
10571096 * <p>This constructor will initiate connection to the server and return
10581097 * immediately - potentially (usually) before the session is fully established.
10591098 * The watcher from options will be notified of any changes in state. This
@@ -1181,6 +1220,8 @@ public ZooKeeper(ZooKeeperOptions options) throws IOException {
11811220 * majority in the background.
11821221 * @throws IOException in cases of network failure
11831222 * @throws IllegalArgumentException if an invalid chroot path is specified
1223+ *
1224+ * @see #builder(String, Duration) for builder style construction
11841225 */
11851226 public ZooKeeper (
11861227 String connectString ,
@@ -1189,7 +1230,7 @@ public ZooKeeper(
11891230 long sessionId ,
11901231 byte [] sessionPasswd ,
11911232 boolean canBeReadOnly ) throws IOException {
1192- this (new ZooKeeperBuilder (connectString , Duration .ofMillis (sessionTimeout ))
1233+ this (builder (connectString , Duration .ofMillis (sessionTimeout ))
11931234 .withDefaultWatcher (watcher )
11941235 .withSession (sessionId , sessionPasswd )
11951236 .withCanBeReadOnly (canBeReadOnly )
0 commit comments