Skip to content

Commit af0bc04

Browse files
author
Gitar
committed
[Gitar] Updating Java files
1 parent db1e420 commit af0bc04

File tree

1 file changed

+55
-44
lines changed

1 file changed

+55
-44
lines changed

src/main/java/Hello.java

+55-44
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import java.io.IOException;
2-
31
import com.launchdarkly.sdk.*;
42
import com.launchdarkly.sdk.server.*;
3+
import java.io.IOException;
54

65
public class Hello {
76

@@ -10,80 +9,88 @@ public class Hello {
109

1110
// Set FEATURE_FLAG_KEY to the feature flag key you want to evaluate.
1211
static String FEATURE_FLAG_KEY = "sample-feature";
13-
12+
1413
private static void showMessage(String s) {
1514
System.out.println("*** " + s);
1615
System.out.println();
1716
}
1817

1918
private static void showBanner() {
20-
showMessage("\n ██ \n" +
21-
" ██ \n" +
22-
" ████████ \n" +
23-
" ███████ \n" +
24-
"██ LAUNCHDARKLY █\n" +
25-
" ███████ \n" +
26-
" ████████ \n" +
27-
" ██ \n" +
28-
" ██ \n");
19+
showMessage(
20+
"\n ██ \n"
21+
+ " ██ \n"
22+
+ " ████████ \n"
23+
+ " ███████ \n"
24+
+ "██ LAUNCHDARKLY █\n"
25+
+ " ███████ \n"
26+
+ " ████████ \n"
27+
+ " ██ \n"
28+
+ " ██ \n");
2929
}
3030

3131
public static void main(String... args) throws Exception {
3232
boolean CIMode = System.getenv("CI") != null;
3333

3434
String envSDKKey = System.getenv("LAUNCHDARKLY_SDK_KEY");
35-
if(envSDKKey != null) {
35+
if (envSDKKey != null) {
3636
SDK_KEY = envSDKKey;
3737
}
3838

3939
String envFlagKey = System.getenv("LAUNCHDARKLY_FLAG_KEY");
40-
if(envFlagKey != null) {
40+
if (envFlagKey != null) {
4141
FEATURE_FLAG_KEY = envFlagKey;
4242
}
4343

4444
LDConfig config = new LDConfig.Builder().build();
4545

4646
if (SDK_KEY == null || SDK_KEY.equals("")) {
47-
showMessage("Please set the LAUNCHDARKLY_SDK_KEY environment variable or edit Hello.java to set SDK_KEY to your LaunchDarkly SDK key first.");
47+
showMessage(
48+
"Please set the LAUNCHDARKLY_SDK_KEY environment variable or edit Hello.java to set"
49+
+ " SDK_KEY to your LaunchDarkly SDK key first.");
4850
System.exit(1);
4951
}
5052

5153
final LDClient client = new LDClient(SDK_KEY, config);
5254
if (client.isInitialized()) {
5355
showMessage("SDK successfully initialized!");
5456
} else {
55-
showMessage("SDK failed to initialize. Please check your internet connection and SDK credential for any typo.");
57+
showMessage(
58+
"SDK failed to initialize. Please check your internet connection and SDK credential for"
59+
+ " any typo.");
5660
System.exit(1);
5761
}
5862

5963
// Set up the evaluation context. This context should appear on your
6064
// LaunchDarkly contexts dashboard soon after you run the demo.
61-
final LDContext context = LDContext.builder("example-user-key")
62-
.name("Sandy")
63-
.build();
65+
final LDContext context = LDContext.builder("example-user-key").name("Sandy").build();
66+
showMessage("The '" + FEATURE_FLAG_KEY + "' feature flag evaluates to " + true + ".");
6467

65-
// Evaluate the feature flag for this context.
66-
boolean flagValue = client.boolVariation(FEATURE_FLAG_KEY, context, false);
67-
showMessage("The '" + FEATURE_FLAG_KEY + "' feature flag evaluates to " + flagValue + ".");
68+
showBanner();
6869

69-
if (flagValue) {
70-
showBanner();
71-
}
72-
73-
//If this is building for CI, we don't need to keep running the Hello App continously.
74-
if(CIMode) {
70+
// If this is building for CI, we don't need to keep running the Hello App continously.
71+
if (CIMode) {
7572
System.exit(0);
7673
}
7774

7875
// We set up a flag change listener so you can see flag changes as you change
7976
// the flag rules.
80-
client.getFlagTracker().addFlagValueChangeListener(FEATURE_FLAG_KEY, context, event -> {
81-
showMessage("The '" + FEATURE_FLAG_KEY + "' feature flag evaluates to " + event.getNewValue() + ".");
82-
83-
if (event.getNewValue().booleanValue()) {
84-
showBanner();
85-
}
86-
});
77+
client
78+
.getFlagTracker()
79+
.addFlagValueChangeListener(
80+
FEATURE_FLAG_KEY,
81+
context,
82+
event -> {
83+
showMessage(
84+
"The '"
85+
+ FEATURE_FLAG_KEY
86+
+ "' feature flag evaluates to "
87+
+ event.getNewValue()
88+
+ ".");
89+
90+
if (event.getNewValue().booleanValue()) {
91+
showBanner();
92+
}
93+
});
8794
showMessage("Listening for feature flag changes.");
8895

8996
// Here we ensure that when the application terminates, the SDK shuts down
@@ -92,15 +99,19 @@ public static void main(String... args) throws Exception {
9299
// statistics may not appear on your dashboard. In a normal long-running
93100
// application, the SDK would continue running and events would be delivered
94101
// automatically in the background.
95-
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
96-
public void run() {
97-
try {
98-
client.close();
99-
} catch (IOException e) {
100-
// ignore
101-
}
102-
}
103-
}, "ldclient-cleanup-thread"));
102+
Runtime.getRuntime()
103+
.addShutdownHook(
104+
new Thread(
105+
new Runnable() {
106+
public void run() {
107+
try {
108+
client.close();
109+
} catch (IOException e) {
110+
// ignore
111+
}
112+
}
113+
},
114+
"ldclient-cleanup-thread"));
104115

105116
// Keeps example application alive.
106117
Object mon = new Object();

0 commit comments

Comments
 (0)