> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/feature-management-experimentation/new-to-fme/sdks-and-customer-deployed-components/server-side-configs-sdks/java-sdk.md). Agents can also search and read this documentation through its [MCP server](https://developer.harness.io/~gitbook/mcp).

# Java Configs SDK

Use the Harness FME Java Configs SDK to serve standalone, versioned configuration objects in Java and Kotlin applications.

This guide provides detailed information about our Java Configs SDK. The SDK serves Configs: standalone, versioned configuration objects that you manage independently from feature flags. Configs can be evaluated with or without targeting rules and are well suited for use cases such as AI prompts, model parameters, and other application configuration that benefits from governed, versioned management. Go to our [Java Configs SDK GitHub repository](https://github.com/splitio/java-configs-client) to learn more.

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

The Java Configs SDK supports JDK 8 and later.

### Initialization <a href="#initialization" id="initialization"></a>

Set up the Java Configs SDK in your code base with two simple steps.

#### 1. Import the SDK into your project <a href="#id-1-import-the-sdk-into-your-project" id="id-1-import-the-sdk-into-your-project"></a>

Import the SDK into your project using one of the following methods:

{% tabs %}
{% tab title="Maven" %}

```xml
<dependency>
    <groupId>io.split</groupId>
    <artifactId>configs-java</artifactId>
    <version>1.0.0-beta1</version>
</dependency>
```

{% endtab %}

{% tab title="Gradle" %}

```groovy
implementation 'io.split:configs-java:1.0.0-beta1'
```

{% endtab %}
{% endtabs %}

#### 2. Instantiate the SDK and create a new client <a href="#id-2-instantiate-the-sdk-and-create-a-new-client" id="id-2-instantiate-the-sdk-and-create-a-new-client"></a>

{% tabs %}
{% tab title="Java" %}

```java
import io.split.configs.ConfigsClient;

ConfigsClient client = ConfigsClient.build("YOUR_SDK_KEY");
try {
    client.blockUntilReady();
} catch (TimeoutException | InterruptedException e) {
    // log & handle
}
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import io.split.configs.ConfigsClient

val client = ConfigsClient.build("YOUR_SDK_KEY")
try {
    client.blockUntilReady()
} catch (e: Exception) {
    // log & handle
}
```

{% endtab %}
{% endtabs %}

We recommend instantiating the client once as a singleton and reusing it throughout your application.

Configure the SDK with the SDK key for the FME environment that you would like to access. Go to [API keys](https://developer.harness.io/feature-management-experimentation/management-and-administration/api-keys.md) to learn how to retrieve a server-side SDK key.

### Use the SDK <a href="#use-the-sdk" id="use-the-sdk"></a>

#### Basic use <a href="#basic-use" id="basic-use"></a>

When the SDK is instantiated, it kicks off background jobs to update an in-memory cache with config definitions fetched from Harness servers. While the SDK is in this intermediate state, if it is asked to evaluate a config, it does not fail. Instead, it returns a fallback config or, if no fallback is configured, a `Config` with `variant` equal to `"control"` and an empty `value` (`{}`).

To make sure the SDK has loaded the latest definitions before evaluating, call `blockUntilReady()` before calling `getConfig`. If the SDK is not ready within the configured `readyTimeout`, a `TimeoutException` is thrown.

The `getConfig` method returns a `Config` object with two properties:

* **`variant()`:** The string name of the resolved variant.
* **`value()`:** The raw JSON object (as a `Map<String, Object>`) associated with that variant.

If you do not pass a target, the SDK returns the default variant of the config. If you pass a target, the SDK evaluates the config's targeting rules against that target.

{% tabs %}
{% tab title="Java" %}

```java
import io.split.configs.Config;
import io.split.configs.Target;

// Without target: returns the default variant of the config
Config defaultConfig = client.getConfig("CONFIG_NAME");
System.out.println(defaultConfig.variant()); // "v1"
System.out.println(defaultConfig.value());   // {prompt=Hello world, temperature=0.5}

// With target: evaluates targeting rules for the given key
Config config = client.getConfig("CONFIG_NAME", new Target("user-123"));
System.out.println(config.variant());
System.out.println(config.value());
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import io.split.configs.Config
import io.split.configs.Target

// Without target: returns the default variant of the config
val defaultConfig: Config = client.getConfig("CONFIG_NAME")
println(defaultConfig.variant()) // "v1"
println(defaultConfig.value())   // {prompt=Hello world, temperature=0.5}

// With target: evaluates targeting rules for the given key
val config = client.getConfig("CONFIG_NAME", Target("user-123"))
println(config.variant())
println(config.value())
```

{% endtab %}
{% endtabs %}

If a config cannot be evaluated, the SDK returns the fallback config value: default `Config` with `variant` `"control"` and empty object `value`, unless overridden globally or per config. Go to [Configure fallback configs](#configure-fallback-configs) to learn more.

#### Attribute syntax <a href="#attribute-syntax" id="attribute-syntax"></a>

To [target based on custom attributes](https://developer.harness.io/feature-management-experimentation/use-fme/feature-management/targeting/target-with-custom-attributes.md), pass a `Target` object with a `key` and an `attributes` map to the `getConfig` method.

In the example below, we evaluate a config for a user. The provided attributes `plan_type`, `registered_date`, `permissions`, `paying_customer`, and `deal_size` are passed to the `getConfig` call. These attributes are compared and evaluated against the targeting rules defined for the config in Harness FME to decide which variant to resolve.

The supported attribute types are: strings, numbers, dates, booleans, and sets. The proper data type and syntax for each are:

* **Strings:** Use type `String`.
* **Numbers:** Use type `Long` or `Integer`.
* **Dates:** Express the value in `milliseconds since epoch`. Use type `Long`.
* **Booleans:** Use type `Boolean`.
* **Sets:** Use type `Collection`.

{% tabs %}
{% tab title="Java" %}

```java
import io.split.configs.Config;
import io.split.configs.Target;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

Map<String, Object> attributes = new HashMap<>();
attributes.put("plan_type", "growth");
attributes.put("registered_date", System.currentTimeMillis());
attributes.put("deal_size", 10000);
attributes.put("paying_customer", true);
attributes.put("permissions", Arrays.asList("read", "write"));

Target target = new Target("user-123", attributes);
Config config = client.getConfig("CONFIG_NAME", target);
System.out.println(config.variant());
System.out.println(config.value());
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import io.split.configs.Config
import io.split.configs.Target

val attributes = mapOf(
    "plan_type" to "growth",
    "registered_date" to System.currentTimeMillis(),
    "deal_size" to 10000,
    "paying_customer" to true,
    "permissions" to listOf("read", "write")
)

val target = Target("user-123", attributes)
val config = client.getConfig("CONFIG_NAME", target)
println(config.variant())
println(config.value())
```

{% endtab %}
{% endtabs %}

#### Append properties to impressions <a href="#append-properties-to-impressions" id="append-properties-to-impressions"></a>

[Impressions](https://developer.harness.io/feature-management-experimentation/use-fme/feature-management/monitoring-and-analysis/impressions.md) are generated by the SDK each time a `getConfig` method is called with a target. These impressions are periodically sent back to Harness servers for feature monitoring and experimentation.

You can append properties to an impression by passing an `EvaluationOptions` object to the `getConfig` method. These properties are then included in the impression sent by the SDK and can provide useful context to the impression data.

Three types of properties are supported: strings, numbers, and booleans.

{% tabs %}
{% tab title="Java" %}

```java
import io.split.configs.EvaluationOptions;
import io.split.configs.Target;

Map<String, Object> properties = new HashMap<>();
properties.put("package", "premium");
properties.put("admin", true);
properties.put("discount", 50);

EvaluationOptions evaluationOptions = new EvaluationOptions(properties);
Config config = client.getConfig("CONFIG_NAME", new Target("user-123"), evaluationOptions);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import io.split.configs.EvaluationOptions
import io.split.configs.Target

val properties = mapOf<String, Any>(
    "package" to "premium",
    "admin" to true,
    "discount" to 50
)

val evaluationOptions = EvaluationOptions(properties)
val config = client.getConfig("CONFIG_NAME", Target("user-123"), evaluationOptions)
```

{% endtab %}
{% endtabs %}

#### Shutdown <a href="#shutdown" id="shutdown"></a>

Call the `client.destroy()` method before letting a process using the SDK exit, as this method gracefully shuts down the SDK by stopping all background sync jobs, clearing caches, closing connections, and flushing any remaining unpublished events and impressions.

{% tabs %}
{% tab title="Java" %}

```java
client.destroy();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
client.destroy()
```

{% endtab %}
{% endtabs %}

After `destroy()` is called, any subsequent invocations to `getConfig` return the fallback config or, if no fallback is configured, a `Config` with `variant` `"control"` and empty object `value`.

### Track <a href="#track" id="track"></a>

Use the `track` method to record any actions your customers perform. Each action is known as an `event` and corresponds to an `event type`. Calling `track` through one of our SDKs or via the API allows you to measure the impact of your configs on your users' actions and metrics.

Go to [Events](https://developer.harness.io/feature-management-experimentation/use-fme/release-monitoring/events.md) to learn more about using track events in features.

In the examples below, you can see that the `track` method can take up to five arguments. The proper data type and syntax for each are:

* **key:** The key that identifies the entity related to this event. The expected data type is **String**.
* **TRAFFIC\_TYPE:** The traffic type of the key in the track call. The expected data type is **String**. Go to [traffic types](https://developer.harness.io/feature-management-experimentation/management-and-administration/traffic-types.md) to learn more.
* **EVENT\_TYPE:** The event type that this event should correspond to. The expected data type is **String**. Full requirements on this argument are:
  * Contains 63 characters or fewer.
  * Starts with a letter or number.
  * Contains only letters, numbers, hyphen, underscore, or period.
  * This is the regular expression we use to validate the value: `[a-zA-Z0-9][-_\.a-zA-Z0-9]{0,62}`
* **VALUE:** (Optional) The value to be used in creating the metric. This field can be sent as null or 0 if you intend to purely use the count function when creating a metric. The expected data type is **Double**.
* **PROPERTIES:** (Optional) A map of key-value pairs that can be used to filter your metrics. Go to [Event properties](https://developer.harness.io/feature-management-experimentation/use-fme/release-monitoring/events.md#event-properties) to learn more. FME currently supports three types of properties: strings, numbers, and booleans.

The `track` method returns a boolean value of `true` or `false` to indicate whether the SDK was able to successfully queue the event to be sent back to Harness servers on the next event post. The SDK returns `false` if an incorrect input has been provided.

{% tabs %}
{% tab title="Java" %}

```java
// If you would like to send an event without a value
boolean queued = client.track("key", "TRAFFIC_TYPE", "EVENT_TYPE", null, null);

// Example
queued = client.track("john@doe.com", "user", "page_load_time", null, null);

// If you would like to associate a value with an event
queued = client.track("key", "TRAFFIC_TYPE", "EVENT_TYPE", 83.334, null);

// Example
queued = client.track("john@doe.com", "user", "page_load_time", 83.334, null);

// If you would like to associate a value and properties with an event
Map<String, Object> properties = new HashMap<>();
properties.put("package", "premium");
properties.put("admin", true);
properties.put("discount", 50);
queued = client.track("john@doe.com", "user", "page_load_time", 83.334, properties);

// If you would like to associate only properties with an event
queued = client.track("john@doe.com", "user", "page_load_time", null, properties);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
// If you would like to send an event without a value
var queued = client.track("key", "TRAFFIC_TYPE", "EVENT_TYPE", null, null)

// Example
queued = client.track("john@doe.com", "user", "page_load_time", null, null)

// If you would like to associate a value with an event
queued = client.track("key", "TRAFFIC_TYPE", "EVENT_TYPE", 83.334, null)

// Example
queued = client.track("john@doe.com", "user", "page_load_time", 83.334, null)

// If you would like to associate a value and properties with an event
val properties = mapOf<String, Any>(
    "package" to "premium",
    "admin" to true,
    "discount" to 50
)
queued = client.track("john@doe.com", "user", "page_load_time", 83.334, properties)

// If you would like to associate only properties with an event
queued = client.track("john@doe.com", "user", "page_load_time", null, properties)
```

{% endtab %}
{% endtabs %}

### Configuration <a href="#configuration" id="configuration"></a>

The SDK has a number of knobs for configuring performance. Each knob is tuned to a reasonable default. However, you can override the value while instantiating the SDK. The parameters available for configuration are shown below.

| **Configuration**  | **Description**                                                                                                                                                             | **Default value** |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- |
| `pollingRate`      | How often, in seconds, the SDK polls for config and segment updates. Minimum value: `5`.                                                                                    | `60`              |
| `pushRate`         | How often, in seconds, the SDK flushes queued events and impressions. Minimum value: `60`.                                                                                  | `60`              |
| `queueSize`        | Maximum number of events or impressions queued in memory before a forced flush. Minimum value: `1000`.                                                                      | `10000`           |
| `logLevel`         | Logging level. Acceptable values are `NONE`, `ERROR`, `WARN`, `INFO`, and `DEBUG`.                                                                                          | `NONE`            |
| `readyTimeout`     | Time in seconds before `blockUntilReady()` throws a `TimeoutException`. Use `-1` to wait indefinitely.                                                                      | `10`              |
| `serviceEndpoints` | Override the base URLs for config, events, and auth requests. Go to [Service endpoints](#service-endpoints) to learn more.                                                  | See below         |
| `fallbackConfigs`  | Fallback configs returned when evaluation fails or the requested config name does not exist. Go to [Configure fallback configs](#configure-fallback-configs) to learn more. | `null`            |

#### Service endpoints <a href="#service-endpoints" id="service-endpoints"></a>

The default service endpoints are:

| **Endpoint** | **Default value**          |
| ------------ | -------------------------- |
| `configs`    | `https://configs.split.io` |
| `events`     | `https://events.split.io`  |
| `auth`       | `https://auth.split.io`    |

To set each of the parameters defined above, use the following syntax.

{% tabs %}
{% tab title="Java" %}

```java
import io.split.configs.ConfigsClient;
import io.split.configs.ConfigsClientSettings;
import io.split.configs.LogLevel;
import io.split.configs.ServiceEndpoints;

ConfigsClientSettings settings = ConfigsClientSettings.builder()
    .pollingRate(60)
    .pushRate(60)
    .queueSize(10000)
    .logLevel(LogLevel.INFO)
    .readyTimeout(10)
    .serviceEndpoints(ServiceEndpoints.builder()
        .configs("https://configs.split.io")
        .events("https://events.split.io")
        .auth("https://auth.split.io")
        .build())
    .build();

ConfigsClient client = ConfigsClient.build("YOUR_SDK_KEY", settings);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import io.split.configs.ConfigsClient
import io.split.configs.ConfigsClientSettings
import io.split.configs.LogLevel
import io.split.configs.ServiceEndpoints

val settings = ConfigsClientSettings.builder()
    .pollingRate(60)
    .pushRate(60)
    .queueSize(10000)
    .logLevel(LogLevel.INFO)
    .readyTimeout(10)
    .serviceEndpoints(ServiceEndpoints.builder()
        .configs("https://configs.split.io")
        .events("https://events.split.io")
        .auth("https://auth.split.io")
        .build())
    .build()

val client = ConfigsClient.build("YOUR_SDK_KEY", settings)
```

{% endtab %}
{% endtabs %}

#### Configure fallback configs <a href="#configure-fallback-configs" id="configure-fallback-configs"></a>

Fallback configs let you define a `Config` value to be returned when a config cannot be evaluated. By default, the SDK returns a `Config` with `variant` `"control"` and an empty `value` (`{}`), but you can override this globally or for individual configs at the SDK level.

This is useful when you want to:

* Maintain a predictable user experience during outages or evaluation failures.
* Protect critical user flows by returning a safe, stable configuration.
* Customize behavior per config so each evaluation inherits appropriate safe defaults if something goes wrong.

Each fallback entry must include a `variant` (string) and optionally a `value` (map) matching the [Config return type](#use-the-sdk).

**Global fallback config**

Set a global fallback config when instantiating the SDK. This value is returned whenever any config cannot be evaluated.

{% tabs %}
{% tab title="Java" %}

```java
import io.split.configs.FallbackConfig;
import io.split.configs.FallbackConfigs;
import io.split.configs.ConfigsClientSettings;

Map<String, Object> fallbackValue = new HashMap<>();
fallbackValue.put("prompt", "default prompt");
fallbackValue.put("temperature", 0.9);

ConfigsClientSettings settings = ConfigsClientSettings.builder()
    .fallbackConfigs(FallbackConfigs.builder()
        .global(new FallbackConfig("v1", fallbackValue))
        .build())
    .build();

ConfigsClient client = ConfigsClient.build("YOUR_SDK_KEY", settings);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import io.split.configs.FallbackConfig
import io.split.configs.FallbackConfigs
import io.split.configs.ConfigsClientSettings

val fallbackValue = mapOf<String, Any>(
    "prompt" to "default prompt",
    "temperature" to 0.9
)

val settings = ConfigsClientSettings.builder()
    .fallbackConfigs(FallbackConfigs.builder()
        .global(FallbackConfig("v1", fallbackValue))
        .build())
    .build()

val client = ConfigsClient.build("YOUR_SDK_KEY", settings)
```

{% endtab %}
{% endtabs %}

**Per-config fallback**

You can also set a fallback config per config name via the `byName` method. Per-config fallbacks always take precedence over the global fallback, so if both are defined, the SDK returns the per-config value when that config cannot be evaluated.

{% tabs %}
{% tab title="Java" %}

```java
import io.split.configs.FallbackConfig;
import io.split.configs.FallbackConfigs;
import io.split.configs.ConfigsClientSettings;

Map<String, Object> chatFallbackValue = new HashMap<>();
chatFallbackValue.put("prompt", "fallback chat prompt");
chatFallbackValue.put("temperature", 0.1);

ConfigsClientSettings settings = ConfigsClientSettings.builder()
    .fallbackConfigs(FallbackConfigs.builder()
        .byName("chat_bot_config", new FallbackConfig("v2", chatFallbackValue))
        .build())
    .build();

ConfigsClient client = ConfigsClient.build("YOUR_SDK_KEY", settings);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import io.split.configs.FallbackConfig
import io.split.configs.FallbackConfigs
import io.split.configs.ConfigsClientSettings

val chatFallbackValue = mapOf<String, Any>(
    "prompt" to "fallback chat prompt",
    "temperature" to 0.1
)

val settings = ConfigsClientSettings.builder()
    .fallbackConfigs(FallbackConfigs.builder()
        .byName("chat_bot_config", FallbackConfig("v2", chatFallbackValue))
        .build())
    .build()

val client = ConfigsClient.build("YOUR_SDK_KEY", settings)
```

{% endtab %}
{% endtabs %}

### Advanced use cases <a href="#advanced-use-cases" id="advanced-use-cases"></a>

This section describes advanced use cases and features provided by the SDK.

#### Subscribe to events <a href="#subscribe-to-events" id="subscribe-to-events"></a>

You can listen for three different events from the SDK.

* `SDK_READY`. This event fires once the SDK is ready to evaluate configs using the most up-to-date version of your rollout plan, downloaded from Harness servers.
* `SDK_READY_TIMED_OUT`. This event fires if the SDK could not fully download the data from Harness servers (`SDK_READY` event) within the time specified by the `readyTimeout` setting. This event does not indicate that the SDK initialization was interrupted. The SDK continues downloading and fires the `SDK_READY` event when finished. This delayed `SDK_READY` event may happen with slow connections or large rollout plans with many configs and segments.
* `SDK_UPDATE`. This event fires whenever your rollout plan is changed. Listen for this event to refresh your app whenever a config or segment is changed in Harness FME.

These events provide hooks to run custom logic whenever the SDK state changes.

{% tabs %}
{% tab title="Java" %}

```java
import io.split.configs.events.ConfigsEvent;
import io.split.configs.events.SdkUpdateMetadata;
import java.util.List;
import java.util.function.Consumer;

client.on(ConfigsEvent.SDK_READY, () -> {
    System.out.println("Configs SDK is ready.");
});

client.on(ConfigsEvent.SDK_READY_TIMED_OUT, () -> {
    System.out.println("Configs SDK emitted SDK_READY_TIMED_OUT event.");
});

client.on(ConfigsEvent.SDK_UPDATE, new Consumer<SdkUpdateMetadata>() {
    @Override
    public void accept(SdkUpdateMetadata metadata) {
        String type = metadata.getType().name(); // "CONFIGS_UPDATE"
        List<String> names = metadata.getNames();
        System.out.println("Updated configs: " + names);
    }
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
import io.split.configs.events.ConfigsEvent
import io.split.configs.events.SdkUpdateMetadata
import java.util.function.Consumer

client.on(ConfigsEvent.SDK_READY) {
    println("Configs SDK is ready.")
}

client.on(ConfigsEvent.SDK_READY_TIMED_OUT) {
    println("Configs SDK emitted SDK_READY_TIMED_OUT event.")
}

client.on(ConfigsEvent.SDK_UPDATE, Consumer<SdkUpdateMetadata> { metadata ->
    val type = metadata.type.name // "CONFIGS_UPDATE"
    val names = metadata.names
    println("Updated configs: $names")
})
```

{% endtab %}
{% endtabs %}

Use the `off` method to remove all listeners for a specific event.

{% tabs %}
{% tab title="Java" %}

```java
client.off(ConfigsEvent.SDK_UPDATE);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
client.off(ConfigsEvent.SDK_UPDATE)
```

{% endtab %}
{% endtabs %}

**Include metadata**

`metadata` provides additional context for events:

* `SDK_UPDATE`: Includes `getType()` (`CONFIGS_UPDATE`) and `getNames()` (list of impacted config names).
* `SDK_READY` and `SDK_READY_TIMED_OUT`: No metadata is included.

{% @harness-feedback/feedback %}
