Optimizely Rollouts

The Rollouts Developer Hub

Welcome to the Rollouts developer hub. You'll find comprehensive guides and documentation to help you start working with Rollouts as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    

Java

Quickstart guide for Optimizely Rollouts

Welcome to the quickstart guide for Optimizely's Java SDK. The instructions below will help you implement Rollouts and launch your first feature flag.

This guide will help you:

  1. Install the SDK
  2. Instantiate Optimizely when your app starts
  3. Create a feature flag
  4. Roll the feature out

1. Install the SDK

The Java SDK is distributed through Bintray. The core-api and httpclient Bintray packages are optimizely-sdk-core-api and optimizely-sdk-httpclient, respectively. You can find repository information and also instructions on how to install the dependencies on Bintray. Gradle repository and dependency configurations are shown on the right. The SDK is compatible with Java 1.6 and above.

core-api requires org.slf4j:slf4j-api:1.7.16 and a supported JSON parser. We currently integrate with these parsers (listed in their selection order priority):

  1. Jackson
  2. GSON
  3. json.org
  4. json-simple

If more than one of these parsers are available at runtime, the core-api chooses one for use per the selection order priority. If none of these packages are already provided in your project's classpath, you must add one.

repositories {
    jcenter()
}

dependencies {
    compile 'com.optimizely.ab:core-api:3.0.0'
    compile 'org.apache.httpcomponents:httpclient:4.5.6'

    // The SDK integrates with multiple JSON parsers. Here, we use Jackson.
    compile 'com.fasterxml.jackson.core:jackson-core:2.7.1'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.1'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.7.1'

    compile 'org.slf4j:slf4j-api:1.7.16'
    compile 'ch.qos.logback:logback-classic:1.1.7'
}

The full source code is at https://github.com/optimizely/java-sdk.

2. Configure Optimizely when your application starts

The datafile stores the configuration for all your features and rollouts. Whenever you make a change in Optimizely, the datafile is automatically updated so you can pull configuration changes down into your application.

The sample below shows how you can get a local copy of the datafile from our server and instantiate a client with it. Later, you'll want to adjust this code to handle datafile updates.

public String getDatafile() throws IOException {
    String url = "https://cdn.optimizely.com/datafiles/<Your_SDK_KEY>.json";
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet(url);

    HttpEntity entity = httpclient.execute(httpget).getEntity();
    return EntityUtils.toString(entity);
}

Using the datafile, instantiate the Optimizely client. The datafile contains all the information about your feature flags and rollouts.

String datafile = getDatafile();
Optimizely optimizelyClient = Optimizely.builder(datafile, new NoopEventHandler()).build();

Here's where to find your SDK Key:

  1. Navigate to Settings > Datafile.
  2. Copy the SDK Key / Primary URL.
Click to enlarge

Click to enlarge

3. Create a feature flag

Choose a feature in your app to turn on and off with a feature flag. For your first flag, consider starting with a link or visual element that's simple to change, show, or hide based on a Boolean.

To set up your first feature flag, navigate to Features > Create New Feature.

Here's how to set it up:

Click to enlarge.

Click to enlarge.

After saving, use the Boolean Is Feature Enabled function to show, hide, or change some visual part of your application. You should see a value of false from this function because you haven't rolled out the feature yet. You'll turn it on in the next step.

Boolean enabled = optimizelyClient.isFeatureEnabled("new_feature", "user123");

The userID enables you to create consistent experiences for a user across multiple visits, but you don't need it for this quickstart. Make the userID any non-null string for now.

4. Roll the feature out

In Optimizely, navigate back to Features and select your feature flag.

You'll return to this feature whenever you want to update the feature flag. For example, roll out your feature incrementally by moving the slider up by 10% per day or show it to a certain group of users. Move it to 100% for a big reveal, or 0% if issues arise in production. No code deployment necessary.

A basic way to confirm that your feature flag is working:

Show the feature to yourself

  1. Navigate to your feature.
  2. Toggle it ON and move the slider to 100% traffic. Click Save.
  3. Confirm that you see the feature.

Hide the feature from yourself

  1. Navigate back to the feature.
  2. Toggle it OFF. Click Save.
  3. Confirm that you no longer see the feature.

When you're ready, go ahead and launch your feature in production. Come back and change its configuration any time, without deploying code.



Java


Quickstart guide for Optimizely Rollouts

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.