Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #205 from launchdarkly/eb/ch51696/stream-store-status
Browse files Browse the repository at this point in the history
(5.0 - #7) add stream logic for data store outages + improve test code
  • Loading branch information
eli-darkly authored Apr 15, 2020
2 parents 5c179a2 + 9dbefe3 commit 49cf6df
Show file tree
Hide file tree
Showing 24 changed files with 821 additions and 598 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ public Status getStoreStatus() {
}

@Override
public void addStatusListener(StatusListener listener) {
if (delegateTo != null) {
delegateTo.addStatusListener(listener);
}
public boolean addStatusListener(StatusListener listener) {
return delegateTo != null && delegateTo.addStatusListener(listener);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.common.collect.ImmutableSet;
import com.launchdarkly.sdk.server.DataModelDependencies.KindAndKey;
import com.launchdarkly.sdk.server.interfaces.DataStore;
import com.launchdarkly.sdk.server.interfaces.DataStoreStatusProvider;
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.DataKind;
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.FullDataSet;
import com.launchdarkly.sdk.server.interfaces.DataStoreTypes.ItemDescriptor;
Expand Down Expand Up @@ -32,10 +33,12 @@ final class DataStoreUpdatesImpl implements DataStoreUpdates {
private final DataStore store;
private final FlagChangeEventPublisher flagChangeEventPublisher;
private final DataModelDependencies.DependencyTracker dependencyTracker = new DataModelDependencies.DependencyTracker();

private final DataStoreStatusProvider dataStoreStatusProvider;

DataStoreUpdatesImpl(DataStore store, FlagChangeEventPublisher flagChangeEventPublisher) {
this.store = store;
this.flagChangeEventPublisher = flagChangeEventPublisher;
this.dataStoreStatusProvider = new DataStoreStatusProviderImpl(store);
}

@Override
Expand Down Expand Up @@ -78,6 +81,11 @@ public void upsert(DataKind kind, String key, ItemDescriptor item) {
}
}

@Override
public DataStoreStatusProvider getStatusProvider() {
return dataStoreStatusProvider;
}

private boolean hasFlagChangeEventListeners() {
return flagChangeEventPublisher != null && flagChangeEventPublisher.hasListeners();
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/launchdarkly/sdk/server/FeatureRequestor.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
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;

Expand All @@ -19,5 +31,23 @@ static class AllData {
this.flags = flags;
this.segments = segments;
}

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

static KeyedItems<ItemDescriptor> toKeyedItems(DataKind kind, Map<String, ? extends VersionedData> itemsMap) {
ImmutableList.Builder<Map.Entry<String, ItemDescriptor>> builder = ImmutableList.builder();
if (itemsMap != null) {
for (Map.Entry<String, ? extends VersionedData> 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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Future<Void> start() {
scheduler.scheduleAtFixedRate(() -> {
try {
FeatureRequestor.AllData allData = requestor.getAllData();
dataStoreUpdates.init(DefaultFeatureRequestor.toFullDataSet(allData));
dataStoreUpdates.init(allData.toFullDataSet());
if (!initialized.getAndSet(true)) {
logger.info("Initialized LaunchDarkly client.");
initFuture.set(null);
Expand Down
Loading

0 comments on commit 49cf6df

Please sign in to comment.