### Quick Start: Initialize FeatBit Java SDK
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/initialization.md
A simple, all-in-one example demonstrating SDK initialization, user creation, flag evaluation, and event tracking.
```java
import co.featbit.commons.model.FBUser;
import co.featbit.server.FBClientImp;
import co.featbit.server.FBConfig;
import co.featbit.server.exterior.FBClient;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
// 1. Create configuration
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://localhost:5100")
.eventURL("http://localhost:5100")
.build();
// 2. Create client
FBClient client = new FBClientImp("your-env-secret", config);
// 3. Wait for readiness (optional)
if (client.isInitialized()) {
// 4. Create a user
FBUser user = new FBUser.Builder("user-id")
.userName("John Doe")
.build();
// 5. Evaluate flags
Boolean featureEnabled = client.boolVariation("feature-flag-key", user, false);
System.out.println("Feature enabled: " + featureEnabled);
// 6. Track events
client.trackMetric(user, "feature_used");
}
// 7. Clean up
try {
client.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
```
--------------------------------
### Configure SDK Initialization with Zero Start Wait Time
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/errors.md
Configure the FeatBit client to start waiting immediately by setting `startWaitTime` to `Duration.ZERO`. This is useful for faster initialization checks.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL(streamUrl)
.eventURL(eventUrl)
.startWaitTime(Duration.ZERO)
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Minimal Online Configuration
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Example of setting up a minimal online FBConfig with streaming and event URLs, then initializing an FBClient.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://feature-flags.example.com:5100")
.eventURL("http://feature-flags.example.com:5100")
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Testing Configuration
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/configuration.md
Configuration suitable for testing environments, using local host URLs, zero start wait time to avoid blocking, and disabling event tracking. This setup is useful for rapid local development and testing.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://localhost:5100")
.eventURL("http://localhost:5100")
.startWaitTime(Duration.ZERO) // Don't block
.disableEvents(true) // No event tracking
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Get Start Wait Time
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Retrieves the configured startup wait duration from the FBConfig.
```java
public Duration getStartWaitTime()
```
--------------------------------
### Install SDK using Gradle
Source: https://github.com/featbit/featbit-java-sdk/blob/master/README.md
Add the FeatBit Java SDK to your project's Gradle dependencies.
```gradle
implementation 'co.featbit:featbit-java-sdk:1.4.5'
```
--------------------------------
### Minimal Production Setup for FeatBit Java SDK
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/README.md
Use this configuration for a standard production environment. It sets the streaming and event URLs for the SDK.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("wss://api.example.com:5100")
.eventURL("https://api.example.com:5100")
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Install SDK using Maven
Source: https://github.com/featbit/featbit-java-sdk/blob/master/README.md
Add the FeatBit Java SDK to your project's Maven dependencies.
```xml
co.featbit
featbit-java-sdk
1.4.5
```
--------------------------------
### Reactive UI Updates (Web Framework Example)
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/flagtracker.md
Update UI components reactively when a specific flag changes, for example, by sending messages to connected clients.
```java
// In a Spring Controller or similar
@PostConstruct
void initFlagTracking() {
FBUser currentUser = getCurrentUser();
tracker.addFlagValueChangeListener(
"ui-theme",
currentUser,
event -> {
// Notify all WebSocket clients of theme change
messagingTemplate.convertAndSendToUser(
currentUser.getKey(),
"/topic/ui-updates",
new ThemeChangeMessage((String) event.getNewValue())
);
}
);
}
```
--------------------------------
### Testing Setup for FeatBit Java SDK
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/README.md
Configure the SDK for testing environments, typically using local endpoints and disabling events. The `startWaitTime` is set to zero for immediate startup.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://localhost:5100")
.eventURL("http://localhost:5100")
.startWaitTime(Duration.ZERO)
.disableEvents(true)
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Quick Start: Initialize and Evaluate Feature Flag
Source: https://github.com/featbit/featbit-java-sdk/blob/master/README.md
Demonstrates basic SDK initialization with custom configuration and evaluation of a boolean feature flag for a user. Ensure to replace placeholder values for environment secret, stream URL, and event URL.
```java
import co.featbit.commons.model.FBUser;
import co.featbit.commons.model.EvalDetail;
import co.featbit.server.FBClientImp;
import co.featbit.server.FBConfig;
import co.featbit.server.exterior.FBClient;
import java.io.IOException;
class Main {
public static void main(String[] args) throws IOException {
String envSecret = "";
String streamUrl = "ws://localhost:5100";
String eventUrl = "http://localhost:5100";
FBConfig config = new FBConfig.Builder()
.streamingURL(streamUrl)
.eventURL(eventUrl)
.build();
FBClient client = new FBClientImp(envSecret, config);
if (client.isInitialized()) {
// The flag key to be evaluated
String flagKey = "use-new-algorithm";
// The user
FBUser user = new FBUser.Builder("bot-id")
.userName("bot")
.build();
// Evaluate a boolean flag for a given user
Boolean flagValue = client.boolVariation(flagKey, user, false);
System.out.printf("flag %s, returns %b for user %s%n", flagKey, flagValue, user.getUserName());
// Evaluate a boolean flag for a given user with evaluation detail
EvalDetail ed = client.boolVariationDetail(flagKey, user, false);
System.out.printf("flag %s, returns %b for user %s, reason: %s%n", flagKey, ed.getVariation(), user.getUserName(), ed.getReason());
}
// Close the client to ensure that all insights are sent out before the app exits
client.close();
System.out.println("APP FINISHED");
}
}
```
--------------------------------
### Obtain DataUpdateStatusProvider Instance
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/types.md
Example of how to obtain an instance of DataUpdateStatusProvider from the FeatBit client.
```java
Status.DataUpdateStatusProvider provider = client.getDataUpdateStatusProvider();
```
--------------------------------
### Minimal Online Configuration
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/configuration.md
Basic configuration for an online FeatBit client, specifying the streaming and event URLs. This is a starting point for most online use cases.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://feature-flags.example.com:5100")
.eventURL("http://feature-flags.example.com:5100")
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### UserTag Construction Examples
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/types.md
Demonstrates two ways to construct a UserTag object: using the static of() method or the constructor directly.
```java
UserTag tag = UserTag.of("userId", UserTag.HEADER, "user_id");
// or
UserTag tag = new UserTag("userId", UserTag.HEADER, "user_id");
```
--------------------------------
### Asynchronous FBClient Initialization
Source: https://github.com/featbit/featbit-java-sdk/blob/master/README.md
Instantiate FBClient with a configuration that has a zero start wait time for immediate return. Use getDataUpdateStatusProvider().waitForOKState() to asynchronously wait for initialization to complete within a specified duration.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL(streamUrl)
.eventURL(eventUrl)
.startWaitTime(Duration.ZERO)
.build();
FBClient client = new FBClientImp(sdkKey, config);
// later, when you want to wait for initialization to finish:
boolean inited = client.getDataUpdateStatusProvider().waitForOKState(Duration.ofSeconds(10))
if (inited) {
// the client is ready
}
```
--------------------------------
### Asynchronous SDK Initialization and State Handling
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/errors.md
Initiate SDK initialization asynchronously in a separate thread and handle the `ready` state or `InterruptedException`. This prevents blocking the main thread during SDK setup.
```java
new Thread(() -> {
try {
boolean ready = client.getDataUpdateStatusProvider()
.waitForOKState(Duration.ofMinutes(1));
if (ready) {
onSDKReady();
} else {
onSDKInitFailed();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}).start();
```
--------------------------------
### Obtain FlagTracker Instance
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/flagtracker.md
Get an instance of FlagTracker from the FeatBit client to manage flag change listeners.
```java
FlagTracker tracker = client.getFlagTracker();
```
--------------------------------
### Synchronous FBClient Initialization
Source: https://github.com/featbit/featbit-java-sdk/blob/master/README.md
Instantiate FBClient with a configuration that includes a start wait time. The constructor will block until connected or the timeout expires. Check initialization status with isInitialized().
```java
FBConfig config = new FBConfig.Builder()
.streamingURL(streamUrl)
.eventURL(eventUrl)
.startWaitTime(Duration.ofSeconds(10))
.build();
FBClient client = new FBClientImp(envSecret, config);
if(client.isInitialized()){
// the client is ready
}
```
--------------------------------
### Configure Logback for FeatBit SDK
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/errors.md
Use this configuration in your Logback setup to enable DEBUG level logging for the FeatBit SDK. This helps in capturing detailed error information.
```xml
```
--------------------------------
### Initialize SDK in Offline Mode (Java)
Source: https://github.com/featbit/featbit-java-sdk/blob/master/README.md
Configure the SDK to operate in offline mode, preventing remote calls and using fallback values. This setup requires a `FBConfig` builder and an `FBClientImp` instance.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL(streamUrl)
.eventURL(eventUrl)
.offline(true)
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Offline Setup for FeatBit Java SDK
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/README.md
Enable offline mode for the SDK, which loads flag configurations from a local JSON file. Ensure the JSON file is correctly loaded and provided to the client.
```java
FBConfig config = new FBConfig.Builder()
.offline(true)
.build();
FBClient client = new FBClientImp(envSecret, config);
client.initializeFromExternalJson(loadJson("flags.json"));
```
--------------------------------
### Java: Evaluate Feature Flag with Details
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/evaldetail.md
Demonstrates how to get detailed evaluation results for a boolean feature flag. It shows how to handle cases where the flag is not found and log the evaluation outcome.
```java
FBClient client = new FBClientImp(envSecret, config);
FBUser user = new FBUser.Builder("user-123")
.userName("John")
.build();
// Get evaluation details
EvalDetail detail = client.boolVariationDetail("feature-x", user, false);
if (detail.isDefaultVariation()) {
logger.warn("Flag not found: {}", detail.getReason());
useDefault();
} else {
logger.info("Flag {} evaluated to: {}", detail.getKeyName(), detail.getVariation());
if (detail.getVariation()) {
enableFeature();
}
}
```
--------------------------------
### Configure Log4j2 for FeatBit SDK
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/errors.md
Use this configuration in your Log4j2 setup to enable debug level logging for the FeatBit SDK. This is useful for detailed error capturing.
```xml
```
--------------------------------
### FBUser toString() Method Example
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbuser.md
Provides a string representation of the FBUser for debugging purposes, showing key, userName, and custom attributes. This method is part of the Object class override.
```java
@Override
public String toString()
```
```text
FBUser{userName=John, key=user-123, custom={email=john@example.com, role=admin}}
```
--------------------------------
### Initialize FBClient with Custom Configuration
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbclient.md
Demonstrates how to create an FBClient instance with a custom configuration, including streaming and event URLs, and a specific start-up wait time. Ensure the environment secret is valid and the configuration object is properly built.
```java
String envSecret = "your-env-secret";
String streamUrl = "ws://localhost:5100";
String eventUrl = "http://localhost:5100";
FBConfig config = new FBConfig.Builder()
.streamingURL(streamUrl)
.eventURL(eventUrl)
.startWaitTime(Duration.ofSeconds(10))
.build();
FBClient client = new FBClientImp(envSecret, config);
if (client.isInitialized()) {
System.out.println("Client is ready");
}
```
--------------------------------
### Java EvalDetail toString Method Example
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/evaldetail.md
Provides a string representation of an EvalDetail object, useful for debugging. The example shows the expected format of the output string.
```java
EvalDetail{variation=true, isDefault=false, reason=Matched rule 0, name=New Feature, keyName=new-feature}
```
--------------------------------
### Initialize FeatBit Java SDK with Custom Configuration
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/README.md
Illustrates how to initialize the FeatBit SDK with a custom configuration, including setting the streaming and event URLs, and specifying a start-up wait time. The SDK initializes asynchronously.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://server:5100")
.eventURL("http://server:5100")
.startWaitTime(Duration.ofSeconds(15)) // Block up to 15 seconds
.build();
FBClient client = new FBClientImp(envSecret, config);
if (client.isInitialized()) {
// Safe to use
}
```
--------------------------------
### Get Insight Processor Factory
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Retrieves the configured InsightProcessorFactory from the FBConfig.
```java
public InsightProcessorFactory getInsightProcessorFactory()
```
--------------------------------
### Testing Configuration
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Sets up a testing configuration for FBConfig, disabling events and setting streaming/event URLs to localhost with zero startup wait time, then initializes an FBClient.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://localhost:5100")
.eventURL("http://localhost:5100")
.startWaitTime(Duration.ZERO)
.disableEvents(true)
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Get HTTP Config Factory
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Retrieves the configured HttpConfigFactory from the FBConfig.
```java
public HttpConfigFactory getHttpConfigFactory()
```
--------------------------------
### Get Data Synchronizer Factory
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Retrieves the configured DataSynchronizerFactory from the FBConfig.
```java
public DataSynchronizerFactory getDataSynchronizerFactory()
```
--------------------------------
### Get Data Storage Factory
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Retrieves the configured DataStorageFactory from the FBConfig.
```java
public DataStorageFactory getDataStorageFactory()
```
--------------------------------
### Configure SDK with Environment Variables in Java
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/configuration.md
Read environment variables for streaming and event URLs, and the environment secret, then pass them to the `FBConfig.Builder` to initialize the `FBClient`.
```java
String streamUrl = System.getenv("FEATBIT_STREAM_URL");
String eventUrl = System.getenv("FEATBIT_EVENT_URL");
String envSecret = System.getenv("FEATBIT_ENV_SECRET");
FBConfig config = new FBConfig.Builder()
.streamingURL(streamUrl)
.eventURL(eventUrl)
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Production Configuration
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/configuration.md
Recommended configuration for production environments, including custom HTTP connection and socket timeouts, secure streaming and event URLs, and a start-up wait time. It also shows how to check if the client is initialized before use.
```java
HttpConfigurationBuilder httpConfig = Factory.httpConfigFactory()
.connectTime(Duration.ofSeconds(5))
.socketTime(Duration.ofSeconds(10));
FBConfig config = new FBConfig.Builder()
.streamingURL("wss://feature-flags.example.com:5100")
.eventURL("https://feature-flags.example.com:5100")
.httpConfigFactory(httpConfig)
.startWaitTime(Duration.ofSeconds(15))
.build();
FBClient client = new FBClientImp(envSecret, config);
// Check if client is ready before using
if (client.isInitialized()) {
// Safe to evaluate flags
}
```
--------------------------------
### Get Event URL
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Retrieves the configured HTTP event URL from the FBConfig.
```java
public String getEventURL()
```
--------------------------------
### Production Configuration with Timeouts
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Configures production settings including connection and socket timeouts, streaming/event URLs, and startup wait time, then initializes an FBClient and checks its initialization status.
```java
HttpConfigurationBuilder httpConfig = Factory.httpConfigFactory()
.connectTime(Duration.ofSeconds(5))
.socketTime(Duration.ofSeconds(10));
FBConfig config = new FBConfig.Builder()
.streamingURL("wss://feature-flags.example.com:5100")
.eventURL("https://feature-flags.example.com:5100")
.httpConfigFactory(httpConfig)
.startWaitTime(Duration.ofSeconds(15))
.build();
FBClient client = new FBClientImp(envSecret, config);
if (client.isInitialized()) {
// Ready to evaluate flags
}
```
--------------------------------
### Get Streaming URL
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Retrieves the configured WebSocket streaming URL from the FBConfig.
```java
public String getStreamingURL()
```
--------------------------------
### Initialize FBClient with Try-With-Resources
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/initialization.md
Use try-with-resources for automatic cleanup of the FBClient. Ensure the client is initialized before use.
```java
try (FBClient client = new FBClientImp(envSecret, config)) {
if (client.isInitialized()) {
Boolean flag = client.boolVariation("key", user, false);
// Use flag
}
} // client.close() called automatically
```
--------------------------------
### Get User Name
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbuser.md
Retrieves the display name of the user. This is a user-friendly attribute.
```java
public String getUserName()
```
--------------------------------
### Asynchronous Initialization with Wait
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/configuration.md
Configure the SDK for immediate return on initialization and later wait for the data update status to be OK. This pattern avoids blocking the main thread during startup and allows for controlled initialization checks.
```java
// Return immediately, don't block
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://feature-flags.example.com:5100")
.eventURL("http://feature-flags.example.com:5100")
.startWaitTime(Duration.ZERO)
.build();
FBClient client = new FBClientImp(envSecret, config);
// Later, wait for initialization at your chosen time
Thread.startVirtualThread(() -> {
try {
Status.DataUpdateStatusProvider provider = client.getDataUpdateStatusProvider();
boolean ready = provider.waitForOKState(Duration.ofSeconds(30));
if (ready) {
System.out.println("SDK is ready");
} else {
System.out.println("SDK initialization timed out");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
});
```
--------------------------------
### getBooleanDetail
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/allflagstates.md
Gets the evaluation details for a boolean flag. This method provides more insight into how the flag was evaluated.
```APIDOC
## getBooleanDetail
### Description
Gets the evaluation details for a boolean flag.
### Method Signature
`EvalDetail getBooleanDetail(String flagKeyName, Boolean defaultValue)`
### Parameters
#### Path Parameters
* None
#### Query Parameters
* None
#### Request Body
* None
### Returns
An `EvalDetail` with value and evaluation reason.
### Example
*No example provided in source.*
```
--------------------------------
### getProperty(String attribute)
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbuser.md
Gets the value of a user attribute by name, either built-in or custom.
```APIDOC
## getProperty(String attribute)
### Description
Gets the value of a user attribute by name, either built-in or custom.
### Parameters
#### Path Parameters
- **attribute** (String) - Required - The attribute name (case-insensitive for built-ins)
### Returns
The attribute value, or `null` if not found.
### Built-in Attributes (case-insensitive):
- "name" → returns `userName`
- "keyid" → returns `key`
- "key" → returns `key`
### Example
```java
String email = user.getProperty("email"); // from custom attributes
String name = user.getProperty("name"); // built-in, same as getKey()
String key = user.getProperty("KEY"); // case-insensitive
```
```
--------------------------------
### getIntegerDetail
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/allflagstates.md
Gets the evaluation details for an integer flag. Use this to understand the evaluation process for integer flags.
```APIDOC
## getIntegerDetail
### Description
Gets the evaluation details for an integer flag.
### Method Signature
`EvalDetail getIntegerDetail(String flagKeyName, Integer defaultValue)`
### Parameters
#### Path Parameters
* None
#### Query Parameters
* None
#### Request Body
* None
### Returns
An `EvalDetail` with value and evaluation reason.
### Example
*No example provided in source.*
```
--------------------------------
### Synchronous Initialization (Blocking)
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/initialization.md
Initialize the SDK by blocking up to 15 seconds for flag data to load. Suitable for simple applications or testing where immediate readiness is required.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://localhost:5100")
.eventURL("http://localhost:5100")
// startWaitTime defaults to 15 seconds
.build();
FBClient client = new FBClientImp(envSecret, config);
// Constructor blocks here for up to 15 seconds
if (client.isInitialized()) {
// SDK is ready, all flags loaded
evaluateFlags(client);
} else {
// Timeout or error, but SDK continues trying in background
useDefaults();
}
```
--------------------------------
### Get User Key
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbuser.md
Retrieves the unique identifier for the user. This is a core attribute used for user identification.
```java
public String getKey()
```
```java
String id = user.getKey(); // "user-123"
```
--------------------------------
### FBConfig Builder Usage
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Demonstrates how to construct an FBConfig instance using the Builder pattern, setting custom URLs and wait times.
```APIDOC
## FBConfig.Builder
### Description
Builder for creating `FBConfig` instances. Calls can be chained.
### Constructor
```java
public Builder()
```
Creates a new builder with default settings:
- `offline` = false
- `disableEvents` = false
- `startWaitTime` = 15 seconds
- `streamingURL` = null
- `eventURL` = null
### Example Usage
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://localhost:5100")
.eventURL("http://localhost:5100")
.startWaitTime(Duration.ofSeconds(10))
.build();
```
```
--------------------------------
### Initialize and Reuse Single Shared Client
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/initialization.md
Recommended approach for most applications. Create a single `FBClient` instance per environment and reuse it throughout the application to benefit from a shared connection, cache, and reduced resource usage.
```java
public class FBClientProvider {
private static final FBClient client = initializeClient();
private static FBClient initializeClient() {
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://server:5100")
.eventURL("http://server:5100")
.build();
return new FBClientImp(envSecret, config);
}
public static FBClient getClient() {
return client;
}
}
// Usage everywhere
boolean flag = FBClientProvider.getClient().boolVariation("key", user, false);
```
--------------------------------
### Get Feature Flag Display Name
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/evaldetail.md
Retrieves the human-readable display name of the evaluated feature flag.
```java
String flagName = detail.getName(); // "Enable New Feature"
```
--------------------------------
### getStartWaitTime()
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Retrieves the configured startup wait duration.
```APIDOC
## getStartWaitTime()
### Description
Retrieves the configured startup wait duration.
### Method
```java
public Duration getStartWaitTime()
```
### Returns
- **Duration**: The configured startup wait duration.
```
--------------------------------
### Get Feature Flag Key Name
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/evaldetail.md
Retrieves the unique key identifier for the evaluated feature flag.
```java
String flagKey = detail.getKeyName(); // "new-feature"
```
--------------------------------
### Create FBClient with Default FBConfig
Source: https://github.com/featbit/featbit-java-sdk/blob/master/README.md
Use this snippet to create an FBClient with default configurations by providing streaming and event URLs. The constructor will block until data is synced.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL(streamUrl)
.eventURL(eventUrl)
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Manage Multiple Clients for Multi-Environment Scenarios
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/initialization.md
An advanced pattern for scenarios involving multiple distinct environments (e.g., production and staging) within the same application. Ensure to properly initialize and close each client.
```java
FBClient prodClient = new FBClientImp(prodSecret, prodConfig);
FBClient stagingClient = new FBClientImp(stagingSecret, stagingConfig);
// Use appropriate client based on context
Boolean flag = selectedEnv.equals("prod")
? prodClient.boolVariation(key, user, false)
: stagingClient.boolVariation(key, user, false);
// Clean up both
prodClient.close();
stagingClient.close();
```
--------------------------------
### getInteger
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/allflagstates.md
Gets the integer value of a flag, or the default if not found or not an integer. This method is suitable for retrieving integer-based feature flags.
```APIDOC
## getInteger
### Description
Gets the integer value of a flag, or the default if not found or not an integer.
### Method Signature
`Integer getInteger(String flagKeyName, Integer defaultValue)`
### Parameters
#### Path Parameters
* None
#### Query Parameters
* None
#### Request Body
* None
### Parameters Table
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| flagKeyName | String | Yes | The unique flag key |
| defaultValue | Integer | Yes | Value to return if flag not found or wrong type |
### Returns
The integer flag value or `defaultValue`.
### Example
*No example provided in source.*
```
--------------------------------
### Create FBConfig Instance with Builder
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Use the FBConfig.Builder to construct an immutable FBConfig instance with custom streaming and event URLs, and a specified startup wait time. Ensure Duration is imported.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://localhost:5100")
.eventURL("http://localhost:5100")
.startWaitTime(Duration.ofSeconds(10))
.build();
```
--------------------------------
### Get Evaluation Reason
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/evaldetail.md
Retrieves the reason for the flag evaluation. This helps in understanding why a particular variation was returned, especially when debugging.
```java
EvalDetail detail = client.variationDetail("api-version", user, "v1");
System.out.println("Reason: " + detail.getReason());
// Output: Reason: Matched rule 0
```
--------------------------------
### Asynchronous Initialization (Non-Blocking)
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/initialization.md
Initialize the SDK without blocking, returning immediately for faster startup. Use this for web applications or services where startup time is critical.
```java
import co.featbit.server.Status;
import java.time.Duration;
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://localhost:5100")
.eventURL("http://localhost:5100")
.startWaitTime(Duration.ZERO) // Don't block
.build();
FBClient client = new FBClientImp(envSecret, config);
// Constructor returns immediately
// Later, wait for initialization when needed
new Thread(() -> {
try {
Status.DataUpdateStatusProvider provider = client.getDataUpdateStatusProvider();
boolean ready = provider.waitForOKState(Duration.ofSeconds(30));
if (ready) {
System.out.println("SDK is now ready");
onSDKReady();
} else {
System.out.println("SDK initialization timed out");
onSDKInitTimeout();
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}).start();
// Meanwhile, can start application (will use defaults until SDK ready)
startApplication(client);
```
--------------------------------
### getBoolean
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/allflagstates.md
Gets the boolean value of a flag, or the default if not found or not a boolean. This method is useful for retrieving simple boolean feature flags.
```APIDOC
## getBoolean
### Description
Gets the boolean value of a flag, or the default if not found or not a boolean.
### Method Signature
`Boolean getBoolean(String flagKeyName, Boolean defaultValue)`
### Parameters
#### Path Parameters
* None
#### Query Parameters
* None
#### Request Body
* None
### Parameters Table
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| flagKeyName | String | Yes | The unique flag key |
| defaultValue | Boolean | Yes | Value to return if flag not found or wrong type |
### Returns
The boolean flag value or `defaultValue`.
### Example
```java
Boolean betaFeatures = states.getBoolean("beta-features", false);
```
```
--------------------------------
### Get Reason for AllFlagStates Evaluation
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/allflagstates.md
Retrieves the outcome of the bulk flag evaluation. Returns 'OK' on success or an error message if the evaluation failed.
```java
AllFlagStates states = client.getAllLatestFlagsVariations(user);
System.out.println("Evaluation reason: " + states.getReason());
```
--------------------------------
### FBClientImp Constructor
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbclient.md
Initializes a new FBClientImp instance, establishing a connection to the FeatBit feature flag center. It handles authentication and configuration, with options for connection timeouts and error handling.
```APIDOC
## FBClientImp(String envSecret, FBConfig config)
### Description
Creates a new client instance to connect to the FeatBit feature flag center.
### Method Signature
```java
public FBClientImp(String envSecret, FBConfig config) throws NullPointerException, IllegalArgumentException
```
### Parameters
#### Path Parameters
- **envSecret** (String) - Required - The environment secret key for authentication. Must be a valid non-empty string.
- **config** (FBConfig) - Required - Configuration object containing streaming URL, event URL, and other settings
### Returns
An initialized `FBClient` instance.
### Throws
- `NullPointerException` if `envSecret` or `config` is null
- `IllegalArgumentException` if `envSecret` is invalid or URLs are not valid
### Behavior
- Initiates connection to feature flag center (unless offline mode is enabled)
- Blocks for the duration specified by `FBConfig.Builder#startWaitTime()` (default: 15 seconds) waiting for initialization
- Returns immediately if `startWaitTime` is zero or negative
- If connection fails after timeout, the client enters uninitialized state and returns default flag values
- Background reconnection continues unless a `ProtocolException` occurs or `close()` is called
### Example
```java
String envSecret = "your-env-secret";
String streamUrl = "ws://localhost:5100";
String eventUrl = "http://localhost:5100";
FBConfig config = new FBConfig.Builder()
.streamingURL(streamUrl)
.eventURL(eventUrl)
.startWaitTime(Duration.ofSeconds(10))
.build();
FBClient client = new FBClientImp(envSecret, config);
if (client.isInitialized()) {
System.out.println("Client is ready");
}
```
```
--------------------------------
### Get Evaluated Flag Value
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/evaldetail.md
Retrieves the evaluated flag value of type T. This is the primary value returned by the feature flag evaluation.
```java
EvalDetail detail = client.boolVariationDetail("new-feature", user, false);
Boolean featureEnabled = detail.getVariation();
```
--------------------------------
### FBConfig Builder
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/MANIFEST.txt
The FBConfig.Builder allows configuring the FeatBit SDK with various settings, including required URLs, optional parameters, and component factories for storage, synchronization, and event processing.
```APIDOC
## FBConfig.Builder
### Description
Configures the FeatBit SDK by setting essential parameters and optional features. This builder allows customization of streaming and event URLs, offline mode, event disabling, start-up wait times, and component factories for various SDK functionalities.
### Methods
- **Required Settings**: `streamingURL(String url)`, `eventURL(String url)`
- **Optional Settings**: `offline(boolean offline)`, `disableEvents(boolean disableEvents)`, `startWaitTime(long waitTimeMillis)`
- **Component Factories**: Methods to set custom implementations for `storage`, `sync`, `HTTP`, and `events`.
- **HTTP Configuration**: Options for `timeouts`, `proxies`, and `SSL`.
- **`build()`**: Constructs and returns the `FBConfig` object.
```
--------------------------------
### Handle Initialization Failure
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/initialization.md
Check if the SDK client has successfully initialized. If not, log the error details and choose to either use default flag values or throw an exception to fail fast.
```java
FBClient client = new FBClientImp(envSecret, config);
if (!client.isInitialized()) {
// SDK failed to connect
Status.State state = client.getDataUpdateStatusProvider().getState();
if (state.getErrorTrack() != null) {
logger.error("SDK initialization failed: {} - {}\n",
state.getErrorTrack().getErrorType(),
state.getErrorTrack().getMessage());
}
// Option 1: Use defaults and continue
useDefaultFlags();
// Option 2: Fail fast
throw new IllegalStateException("FeatBit SDK failed to initialize");
}
```
--------------------------------
### Configure HTTP Client Settings
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/configuration.md
Use `Factory.httpConfigFactory()` to create an `HttpConfigurationBuilder` and set connection/socket timeouts and proxy details. Pass the resulting configuration to `FBConfig.Builder`.
```java
HttpConfigurationBuilder httpConfig = Factory.httpConfigFactory()
.connectTime(Duration.ofSeconds(5))
.socketTime(Duration.ofSeconds(10))
.httpProxy("proxy.corp.com", 8080)
.passwordAuthenticator("proxyuser", "proxypass");
FBConfig config = new FBConfig.Builder()
.httpConfigFactory(httpConfig)
// ... other settings ...
.build();
```
--------------------------------
### Get Long Variation Details
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbclient.md
Evaluates a long-valued feature flag and returns details about the evaluation. Use this to understand why a specific long value was returned.
```java
EvalDetail detail = client.longVariationDetail("my-long-flag", user, 0L);
```
--------------------------------
### Evaluate Feature Flags with FeatBit Java SDK
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/README.md
Demonstrates how to evaluate boolean feature flags and retrieve evaluation details, including the reason for the evaluation. Ensure the SDK is initialized before use.
```java
FBClient client = new FBClientImp(envSecret, config);
FBUser user = new FBUser.Builder("user-id").userName("User").build();
// Get flag value
Boolean featureEnabled = client.boolVariation("flag-key", user, false);
// Get flag with evaluation details
EvalDetail detail = client.boolVariationDetail("flag-key", user, false);
System.out.println("Value: " + detail.getVariation());
System.out.println("Reason: " + detail.getReason());
```
--------------------------------
### Get Integer Variation Details
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbclient.md
Evaluates an integer-valued feature flag and returns details about the evaluation. Use this to understand why a specific integer value was returned.
```java
EvalDetail detail = client.intVariationDetail("my-int-flag", user, 0);
```
--------------------------------
### Get Double Variation Details
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbclient.md
Evaluates a double-valued feature flag and returns details about the evaluation. Use this to understand why a specific double value was returned.
```java
EvalDetail detail = client.doubleVariationDetail("my-double-flag", user, 0.0);
```
--------------------------------
### Build FBConfig Instance
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Constructs the immutable FBConfig instance with specified configurations. This instance is then used to initialize the FBClient. Ensure all necessary configurations like streaming and event URLs are set before building.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://localhost:5100")
.eventURL("http://localhost:5100")
.startWaitTime(Duration.ofSeconds(5))
.disableEvents(false)
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Get Boolean Variation Details
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbclient.md
Evaluates a boolean-valued feature flag and returns details about the evaluation. Use this to understand why a specific boolean value was returned.
```java
EvalDetail detail = client.boolVariationDetail("my-boolean-flag", user, false);
```
--------------------------------
### Build FBUser Instance
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbuser.md
Construct the final FBUser instance using the build() method. Ensure the user's key and userName are set and not empty to avoid exceptions.
```java
FBUser user = new FBUser.Builder("user-id")
.userName("User Name")
.custom("role", "admin")
.build(); // throws if userName not set
```
--------------------------------
### Development Configuration for FeatBit SDK
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/initialization.md
Set up the FeatBit SDK for development using local endpoints and disabling event tracking. This configuration is suitable for local testing and debugging.
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://localhost:5100")
.eventURL("http://localhost:5100")
.startWaitTime(Duration.ZERO)
.disableEvents(true) // Skip event tracking
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Get String Variation Details
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbclient.md
Evaluates a string-valued feature flag and returns details about the evaluation. Use this to understand why a specific string value was returned.
```java
EvalDetail detail = client.variationDetail("api-version", user, "v1");
System.out.println("Value: " + detail.getVariation());
System.out.println("Reason: " + detail.getReason());
System.out.println("Is Default: " + detail.isDefaultVariation());
```
--------------------------------
### Get No-Op Event Processor Factory
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/configuration.md
Retrieves a factory for a no-operation event processor. This is used automatically in offline mode or can be enabled by disabling events.
```java
InsightProcessorFactory factory = Factory.externalEventTrack();
```
--------------------------------
### Proxy Configuration
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Configures proxy settings, including proxy host, port, and authentication, along with connection timeouts, for the FBConfig, then initializes an FBClient.
```java
HttpConfigurationBuilder httpConfig = Factory.httpConfigFactory()
.httpProxy("corporate-proxy.example.com", 8080)
.passwordAuthenticator("username", "password")
.connectTime(Duration.ofSeconds(5));
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://feature-flags.example.com:5100")
.eventURL("http://feature-flags.example.com:5100")
.httpConfigFactory(httpConfig)
.build();
FBClient client = new FBClientImp(envSecret, config);
```
--------------------------------
### Get Custom User Attributes
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbuser.md
Retrieves all custom attributes set for the user as an immutable map. Built-in attributes like key and userName are not included.
```java
public Map getCustom()
```
```java
Map custom = user.getCustom();
for (Map.Entry entry : custom.entrySet()) {
System.out.println(entry.getKey() + " = " + entry.getValue());
}
```
--------------------------------
### Obtaining HttpConfigurationBuilder Instance
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/types.md
Demonstrates how to obtain an instance of `HttpConfigurationBuilder` using the `Factory.httpConfigFactory()` method. This builder is used to configure HTTP client settings.
```java
HttpConfigurationBuilder builder = Factory.httpConfigFactory();
```
--------------------------------
### Status.DataUpdateStatusProvider
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/types.md
Interface for monitoring the state of data synchronization. It provides methods to get the current state, wait for specific states, and add/remove listeners for state changes.
```APIDOC
## Status.DataUpdateStatusProvider
### Description
Interface for monitoring the state of data synchronization. It provides methods to get the current state, wait for specific states, and add/remove listeners for state changes.
### Methods
- `State getState()` - Returns the current synchronization state.
- `boolean waitFor(StateType state, Duration timeout)` - Blocks execution until the synchronization reaches the specified state or the timeout occurs.
- `boolean waitForOKState(Duration timeout)` - Blocks execution until the synchronization reaches an OK state or the timeout occurs.
- `void addStateListener(StateListener listener)` - Registers a listener to be notified of state changes.
- `void removeStateListener(StateListener listener)` - Unregisters a previously added listener.
### Obtaining an Instance
```java
Status.DataUpdateStatusProvider provider = client.getDataUpdateStatusProvider();
```
```
--------------------------------
### isInitialized()
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbclient.md
Tests whether the client is ready to be used and has successfully initialized. Returns true if the client has successfully connected and loaded flag data; false if still initializing or data storage is empty.
```APIDOC
## isInitialized()
### Description
Tests whether the client is ready to be used and has successfully initialized.
### Returns
`true` if the client has successfully connected and loaded flag data; `false` if still initializing or data storage is empty.
### Example
```java
if (client.isInitialized()) {
// Safe to evaluate flags
Boolean value = client.boolVariation("my-flag", user, false);
}
```
```
--------------------------------
### Get Default Batch Event Processor Factory
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/configuration.md
Retrieves the default InsightProcessorFactory, which is a batch event processor. This is suitable for production environments for efficient network usage.
```java
InsightProcessorFactory factory = Factory.insightProcessorFactory();
```
--------------------------------
### Get User Property by Name
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbuser.md
Retrieves the value of a user attribute by its name. This method supports both built-in and custom attributes. Built-in attribute lookups are case-insensitive.
```java
public String getProperty(String attribute)
```
```java
String email = user.getProperty("email"); // from custom attributes
String name = user.getProperty("name"); // built-in, same as getKey()
String key = user.getProperty("KEY"); // case-insensitive
```
--------------------------------
### FBUser build()
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbuser.md
Constructs the FBUser instance. This method requires the key and userName to be set and non-empty.
```APIDOC
## FBUser build()
### Description
Constructs the `FBUser` instance.
### Returns
An immutable `FBUser` instance.
### Throws
`IllegalArgumentException` if key or userName are not set or are empty.
### Example
```java
FBUser user = new FBUser.Builder("user-id")
.userName("User Name")
.custom("role", "admin")
.build(); // throws if userName not set
```
```
--------------------------------
### Get Double Flag Value
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/allflagstates.md
Retrieves the double value of a flag. Use this when you need the direct double value and are okay with a default if the flag is not found or is of the wrong type.
```java
Double getDouble(String flagKeyName, Double defaultValue)
```
--------------------------------
### Get Long Flag Value
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/allflagstates.md
Retrieves the long value of a flag. Use this when you need the direct long value and are okay with a default if the flag is not found or is of the wrong type.
```java
Long getLong(String flagKeyName, Long defaultValue)
```
--------------------------------
### Use Try-with-Resources for Client Cleanup
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/errors.md
Utilize the try-with-resources statement for automatic cleanup of the FeatBit client. This simplifies resource management and prevents potential `IOException` during manual closing.
```java
try (FBClient client = new FBClientImp(envSecret, config)) {
// Use client
} // Automatically closed
```
--------------------------------
### Initialize SDK from External JSON
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbclient.md
Initializes the SDK with feature flag and segment data from an external JSON string. This is useful for offline mode.
```java
String json = Resources.toString(
Resources.getResource("featbit-bootstrap.json"),
Charsets.UTF_8
);
if (client.initializeFromExternalJson(json)) {
System.out.println("Offline mode initialized");
}
```
--------------------------------
### Configure Custom Data Storage
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/configuration.md
Provide a custom `DataStorage` implementation to the `FBConfig` builder. The default is in-memory storage.
```java
DataStorageFactory customStorage = new RedisDataStorageFactory();
FBConfig config = new FBConfig.Builder()
.dataStorageFactory(customStorage)
// ... other settings ...
.build();
```
--------------------------------
### Get JSON Flag Value
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/allflagstates.md
Retrieves the JSON value of a flag, deserializing it into a specified Java class. Use this when you need the flag's value directly and want it typed.
```java
public class FeatureConfig {
public String theme;
public int timeout;
}
AllFlagStates states = client.getAllLatestFlagsVariations(user);
FeatureConfig config = states.getJsonObject(
"feature-config",
new FeatureConfig(),
FeatureConfig.class
);
```
--------------------------------
### build
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/fbconfig.md
Constructs the immutable FBConfig instance.
```APIDOC
## FBConfig build()
### Description
Constructs the immutable `FBConfig` instance.
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Method Signature
```java
public FBConfig build()
```
### Returns
- A configured `FBConfig` instance ready for use with `FBClientImp`.
### Example
```java
FBConfig config = new FBConfig.Builder()
.streamingURL("ws://localhost:5100")
.eventURL("http://localhost:5100")
.startWaitTime(Duration.ofSeconds(5))
.disableEvents(false)
.build();
FBClient client = new FBClientImp(envSecret, config);
```
```
--------------------------------
### Get Integer Flag Value
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/allflagstates.md
Retrieves the integer value of a flag. Use this when you need the direct integer result and can provide a default value if the flag is not found or has an incorrect type.
```java
Integer getInteger(String flagKeyName, Integer defaultValue)
```
--------------------------------
### Thread-Safe API Usage in Java
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/README.md
Demonstrates safe usage of the SDK's public API from multiple threads. Ensure that the FBClient instance is initialized once per environment.
```java
ExecutorService pool = Executors.newFixedThreadPool(10);
for (int i = 0; i < 100; i++) {
pool.submit(() -> {
FBUser user = new FBUser.Builder("user-" + i).userName("User " + i).build();
Boolean flag = client.boolVariation("flag-key", user, false);
});
}
```
--------------------------------
### Get Boolean Flag Value
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/allflagstates.md
Retrieves the boolean value of a flag. Use this when you need the direct boolean result and can provide a default value if the flag is not found or has an incorrect type.
```java
Boolean getBoolean(String flagKeyName, Boolean defaultValue)
```
```java
Boolean betaFeatures = states.getBoolean("beta-features", false);
```
--------------------------------
### Get JSON Flag Evaluation Details
Source: https://github.com/featbit/featbit-java-sdk/blob/master/_autodocs/api-reference/allflagstates.md
Retrieves the evaluation details for a JSON flag, including the deserialized value and the reason for the evaluation. Use this to understand why a flag evaluated to a certain value.
```java
EvalDetail getJsonDetail(String flagKeyName, T defaultValue, Class clazz)
```