Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.android.env.IEnvironmentReporter;
import com.launchdarkly.sdk.android.subsystems.ClientContext;
import com.launchdarkly.sdk.android.subsystems.HttpConfiguration;
import com.launchdarkly.sdk.android.subsystems.DataSourceUpdateSink;
import com.launchdarkly.sdk.android.subsystems.HttpConfiguration;
import com.launchdarkly.sdk.android.subsystems.TransactionalDataStore;
import com.launchdarkly.sdk.internal.events.DiagnosticStore;

import androidx.annotation.Nullable;

/**
* This package-private subclass of {@link ClientContext} contains additional non-public SDK objects
* that may be used by our internal components.
Expand All @@ -33,21 +36,42 @@ final class ClientContextImpl extends ClientContext {
private final PlatformState platformState;
private final TaskExecutor taskExecutor;
private final PersistentDataStoreWrapper.PerEnvironmentData perEnvironmentData;
@Nullable
private final TransactionalDataStore transactionalDataStore;

/** Used by FDv1 code paths that do not need a {@link TransactionalDataStore}. */
ClientContextImpl(
ClientContext base,
DiagnosticStore diagnosticStore,
FeatureFetcher fetcher,
PlatformState platformState,
TaskExecutor taskExecutor,
PersistentDataStoreWrapper.PerEnvironmentData perEnvironmentData
) {
this(base, diagnosticStore, fetcher, platformState, taskExecutor, perEnvironmentData, null);
}

/**
* Used by FDv2 code paths. The {@code transactionalDataStore} is needed by
* {@link FDv2DataSourceBuilder} to create {@link SelectorSourceFacade} instances
* that provide selector state to initializers and synchronizers.
*/
ClientContextImpl(
ClientContext base,
DiagnosticStore diagnosticStore,
FeatureFetcher fetcher,
PlatformState platformState,
TaskExecutor taskExecutor,
PersistentDataStoreWrapper.PerEnvironmentData perEnvironmentData,
@Nullable TransactionalDataStore transactionalDataStore
) {
super(base);
this.diagnosticStore = diagnosticStore;
this.fetcher = fetcher;
this.platformState = platformState;
this.taskExecutor = taskExecutor;
this.perEnvironmentData = perEnvironmentData;
this.transactionalDataStore = transactionalDataStore;
}

static ClientContextImpl fromConfig(
Expand Down Expand Up @@ -95,12 +119,30 @@ public static ClientContextImpl get(ClientContext context) {
return new ClientContextImpl(context, null, null, null, null, null);
}

/** Creates a context for FDv1 data sources that do not need a {@link TransactionalDataStore}. */
public static ClientContextImpl forDataSource(
ClientContext baseClientContext,
DataSourceUpdateSink dataSourceUpdateSink,
LDContext newEvaluationContext,
boolean newInBackground,
Boolean previouslyInBackground
) {
return forDataSource(baseClientContext, dataSourceUpdateSink, newEvaluationContext,
newInBackground, previouslyInBackground, null);
}

/**
* Creates a context for data sources, optionally including a {@link TransactionalDataStore}.
* FDv2 data sources require the store so that {@link FDv2DataSourceBuilder} can provide
* selector state to initializers and synchronizers via {@link SelectorSourceFacade}.
*/
public static ClientContextImpl forDataSource(
ClientContext baseClientContext,
DataSourceUpdateSink dataSourceUpdateSink,
LDContext newEvaluationContext,
boolean newInBackground,
Boolean previouslyInBackground,
@Nullable TransactionalDataStore transactionalDataStore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overloads of forDataSource need comments or perhaps a different name for the latter version to help someone understand the implication of each.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed this in my last push. Is it a problem if the comments directly reference FDv1 and FDv2?

) {
ClientContextImpl baseContextImpl = ClientContextImpl.get(baseClientContext);
return new ClientContextImpl(
Expand All @@ -123,7 +165,8 @@ public static ClientContextImpl forDataSource(
baseContextImpl.getFetcher(),
baseContextImpl.getPlatformState(),
baseContextImpl.getTaskExecutor(),
baseContextImpl.getPerEnvironmentData()
baseContextImpl.getPerEnvironmentData(),
transactionalDataStore
);
}

Expand All @@ -139,7 +182,8 @@ public ClientContextImpl setEvaluationContext(LDContext context) {
this.fetcher,
this.platformState,
this.taskExecutor,
this.perEnvironmentData
this.perEnvironmentData,
this.transactionalDataStore
);
}

Expand All @@ -163,6 +207,11 @@ public PersistentDataStoreWrapper.PerEnvironmentData getPerEnvironmentData() {
return throwExceptionIfNull(perEnvironmentData);
}

@Nullable
public TransactionalDataStore getTransactionalDataStore() {
return transactionalDataStore;
}

private static <T> T throwExceptionIfNull(T o) {
if (o == null) {
throw new IllegalStateException(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.launchdarkly.sdk.android;

/**
* Enumerates the built-in FDv2 connection modes. Each mode maps to a
* {@link ModeDefinition} that specifies which initializers and synchronizers
* are active when the SDK is operating in that mode.
* <p>
* Not to be confused with {@link ConnectionInformation.ConnectionMode}, which
* is the public FDv1 enum representing the SDK's current connection state
* (e.g. POLLING, STREAMING, SET_OFFLINE). This class is an internal FDv2
* concept describing the <em>desired</em> data-acquisition pipeline.
* <p>
* This is a closed enum — custom connection modes (spec 5.3.5 TBD) are not
* supported in this release.
* <p>
* Package-private — not part of the public SDK API.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be worth adding a comment to help distinguish this type from the ConnectionInformation.ConnectionMode. I think we also have to develop a strategy for deprecating / updating the existing ConnectionMode status APIs. We don't have to solve that completely before this merges, but we need to make sure it isn't going to be painful.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed this in my latest push 👍

*
* @see ModeDefinition
* @see ModeResolutionTable
*/
final class ConnectionMode {

static final ConnectionMode STREAMING = new ConnectionMode("streaming");
static final ConnectionMode POLLING = new ConnectionMode("polling");
static final ConnectionMode OFFLINE = new ConnectionMode("offline");
static final ConnectionMode ONE_SHOT = new ConnectionMode("one-shot");
static final ConnectionMode BACKGROUND = new ConnectionMode("background");

private final String name;

private ConnectionMode(String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}
}
Loading
Loading