All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.harness.cf.client.api.CfClient Maven / Gradle / Ivy

The newest version!
package io.harness.cf.client.api;

import com.google.gson.JsonObject;
import io.harness.cf.client.connector.Connector;
import io.harness.cf.client.dto.Message;
import io.harness.cf.client.dto.Target;
import io.harness.cf.client.logger.LogUtil;
import io.harness.cf.model.FeatureSnapshot;
import java.util.List;
import java.util.function.Consumer;
import lombok.NonNull;

public class CfClient implements AutoCloseable {

  private static volatile CfClient instance;
  private InnerClient client;

  static {
    LogUtil.setSystemProps();
  }

  public CfClient() {
    client = null;
  }

  public CfClient(@NonNull final String sdkKey) {
    client = new InnerClient(sdkKey);
  }

  @Deprecated
  public CfClient(@NonNull final String sdkKey, final Config options) {
    client = new InnerClient(sdkKey, options);
  }

  public CfClient(@NonNull final String sdkKey, final BaseConfig options) {
    client = new InnerClient(sdkKey, options);
  }

  public CfClient(@NonNull final Connector connector) {
    client = new InnerClient(connector);
  }

  public CfClient(@NonNull final Connector connector, final BaseConfig options) {
    client = new InnerClient(connector, options);
  }

  public static CfClient getInstance() {

    if (instance == null)
      synchronized (CfClient.class) {
        if (instance == null) {

          instance = new CfClient();
        }
      }
    return instance;
  }

  public void initialize(final String apiKey) {
    initialize(apiKey, Config.builder().build());
  }

  @Deprecated
  public void initialize(final String apiKey, final Config config) {
    client = new InnerClient(apiKey, config);
  }

  public void initialize(final String apiKey, final BaseConfig config) {
    client = new InnerClient(apiKey, config);
  }

  public void initialize(@NonNull final Connector connector) {
    client = new InnerClient(connector);
  }

  public void initialize(@NonNull final Connector connector, final Config options) {
    client = new InnerClient(connector, options);
  }

  public void waitForInitialization() throws InterruptedException, FeatureFlagInitializeException {
    client.waitForInitialization();
  }

  public void on(@NonNull final Event event, @NonNull final Consumer consumer) {
    client.on(event, consumer);
  }

  public List getAllFeatureSnapshots(String prefix) {
    return client.getFeatureSnapshots(prefix);
  }

  public List getAllFeatureSnapshots() {
    return client.getFeatureSnapshots();
  }

  public FeatureSnapshot getFeatureSnapshot(@NonNull String identifier) {
    return client.getFeatureSnapshot(identifier);
  }

  public void off() {
    client.off();
  }

  public void off(@NonNull final Event event) {
    client.off(event);
  }

  public void off(@NonNull final Event event, @NonNull final Consumer consumer) {
    client.off(event, consumer);
  }

  public void update(@NonNull final Message message) {
    client.update(message, true);
  }

  public boolean boolVariation(
      @NonNull final String identifier, final Target target, final boolean defaultValue) {
    return client.boolVariation(identifier, target, defaultValue);
  }

  public String stringVariation(
      @NonNull String identifier, final Target target, @NonNull final String defaultValue) {
    return client.stringVariation(identifier, target, defaultValue);
  }

  public double numberVariation(
      @NonNull final String identifier, final Target target, final double defaultValue) {
    return client.numberVariation(identifier, target, defaultValue);
  }

  public JsonObject jsonVariation(
      @NonNull final String identifier,
      final Target target,
      @NonNull final JsonObject defaultValue) {
    return client.jsonVariation(identifier, target, defaultValue);
  }

  public void close() {
    client.close();
  }

  @Deprecated
  public void destroy() {
    close();
  }

  /* Package private */

  InnerClient getInnerClient() {
    return client;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy