Java SDK
Flipswitch SDK for Java with real-time SSE support
Java SDK
The Flipswitch Java SDK provides an OpenFeature-compatible provider with automatic cache invalidation via Server-Sent Events (SSE).
Requirements
- Java 17+
- OpenFeature SDK 1.x
Installation
Quick Start
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | String | required | Environment API key from dashboard |
baseUrl | String | https://api.flipswitch.dev | Your Flipswitch server URL |
enableRealtime | boolean | true | Enable SSE for real-time flag updates |
cacheTtl | Duration | 60s | Cache time-to-live |
httpClient | OkHttpClient | default | Custom HTTP client |
Evaluation Context
Pass user attributes for targeting:
Real-Time Updates
When enableRealtime(true) is set (default), the SDK maintains an SSE connection to receive instant flag changes:
- The SSE client receives a
flag-changeevent - The local cache is immediately invalidated
- Next flag evaluation fetches the fresh value
Event Listeners
Connection Status
Detailed Evaluation
Get full evaluation details including variant and reason:
Object Flags
For complex flag values (JSON objects):
Bulk Flag Evaluation
Evaluate all flags at once:
Spring Boot Integration
Then inject and use in your services:
application.yml:
Reconnection Strategy
The SSE client automatically reconnects with exponential backoff:
- Initial delay: 1 second
- Maximum delay: 30 seconds
- Backoff multiplier: 2x
When reconnected, the provider state changes from STALE back to READY.
Shutdown
Always shutdown the provider when done:
In Spring Boot, the provider will be automatically shut down when the application context closes.
Troubleshooting
SSE connection keeps disconnecting
Check if your proxy or load balancer supports long-lived connections. Configure timeout settings accordingly.
Flags not updating in real-time
Verify that enableRealtime(true) is set and check the SSE status:
Memory leaks
Ensure you call shutdown() when the provider is no longer needed, especially in testing scenarios.