-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.java
More file actions
34 lines (28 loc) · 1.04 KB
/
Example.java
File metadata and controls
34 lines (28 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import com.launchdarkly.sdk.*;
import com.launchdarkly.sdk.server.*;
public class Example {
public static void main(String[] args) {
// Initialize the LDClient with your SDK key
LDClient client = new LDClient("your-sdk-key");
role = getSystemRole();
try {
// Create a context with a role
LDContext context = LDContext.builder("user-key-123")
.set("role", role)
.build();
// Evaluate the flag
boolean accessGranted = client.boolVariation("accessGranted", context, false);
// Print the result
if (accessGranted) {
System.out.println("Access is granted for role: " + context.getValue("role"));
useUpdatedURL()
} else {
System.out.println("Access is denied for role: " + context.getValue("role"));
useOldURL()
}
} finally {
// Always close the client when you're done
client.close();
}
}
}