Skip to content

Commit

Permalink
Remove Version enum
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentgo committed Mar 11, 2024
1 parent 0858710 commit 5179c18
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -648,7 +648,7 @@ public ConnectionStateListenerManagerFactory getConnectionStateListenerManagerFa
}

public ZookeeperCompatibility getZookeeperCompatibility() {
return zookeeperCompatibility;
return zookeeperCompatibility;
}

private Builder() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5179c18

Please sign in to comment.