builder = new ImmutableMap.Builder<>();
+ ALPHABETS = builder.put("0", "Q")
+ .put("1", "B")
+ .put("2", "W")
+ .put("3", "S")
+ .put("4", "P")
+ .put("5", "H")
+ .put("6", "D")
+ .put("7", "X")
+ .put("8", "Z")
+ .put("9", "U")
+ .build();
+ }
private static String encodeNumber(long number, int length) {
String str = "000000000000" + number;
@@ -146,4 +151,8 @@ public static void shutDownThreadPool(String name, ThreadPoolExecutor pool, Dura
Loggers.UTILS.debug("gracefully shut down thread pool of {}", name);
}
+ public static int intLEFromBytes(byte[] bytes) {
+ return bytes[3] << 24 | (bytes[2] & 255) << 16 | (bytes[1] & 255) << 8 | bytes[0] & 255;
+ }
+
}
diff --git a/src/main/java/co/featureflags/server/VariationSplittingAlgorithm.java b/src/main/java/co/featureflags/server/VariationSplittingAlgorithm.java
index 8766cb6..22dc417 100644
--- a/src/main/java/co/featureflags/server/VariationSplittingAlgorithm.java
+++ b/src/main/java/co/featureflags/server/VariationSplittingAlgorithm.java
@@ -26,7 +26,7 @@ static double percentageOfKey(String key) {
MessageDigest md5 = MessageDigest.getInstance("MD5");
md5.update(key.getBytes(StandardCharsets.US_ASCII));
byte[] digest = md5.digest();
- int magicNumber = Ints.fromByteArray(digest);
+ int magicNumber = Utils.intLEFromBytes(digest);
return Math.abs((double) magicNumber / Integer.MIN_VALUE);
} catch (Exception ex) {
return 0D;
diff --git a/src/main/java/co/featureflags/server/exterior/FFCClient.java b/src/main/java/co/featureflags/server/exterior/FFCClient.java
index b7d801c..b48a443 100644
--- a/src/main/java/co/featureflags/server/exterior/FFCClient.java
+++ b/src/main/java/co/featureflags/server/exterior/FFCClient.java
@@ -79,7 +79,7 @@ public interface FFCClient extends Closeable {
boolean isEnabled(String featureFlagKey, FFCUser user);
/**
- * alias of boolVariation for a given user
+ * alias of boolVariation for a current user
*
* note that this method should be called in the context that support to capture automatically the current user
*
@@ -158,6 +158,29 @@ public interface FFCClient extends Closeable {
*/
long longVariation(String featureFlagKey, Long defaultValue);
+ /**
+ * Calculates the json value of a feature flag for a given user.
+ *
+ * @param featureFlagKey the unique key for the feature flag
+ * @param user the end user requesting the flag
+ * @param clazz json deserialization class
+ * @param defaultValue the default value of the flag
+ * @param json object type
+ * @return the variation for the given user, or {@code defaultValue} if the flag is disabled, current user doesn't exist
+ */
+ T jsonVariation(String featureFlagKey, FFCUser user, Class clazz, T defaultValue);
+
+ /**
+ * Calculates the json value of a feature flag for the current user.
+ *
+ * @param featureFlagKey the unique key for the feature flag
+ * @param clazz json deserialization class
+ * @param defaultValue the default value of the flag
+ * @param json object type
+ * @return the variation for the current user, or {@code defaultValue} if the flag is disabled, current user doesn't exist
+ */
+ T jsonVariation(String featureFlagKey, Class clazz, T defaultValue);
+
/**
* Returns true if the specified feature flag currently exists.
*
@@ -267,7 +290,7 @@ public interface FFCClient extends Closeable {
FlagState doubleVariationDetail(String featureFlagKey, FFCUser user, Double defaultValue);
/**
- * Calculates the double value of a feature flag for a given user, and returns an object that describes the
+ * Calculates the double value of a feature flag for a current user, and returns an object that describes the
* way the value was determined.
*
* note that this method should be called in the context that support to capture automatically the current user
@@ -293,7 +316,7 @@ public interface FFCClient extends Closeable {
FlagState intVariationDetail(String featureFlagKey, FFCUser user, Integer defaultValue);
/**
- * Calculates the int value of a feature flag for a given user, and returns an object that describes the
+ * Calculates the int value of a feature flag for a current user, and returns an object that describes the
* way the value was determined.
*
* Note that If the variation has a numeric value, but not a int value, it is rounded toward zero(DOWN mode)
@@ -315,13 +338,13 @@ public interface FFCClient extends Closeable {
*
* @param featureFlagKey the unique key for the feature flag
* @param user the end user requesting the flag
- * @param defaultValue the unique key for the feature flag
+ * @param defaultValue the default value of the flag
* @return an {@link FlagState} object
*/
FlagState longVariationDetail(String featureFlagKey, FFCUser user, Long defaultValue);
/**
- * Calculates the long of a feature flag for a given user, and returns an object that describes the
+ * Calculates the long of a feature flag for the current user, and returns an object that describes the
* way the value was determined.
*
* Note that If the variation has a numeric value, but not a long value, it is rounded toward zero(DOWN mode)
@@ -329,11 +352,36 @@ public interface FFCClient extends Closeable {
* note that this method should be called in the context that support to capture automatically the current user
*
* @param featureFlagKey the unique key for the feature flag
- * @param defaultValue the unique key for the feature flag
+ * @param defaultValue the default value of the flag
* @return an {@link FlagState} object
*/
FlagState longVariationDetail(String featureFlagKey, Long defaultValue);
+ /**
+ * Calculates the json value of a feature flag for a given user, and returns an object that describes the
+ * way the value was determined.
+ *
+ * @param featureFlagKey the unique key for the feature flag
+ * @param user the end user requesting the flag
+ * @param clazz json deserialization class
+ * @param defaultValue the default value of the flag
+ * @param json object type
+ * @return an {@link FlagState} object
+ */
+ FlagState jsonVariationDetail(String featureFlagKey, FFCUser user, Class clazz, T defaultValue);
+
+ /**
+ * Calculates the json value of a feature flag for a current user, and returns an object that describes the
+ * way the value was determined.
+ *
+ * @param featureFlagKey the unique key for the feature flag
+ * @param clazz json deserialization class
+ * @param defaultValue the default value of the flag
+ * @param json object type
+ * @return an {@link FlagState} object
+ */
+ FlagState jsonVariationDetail(String featureFlagKey, Class clazz, T defaultValue);
+
/**
* Flushes all pending events.
*/
diff --git a/src/main/java/co/featureflags/server/exterior/HttpConfigurationBuilder.java b/src/main/java/co/featureflags/server/exterior/HttpConfigurationBuilder.java
index be9de3b..e471b0d 100644
--- a/src/main/java/co/featureflags/server/exterior/HttpConfigurationBuilder.java
+++ b/src/main/java/co/featureflags/server/exterior/HttpConfigurationBuilder.java
@@ -27,8 +27,8 @@
* @see co.featureflags.server.Factory
*/
public abstract class HttpConfigurationBuilder implements HttpConfigFactory {
- protected final Duration DEFAULT_CONN_TIME = Duration.ofSeconds(10);
- protected final Duration DEFAULT_SOCK_TIME = Duration.ofSeconds(15);
+ protected final Duration DEFAULT_CONN_TIME = Duration.ofSeconds(5);
+ protected final Duration DEFAULT_SOCK_TIME = Duration.ofSeconds(10);
protected Duration connectTime;
protected Duration socketTime;
protected Proxy proxy;