From 9820f6563d991b631a61fe1be39c5b7cd3bcc154 Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Thu, 7 Sep 2023 18:40:11 -0300 Subject: [PATCH 1/3] Refactor internal filter tracking to use a Map --- .../split/android/client/FilterBuilder.java | 28 +++++++-------- .../split/android/client/FilterGrouper.java | 12 +++++-- .../android/client/SplitFactoryHelper.java | 28 +++++---------- .../android/client/SplitFactoryImpl.java | 10 +++--- .../localhost/LocalhostSplitFactory.java | 10 ++++-- .../executor/SplitTaskFactoryImpl.java | 13 ++++--- .../service/splits/SplitChangeProcessor.java | 6 ++-- .../synchronizer/WorkManagerWrapper.java | 4 +-- .../android/client/FilterGrouperTest.java | 36 ++++++++++++------- .../splits/SplitChangeProcessorTest.java | 5 +-- 10 files changed, 84 insertions(+), 68 deletions(-) diff --git a/src/main/java/io/split/android/client/FilterBuilder.java b/src/main/java/io/split/android/client/FilterBuilder.java index 335fcb841..88d1cd5c2 100644 --- a/src/main/java/io/split/android/client/FilterBuilder.java +++ b/src/main/java/io/split/android/client/FilterBuilder.java @@ -6,14 +6,14 @@ import androidx.annotation.Nullable; import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Map; import java.util.SortedSet; +import java.util.TreeMap; import java.util.TreeSet; import io.split.android.client.utils.logger.Logger; -import io.split.android.client.utils.StringHelper; public class FilterBuilder { @@ -30,18 +30,15 @@ public FilterBuilder(List filters) { } public String buildQueryString() { - - if (mFilters.size() == 0) { + if (mFilters.isEmpty()) { return ""; } - StringHelper stringHelper = new StringHelper(); StringBuilder queryString = new StringBuilder(); - List sortedFilters = getGroupedFilter(); - Collections.sort(sortedFilters, new SplitFilterComparator()); + Map sortedFilters = getGroupedFilter(); - for (SplitFilter splitFilter : sortedFilters) { + for (SplitFilter splitFilter : sortedFilters.values()) { SplitFilter.Type filterType = splitFilter.getType(); SortedSet deduptedValues = new TreeSet<>(splitFilter.getValues()); if (deduptedValues.size() < splitFilter.getValues().size()) { @@ -56,15 +53,18 @@ public String buildQueryString() { queryString.append("&"); queryString.append(filterType.queryStringField()); queryString.append("="); - queryString.append(stringHelper.join(",", deduptedValues)); + queryString.append(String.join(",", deduptedValues)); } return queryString.toString(); } @NonNull - public List getGroupedFilter() { - return new ArrayList<>(mFilterGrouper.group(mFilters)); + public Map getGroupedFilter() { + TreeMap sortedFilters = new TreeMap<>(new SplitFilterTypeComparator()); + sortedFilters.putAll(mFilterGrouper.group(mFilters)); + + return sortedFilters; } private void addFilters(List filters) { @@ -103,10 +103,10 @@ private void validateFilterSize(SplitFilter.Type type, int size) { } } - private static class SplitFilterComparator implements Comparator { + private static class SplitFilterTypeComparator implements Comparator { @Override - public int compare(SplitFilter o1, SplitFilter o2) { - return o1.getType().compareTo(o2.getType()); + public int compare(SplitFilter.Type o1, SplitFilter.Type o2) { + return o1.compareTo(o2); } } } diff --git a/src/main/java/io/split/android/client/FilterGrouper.java b/src/main/java/io/split/android/client/FilterGrouper.java index 6e5e39fbb..7b9f52746 100644 --- a/src/main/java/io/split/android/client/FilterGrouper.java +++ b/src/main/java/io/split/android/client/FilterGrouper.java @@ -7,7 +7,12 @@ class FilterGrouper { - List group(List filters) { + /** + * Groups filters by type + * @param filters list of filters to group + * @return map of grouped filters. The key is the filter type, the value is the filter + */ + Map group(List filters) { Map> groupedValues = new HashMap<>(); for (SplitFilter filter : filters) { List groupValues = groupedValues.get(filter.getType()); @@ -18,12 +23,13 @@ List group(List filters) { groupValues.addAll(filter.getValues()); } - List groupedFilters = new ArrayList<>(); + Map groupedFilters = new HashMap<>(); for (Map.Entry> filterEntry : groupedValues.entrySet()) { if (filterEntry.getValue().size() > 0) { - groupedFilters.add(new SplitFilter(filterEntry.getKey(), filterEntry.getValue())); + groupedFilters.put(filterEntry.getKey(), new SplitFilter(filterEntry.getKey(), filterEntry.getValue())); } } + return groupedFilters; } } diff --git a/src/main/java/io/split/android/client/SplitFactoryHelper.java b/src/main/java/io/split/android/client/SplitFactoryHelper.java index 83cb7a841..6541a05e7 100644 --- a/src/main/java/io/split/android/client/SplitFactoryHelper.java +++ b/src/main/java/io/split/android/client/SplitFactoryHelper.java @@ -10,11 +10,8 @@ import java.io.File; import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; +import java.util.HashMap; import java.util.Map; -import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingDeque; @@ -189,9 +186,12 @@ SplitApiFacade buildApiFacade(SplitClientConfig splitClientConfig, } WorkManagerWrapper buildWorkManagerWrapper(Context context, SplitClientConfig splitClientConfig, - String apiKey, String databaseName, List filters) { + String apiKey, String databaseName, Map filters) { + SplitFilter filter = filters.get(SplitFilter.Type.BY_SET) != null ? + filters.get(SplitFilter.Type.BY_SET) : + filters.get(SplitFilter.Type.BY_NAME); return new WorkManagerWrapper( - WorkManager.getInstance(context), splitClientConfig, apiKey, databaseName, filters); + WorkManager.getInstance(context), splitClientConfig, apiKey, databaseName, filter); } @@ -414,27 +414,17 @@ SplitUpdatesWorker getSplitUpdatesWorker(SplitClientConfig config, return null; } - Pair, String>, Set> getFilterConfiguration(SyncConfig syncConfig) { + Pair, String> getFilterConfiguration(SyncConfig syncConfig) { String splitsFilterQueryString = null; - List groupedFilters = new ArrayList<>(); - Set configuredFlagSets = new HashSet<>(); + Map groupedFilters = new HashMap<>(); if (syncConfig != null) { FilterBuilder filterBuilder = new FilterBuilder(syncConfig.getFilters()); groupedFilters = filterBuilder.getGroupedFilter(); splitsFilterQueryString = filterBuilder.buildQueryString(); - - if (!groupedFilters.isEmpty()) { - SplitFilter splitFilter = groupedFilters.get(0); - - // In the case of BY_SET, all filters will be grouped into one with the {@link SplitFilter.Type#BY_SET} type - if (splitFilter != null && splitFilter.getType() == SplitFilter.Type.BY_SET) { - configuredFlagSets.addAll(splitFilter.getValues()); - } - } } - return new Pair<>(new Pair<>(groupedFilters, splitsFilterQueryString), configuredFlagSets); + return new Pair<>(groupedFilters, splitsFilterQueryString); } private TelemetryStorage getTelemetryStorage(boolean shouldRecordTelemetry, TelemetryStorage telemetryStorage) { diff --git a/src/main/java/io/split/android/client/SplitFactoryImpl.java b/src/main/java/io/split/android/client/SplitFactoryImpl.java index af1cecedc..a6b3421c7 100644 --- a/src/main/java/io/split/android/client/SplitFactoryImpl.java +++ b/src/main/java/io/split/android/client/SplitFactoryImpl.java @@ -7,7 +7,9 @@ import java.net.URISyntaxException; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import io.split.android.client.api.Key; @@ -171,10 +173,10 @@ public void taskExecuted(@NonNull SplitTaskExecutionInfo taskInfo) { mStorageContainer = factoryHelper.buildStorageContainer(config.userConsent(), splitDatabase, config.shouldRecordTelemetry(), splitCipher, telemetryStorage); - Pair, String>, Set> filtersConfig = factoryHelper.getFilterConfiguration(config.syncConfig()); - List filters = filtersConfig.first.first; - String splitsFilterQueryStringFromConfig = filtersConfig.first.second; - Set configuredFlagSets = filtersConfig.second; + Pair, String> filtersConfig = factoryHelper.getFilterConfiguration(config.syncConfig()); + Map filters = filtersConfig.first; + String splitsFilterQueryStringFromConfig = filtersConfig.second; + Set configuredFlagSets = (filters.get(SplitFilter.Type.BY_SET) != null) ? new HashSet<>(filters.get(SplitFilter.Type.BY_SET).getValues()) : new HashSet<>(); SplitApiFacade splitApiFacade = factoryHelper.buildApiFacade( config, defaultHttpClient, splitsFilterQueryStringFromConfig); diff --git a/src/main/java/io/split/android/client/localhost/LocalhostSplitFactory.java b/src/main/java/io/split/android/client/localhost/LocalhostSplitFactory.java index de3efad14..1f79f0e8d 100644 --- a/src/main/java/io/split/android/client/localhost/LocalhostSplitFactory.java +++ b/src/main/java/io/split/android/client/localhost/LocalhostSplitFactory.java @@ -9,6 +9,7 @@ import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import io.split.android.client.FilterBuilder; @@ -76,11 +77,14 @@ public LocalhostSplitFactory(String key, Context context, Set configuredSets = new HashSet<>(); if (config.syncConfig() != null) { - List groupedFilters = new FilterBuilder(config.syncConfig().getFilters()) + Map groupedFilters = new FilterBuilder(config.syncConfig().getFilters()) .getGroupedFilter(); - if (!groupedFilters.isEmpty() && groupedFilters.get(0) != null && groupedFilters.get(0).getType() == SplitFilter.Type.BY_SET) { - configuredSets.addAll(groupedFilters.get(0).getValues()); + if (!groupedFilters.isEmpty()) { + SplitFilter bySetFilter = groupedFilters.get(SplitFilter.Type.BY_SET); + if (bySetFilter != null) { + configuredSets.addAll(bySetFilter.getValues()); + } } } diff --git a/src/main/java/io/split/android/client/service/executor/SplitTaskFactoryImpl.java b/src/main/java/io/split/android/client/service/executor/SplitTaskFactoryImpl.java index e828a1cdb..8df128d86 100644 --- a/src/main/java/io/split/android/client/service/executor/SplitTaskFactoryImpl.java +++ b/src/main/java/io/split/android/client/service/executor/SplitTaskFactoryImpl.java @@ -66,7 +66,7 @@ public SplitTaskFactoryImpl(@NonNull SplitClientConfig splitClientConfig, @NonNull SplitStorageContainer splitStorageContainer, @Nullable String splitsFilterQueryString, ISplitEventsManager eventsManager, - @Nullable List filters, + @Nullable Map filters, @Nullable TestingConfig testingConfig) { mSplitClientConfig = checkNotNull(splitClientConfig); @@ -91,13 +91,16 @@ public SplitTaskFactoryImpl(@NonNull SplitClientConfig splitClientConfig, mTelemetryRuntimeProducer); } - mFilters = (filters == null) ? new ArrayList<>() : filters; + mFilters = (filters == null) ? new ArrayList<>() : new ArrayList<>(filters.values()); int flagSetCount = 0; int invalidFlagSetCount = 0; - if (!mFilters.isEmpty() && mFilters.get(0) != null && mFilters.get(0).getType() == SplitFilter.Type.BY_SET) { - flagSetCount = mFilters.get(0).getValues().size(); - invalidFlagSetCount = mFilters.get(0).getInvalidValueCount(); + if (filters != null && !filters.isEmpty()) { + SplitFilter bySetFilter = filters.get(SplitFilter.Type.BY_SET); + if (bySetFilter != null) { + flagSetCount = bySetFilter.getValues().size(); + invalidFlagSetCount = bySetFilter.getInvalidValueCount(); + } } mTelemetryTaskFactory = new TelemetryTaskFactoryImpl(mSplitApiFacade.getTelemetryConfigRecorder(), diff --git a/src/main/java/io/split/android/client/service/splits/SplitChangeProcessor.java b/src/main/java/io/split/android/client/service/splits/SplitChangeProcessor.java index b709beb68..e92ea1bf9 100644 --- a/src/main/java/io/split/android/client/service/splits/SplitChangeProcessor.java +++ b/src/main/java/io/split/android/client/service/splits/SplitChangeProcessor.java @@ -7,11 +7,11 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; import io.split.android.client.SplitFilter; import io.split.android.client.dtos.Split; import io.split.android.client.dtos.SplitChange; -import io.split.android.client.dtos.Status; import io.split.android.client.storage.splits.ProcessedSplitChange; public class SplitChangeProcessor { @@ -25,12 +25,12 @@ public class SplitChangeProcessor { this((SplitFilter) null); } - public SplitChangeProcessor(@Nullable List filters) { + public SplitChangeProcessor(@Nullable Map filters) { // We're only supporting one filter type if (filters == null || filters.isEmpty()) { mSplitFilter = null; } else { - mSplitFilter = filters.get(0); + mSplitFilter = filters.values().iterator().next(); } mStatusProcessStrategy = new StatusProcessStrategy(); diff --git a/src/main/java/io/split/android/client/service/synchronizer/WorkManagerWrapper.java b/src/main/java/io/split/android/client/service/synchronizer/WorkManagerWrapper.java index b2beb4b08..8a255706e 100644 --- a/src/main/java/io/split/android/client/service/synchronizer/WorkManagerWrapper.java +++ b/src/main/java/io/split/android/client/service/synchronizer/WorkManagerWrapper.java @@ -53,14 +53,14 @@ public WorkManagerWrapper(@NonNull WorkManager workManager, @NonNull SplitClientConfig splitClientConfig, @NonNull String apiKey, @NonNull String databaseName, - @Nullable List filters) { + @Nullable SplitFilter filter) { mWorkManager = checkNotNull(workManager); mDatabaseName = checkNotNull(databaseName); mSplitClientConfig = checkNotNull(splitClientConfig); mApiKey = checkNotNull(apiKey); mShouldLoadFromLocal = new HashSet<>(); mConstraints = buildConstraints(); - mFilter = (filters != null && filters.size() == 1) ? filters.get(0) : null; + mFilter = filter; } public void setFetcherExecutionListener(SplitTaskExecutionListener fetcherExecutionListener) { diff --git a/src/test/java/io/split/android/client/FilterGrouperTest.java b/src/test/java/io/split/android/client/FilterGrouperTest.java index c5b5e6868..e3a7fbcec 100644 --- a/src/test/java/io/split/android/client/FilterGrouperTest.java +++ b/src/test/java/io/split/android/client/FilterGrouperTest.java @@ -1,11 +1,16 @@ package io.split.android.client; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; public class FilterGrouperTest { @@ -13,18 +18,23 @@ public class FilterGrouperTest { @Test public void groupingFilters() { - List ungropedFilters = new ArrayList<>(); - ungropedFilters.add(SplitFilter.byName(Arrays.asList("f1", "f2", "f3"))); - ungropedFilters.add(SplitFilter.byName(Arrays.asList("f2", "f3", "f4"))); - ungropedFilters.add(SplitFilter.byName(Arrays.asList("f4", "f5", "f6"))); - ungropedFilters.add(SplitFilter.byPrefix(Arrays.asList("f1", "f2", "f3"))); - ungropedFilters.add(SplitFilter.byPrefix(Arrays.asList("f2", "f3", "f4"))); - ungropedFilters.add(SplitFilter.byPrefix(Arrays.asList("f4", "f5", "f6"))); - - List groupedFiltes = mFilterGrouper.group(ungropedFilters); - - /// This compoe - Assert.assertEquals(2, groupedFiltes.size()); + List ungroupedFilters = new ArrayList<>(); + ungroupedFilters.add(SplitFilter.byName(Arrays.asList("f1", "f2", "f3"))); + ungroupedFilters.add(SplitFilter.byName(Arrays.asList("f2", "f3", "f4"))); + ungroupedFilters.add(SplitFilter.byName(Arrays.asList("f4", "f5", "f6"))); + ungroupedFilters.add(SplitFilter.byPrefix(Arrays.asList("f1", "f2", "f3"))); + ungroupedFilters.add(SplitFilter.byPrefix(Arrays.asList("f2", "f3", "f4"))); + ungroupedFilters.add(SplitFilter.byPrefix(Arrays.asList("f4", "f5", "f6"))); + ungroupedFilters.add(SplitFilter.bySet(Arrays.asList("f1", "f2", "f3"))); + ungroupedFilters.add(SplitFilter.bySet(Arrays.asList("f2", "f3", "f4"))); + ungroupedFilters.add(SplitFilter.bySet(Arrays.asList("f4", "f5", "f6"))); + + Map groupedFilters = mFilterGrouper.group(ungroupedFilters); + + // this class only merges filters of the same type + assertEquals(3, groupedFilters.size()); + assertTrue(groupedFilters.containsKey(SplitFilter.Type.BY_NAME)); + assertTrue(groupedFilters.containsKey(SplitFilter.Type.BY_PREFIX)); + assertTrue(groupedFilters.containsKey(SplitFilter.Type.BY_SET)); } - } diff --git a/src/test/java/io/split/android/client/service/splits/SplitChangeProcessorTest.java b/src/test/java/io/split/android/client/service/splits/SplitChangeProcessorTest.java index a2830c7ef..237228a61 100644 --- a/src/test/java/io/split/android/client/service/splits/SplitChangeProcessorTest.java +++ b/src/test/java/io/split/android/client/service/splits/SplitChangeProcessorTest.java @@ -11,6 +11,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import io.split.android.client.SplitFilter; @@ -206,8 +207,8 @@ public void featureFlagsAreFilteredByNameWhenThereIsSplitFilterByName() { @Test public void creatingWithNullFilterProcessesEverything() { - List filterList = null; - mProcessor = new SplitChangeProcessor(filterList); + Map filterMap = null; + mProcessor = new SplitChangeProcessor(filterMap); Split split1 = newSplit("split_1", Status.ACTIVE); Split split2 = newSplit("split_2", Status.ARCHIVED); From 0b9f11619483969a02fe2318a3c8b594cb0abb3e Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Thu, 7 Sep 2023 18:47:37 -0300 Subject: [PATCH 2/3] Fix test --- .../client/service/synchronizer/WorkManagerWrapperTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/split/android/client/service/synchronizer/WorkManagerWrapperTest.java b/src/test/java/io/split/android/client/service/synchronizer/WorkManagerWrapperTest.java index a79498fa4..edfbd899e 100644 --- a/src/test/java/io/split/android/client/service/synchronizer/WorkManagerWrapperTest.java +++ b/src/test/java/io/split/android/client/service/synchronizer/WorkManagerWrapperTest.java @@ -73,7 +73,7 @@ public void setUp() throws Exception { splitClientConfig, "api_key", "test_database_name", - Collections.singletonList(SplitFilter.bySet(Arrays.asList("set_1", "set_2"))) + SplitFilter.bySet(Arrays.asList("set_1", "set_2")) ); } From 13cae88fbc3c13febfb9717df5e3fe21479ed1f2 Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Fri, 8 Sep 2023 10:24:00 -0300 Subject: [PATCH 3/3] Cleanup --- .../android/client/SplitFactoryHelper.java | 14 ++++++ .../android/client/SplitFactoryImpl.java | 3 +- .../executor/SplitTaskFactoryImpl.java | 44 +++++++++++-------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/src/main/java/io/split/android/client/SplitFactoryHelper.java b/src/main/java/io/split/android/client/SplitFactoryHelper.java index 6541a05e7..399a8740a 100644 --- a/src/main/java/io/split/android/client/SplitFactoryHelper.java +++ b/src/main/java/io/split/android/client/SplitFactoryHelper.java @@ -11,7 +11,9 @@ import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingDeque; @@ -427,6 +429,18 @@ Pair, String> getFilterConfiguration(SyncConf return new Pair<>(groupedFilters, splitsFilterQueryString); } + @NonNull + Set getConfiguredFlagSets(Map filters) { + Set configuredFlagSets; + SplitFilter flagSetSplitFilter = filters.get(SplitFilter.Type.BY_SET); + if (flagSetSplitFilter != null) { + configuredFlagSets = new HashSet<>(flagSetSplitFilter.getValues()); + } else { + configuredFlagSets = new HashSet<>(); + } + return configuredFlagSets; + } + private TelemetryStorage getTelemetryStorage(boolean shouldRecordTelemetry, TelemetryStorage telemetryStorage) { if (telemetryStorage != null) { return telemetryStorage; diff --git a/src/main/java/io/split/android/client/SplitFactoryImpl.java b/src/main/java/io/split/android/client/SplitFactoryImpl.java index a6b3421c7..c387d9d55 100644 --- a/src/main/java/io/split/android/client/SplitFactoryImpl.java +++ b/src/main/java/io/split/android/client/SplitFactoryImpl.java @@ -176,7 +176,6 @@ public void taskExecuted(@NonNull SplitTaskExecutionInfo taskInfo) { Pair, String> filtersConfig = factoryHelper.getFilterConfiguration(config.syncConfig()); Map filters = filtersConfig.first; String splitsFilterQueryStringFromConfig = filtersConfig.second; - Set configuredFlagSets = (filters.get(SplitFilter.Type.BY_SET) != null) ? new HashSet<>(filters.get(SplitFilter.Type.BY_SET).getValues()) : new HashSet<>(); SplitApiFacade splitApiFacade = factoryHelper.buildApiFacade( config, defaultHttpClient, splitsFilterQueryStringFromConfig); @@ -271,7 +270,7 @@ public void taskExecuted(@NonNull SplitTaskExecutionInfo taskInfo) { telemetrySynchronizer, mStorageContainer, splitTaskExecutor, splitApiFacade, validationLogger, keyValidator, customerImpressionListener, streamingComponents.getPushNotificationManager(), componentsRegister, workManagerWrapper, - eventsTracker, configuredFlagSets); + eventsTracker, factoryHelper.getConfiguredFlagSets(filters)); mDestroyer = new Runnable() { public void run() { Logger.w("Shutdown called for split"); diff --git a/src/main/java/io/split/android/client/service/executor/SplitTaskFactoryImpl.java b/src/main/java/io/split/android/client/service/executor/SplitTaskFactoryImpl.java index 8df128d86..e91cd8c3a 100644 --- a/src/main/java/io/split/android/client/service/executor/SplitTaskFactoryImpl.java +++ b/src/main/java/io/split/android/client/service/executor/SplitTaskFactoryImpl.java @@ -92,25 +92,7 @@ public SplitTaskFactoryImpl(@NonNull SplitClientConfig splitClientConfig, } mFilters = (filters == null) ? new ArrayList<>() : new ArrayList<>(filters.values()); - - int flagSetCount = 0; - int invalidFlagSetCount = 0; - if (filters != null && !filters.isEmpty()) { - SplitFilter bySetFilter = filters.get(SplitFilter.Type.BY_SET); - if (bySetFilter != null) { - flagSetCount = bySetFilter.getValues().size(); - invalidFlagSetCount = bySetFilter.getInvalidValueCount(); - } - } - - mTelemetryTaskFactory = new TelemetryTaskFactoryImpl(mSplitApiFacade.getTelemetryConfigRecorder(), - mSplitApiFacade.getTelemetryStatsRecorder(), - telemetryStorage, - splitClientConfig, - mSplitsStorageContainer.getSplitsStorage(), - mSplitsStorageContainer.getMySegmentsStorageContainer(), - flagSetCount, - invalidFlagSetCount); + mTelemetryTaskFactory = initializeTelemetryTaskFactory(splitClientConfig, filters, telemetryStorage); } @Override @@ -212,4 +194,28 @@ public TelemetryStatsRecorderTask getTelemetryStatsRecorderTask() { public SplitInPlaceUpdateTask createSplitsUpdateTask(Split featureFlag, long since) { return new SplitInPlaceUpdateTask(mSplitsStorageContainer.getSplitsStorage(), mSplitChangeProcessor, mEventsManager, mTelemetryRuntimeProducer, featureFlag, since); } + + @NonNull + private TelemetryTaskFactory initializeTelemetryTaskFactory(@NonNull SplitClientConfig splitClientConfig, @Nullable Map filters, TelemetryStorage telemetryStorage) { + final TelemetryTaskFactory mTelemetryTaskFactory; + int flagSetCount = 0; + int invalidFlagSetCount = 0; + if (filters != null && !filters.isEmpty()) { + SplitFilter bySetFilter = filters.get(SplitFilter.Type.BY_SET); + if (bySetFilter != null) { + flagSetCount = bySetFilter.getValues().size(); + invalidFlagSetCount = bySetFilter.getInvalidValueCount(); + } + } + + mTelemetryTaskFactory = new TelemetryTaskFactoryImpl(mSplitApiFacade.getTelemetryConfigRecorder(), + mSplitApiFacade.getTelemetryStatsRecorder(), + telemetryStorage, + splitClientConfig, + mSplitsStorageContainer.getSplitsStorage(), + mSplitsStorageContainer.getMySegmentsStorageContainer(), + flagSetCount, + invalidFlagSetCount); + return mTelemetryTaskFactory; + } }