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

com.launchdarkly.sdk.server.FeatureRequestor Maven / Gradle / Ivy

package com.launchdarkly.sdk.server;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.launchdarkly.sdk.server.DataModel.VersionedData;
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.DataKind;
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.FullDataSet;
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.ItemDescriptor;
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.KeyedItems;

import java.io.Closeable;
import java.io.IOException;
import java.util.AbstractMap;
import java.util.Map;

import static com.launchdarkly.sdk.server.DataModel.FEATURES;
import static com.launchdarkly.sdk.server.DataModel.SEGMENTS;

interface FeatureRequestor extends Closeable {
  DataModel.FeatureFlag getFlag(String featureKey) throws IOException, HttpErrorException;

  DataModel.Segment getSegment(String segmentKey) throws IOException, HttpErrorException;

  AllData getAllData() throws IOException, HttpErrorException;

  static class AllData {
    final Map flags;
    final Map segments;
    
    AllData(Map flags, Map segments) {
      this.flags = flags;
      this.segments = segments;
    }

    FullDataSet toFullDataSet() {
      return new FullDataSet(ImmutableMap.of(
          FEATURES, toKeyedItems(FEATURES, flags),
          SEGMENTS, toKeyedItems(SEGMENTS, segments)
          ).entrySet());
    }

    static KeyedItems toKeyedItems(DataKind kind, Map itemsMap) {
      ImmutableList.Builder> builder = ImmutableList.builder();
      if (itemsMap != null) {
        for (Map.Entry e: itemsMap.entrySet()) {
          ItemDescriptor item = new ItemDescriptor(e.getValue().getVersion(), e.getValue());
          builder.add(new AbstractMap.SimpleEntry<>(e.getKey(), item));
        }
      }
      return new KeyedItems<>(builder.build());
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy