From 5179c189bdf734581ae78d7eff807e5ed0188c3b Mon Sep 17 00:00:00 2001 From: Laurent Goujon Date: Mon, 11 Mar 2024 14:30:20 -0700 Subject: [PATCH] Remove Version enum --- .../curator/utils/ZookeeperCompatibility.java | 57 +++++++++++++------ .../framework/CuratorFrameworkFactory.java | 8 +-- .../details/AsyncCuratorFrameworkImpl.java | 1 - 3 files changed, 44 insertions(+), 22 deletions(-) diff --git a/curator-client/src/main/java/org/apache/curator/utils/ZookeeperCompatibility.java b/curator-client/src/main/java/org/apache/curator/utils/ZookeeperCompatibility.java index 58f9f3259..a14c1a9fe 100644 --- a/curator-client/src/main/java/org/apache/curator/utils/ZookeeperCompatibility.java +++ b/curator-client/src/main/java/org/apache/curator/utils/ZookeeperCompatibility.java @@ -20,29 +20,52 @@ package org.apache.curator.utils; /** - * Describe feature supports based on server compatibility (as opposed to {@code Compatibility} - * which represents client compatibility. + * Describe feature supports based on server compatibility (as opposed to + * {@code Compatibility} which represents client compatibility. */ -public interface ZookeeperCompatibility { - public enum Version implements ZookeeperCompatibility { - VERSION_3_5(false), - LATEST(true); +public class ZookeeperCompatibility { + /** + * Represent latest version with all features enabled + */ + public static final ZookeeperCompatibility LATEST = + builder().hasPersistentWatchers(true).build(); + + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + // List of features introduced by Zookeeper over time. + // All values are set to false by default for backward compatibility + private boolean hasPersistentWatchers = false; + + public Builder hasPersistentWatchers(boolean value) { + this.hasPersistentWatchers = value; + return this; + } + + public boolean hasPersistentWatchers() { + return this.hasPersistentWatchers; + } + + public ZookeeperCompatibility build() { + return new ZookeeperCompatibility(this); + } + } private final boolean hasPersistentWatchers; - private Version(boolean hasPersistentWatchers) { - this.hasPersistentWatchers = hasPersistentWatchers; + private ZookeeperCompatibility(Builder builder) { + this.hasPersistentWatchers = builder.hasPersistentWatchers; } - @Override + /** + * Check if both client and server support persistent watchers + * + * @return {@code true} if both the client library and the server version + * support persistent watchers + */ public boolean hasPersistentWatchers() { - return this.hasPersistentWatchers && Compatibility.hasPersistentWatchers(); + return this.hasPersistentWatchers && Compatibility.hasPersistentWatchers(); } - } - - /** - * Check if both client and server support persistent watchers - * @return {@code true} if both the client library and the server version support persistent watchers - */ - boolean hasPersistentWatchers(); } diff --git a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java index f8cdd2ccc..d24b56d64 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/CuratorFrameworkFactory.java @@ -175,7 +175,7 @@ public static class Builder { ConnectionStateListenerManagerFactory.standard; private int simulatedSessionExpirationPercent = 100; private ZKClientConfig zkClientConfig; - private ZookeeperCompatibility zookeeperCompatibility = ZookeeperCompatibility.Version.LATEST; + private ZookeeperCompatibility zookeeperCompatibility = ZookeeperCompatibility.LATEST; /** * Apply the current values and build a new CuratorFramework @@ -522,8 +522,8 @@ public Builder connectionStateListenerManagerFactory( } public Builder zookeeperCompatibility(ZookeeperCompatibility zookeeperCompatibility) { - this.zookeeperCompatibility = zookeeperCompatibility; - return this; + this.zookeeperCompatibility = zookeeperCompatibility; + return this; } public Executor getRunSafeService() { @@ -648,7 +648,7 @@ public ConnectionStateListenerManagerFactory getConnectionStateListenerManagerFa } public ZookeeperCompatibility getZookeeperCompatibility() { - return zookeeperCompatibility; + return zookeeperCompatibility; } private Builder() {} diff --git a/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCuratorFrameworkImpl.java b/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCuratorFrameworkImpl.java index 171f1215a..ee2941e4d 100644 --- a/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCuratorFrameworkImpl.java +++ b/curator-x-async/src/main/java/org/apache/curator/x/async/details/AsyncCuratorFrameworkImpl.java @@ -40,7 +40,6 @@ import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; - public class AsyncCuratorFrameworkImpl implements AsyncCuratorFramework { private final CuratorFrameworkImpl client; private final Filters filters;