io.harness.cf.client.common.Utils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ff-java-server-sdk Show documentation
Show all versions of ff-java-server-sdk Show documentation
Harness Feature Flag Java Server SDK
The newest version!
package io.harness.cf.client.common;
import static java.util.concurrent.TimeUnit.SECONDS;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.function.Consumer;
public class Utils {
private Utils() {}
public static void shutdownExecutorService(
ExecutorService scheduler, Runnable successCallback, Consumer failCallback) {
scheduler.shutdown();
final int TIMEOUT = 10;
try {
if (!scheduler.awaitTermination(TIMEOUT, SECONDS)) {
scheduler.shutdownNow();
if (scheduler.awaitTermination(TIMEOUT, SECONDS)) {
successCallback.run();
} else {
failCallback.accept(
"ScheduledExecutorService failed to terminate after " + TIMEOUT + " seconds");
}
} else {
successCallback.run();
}
} catch (InterruptedException ie) {
scheduler.shutdownNow();
Thread.currentThread().interrupt();
}
}
public static Map redactHeaders(Map hdrsMap) {
if (hdrsMap == null || hdrsMap.isEmpty()) return Collections.emptyMap();
HashMap map = new HashMap<>(hdrsMap);
map.computeIfPresent("Authorization", (k, v) -> "*");
map.computeIfPresent("API-Key", (k, v) -> "*");
return map;
}
public static boolean isEmpty(Collection> collection) {
return collection == null || collection.isEmpty();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy