Skip to content

Add comprehensive Parameter Store documentation for Java core #2902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
105 changes: 104 additions & 1 deletion docs/server-core/java/_paramStores.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,107 @@
ParameterStore parameterStore = statsig.getParameterStore(user, "my_parameters");
Boolean value = parameterStore.getBoolean("my_parameter_value", false);
System.out.println("Parameter Store value is " + value);
```
```

## Parameter Store

Parameter Store allows you to access configuration parameters with type-safe methods and fallback values.

### Getting a Parameter Store

```java
// Get a Parameter Store by name
ParameterStore parameterStore = statsig.getParameterStore(user, "my_parameter_store");
```

### Retrieving Parameter Values

Parameter Store provides methods for retrieving values of different types with fallback defaults.

```java
// String parameters
String stringValue = parameterStore.getString("string_param", "default_value");

// Boolean parameters
boolean boolValue = parameterStore.getBoolean("bool_param", false);

// Numeric parameters
double doubleValue = parameterStore.getDouble("double_param", 0.0);
int intValue = parameterStore.getInt("int_param", 0);
long longValue = parameterStore.getLong("long_param", 0L);

// Complex parameters
Map<String, Object> defaultMap = new HashMap<>();
defaultMap.put("key", "value");
Map<String, Object> mapValue = parameterStore.getMap("map_param", defaultMap);

Object[] defaultArray = new Object[]{"item1", "item2"};
Object[] arrayValue = parameterStore.getArray("array_param", defaultArray);
```

You can also use the Statsig instance directly:

```java
String stringValue = statsig.getStringFromParameterStore(user, "my_parameter_store", "string_param", "default_value");
```

### Working with Statsig

Here's a complete example showing how to use Parameter Store:

```java
import com.statsig.Statsig;
import com.statsig.StatsigUser;
import com.statsig.ParameterStore;
import java.util.HashMap;
import java.util.Map;

public class ParameterStoreExample {
public static void main(String[] args) {
// Initialize Statsig with your server secret key
Statsig statsig = new Statsig("YOUR_SERVER_SECRET_KEY");
statsig.initialize();

// Create a user
StatsigUser user = new StatsigUser("user-id");
user.setEmail("[email protected]");
user.setCountry("US");

// Get a Parameter Store
ParameterStore parameterStore = statsig.getParameterStore(user, "app_configuration");

// Get different types of parameters with default values
String appName = parameterStore.getString("app_name", "My App");
boolean isDebugMode = parameterStore.getBoolean("debug_mode", false);
int maxRetries = parameterStore.getInt("max_retries", 3);
double timeout = parameterStore.getDouble("timeout_seconds", 30.0);

// Get complex parameters
Map<String, Object> defaultFeatures = new HashMap<>();
defaultFeatures.put("feature_a", true);
defaultFeatures.put("feature_b", false);

Map<String, Object> features = parameterStore.getMap("enabled_features", defaultFeatures);

// Use the parameters in your application
System.out.println("App name: " + appName);
System.out.println("Debug mode: " + isDebugMode);
System.out.println("Max retries: " + maxRetries);
System.out.println("Timeout: " + timeout + " seconds");
System.out.println("Features: " + features);

// Shutdown Statsig when done
statsig.shutdown();
}
}
```

### Best Practices

1. **Provide Sensible Defaults**: Always provide default values that make sense for your application.

2. **Type Safety**: Use the appropriate getter method for the expected parameter type.

3. **Error Handling**: Parameter Store methods handle type mismatches by returning the default value.

4. **Caching**: Parameter Store values are cached locally after retrieval.