Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 43bea6b

Browse files
committed
Merge pull request #10 from launchdarkly/jko/flush
Add a flush function, and make close call flush.
2 parents 2e78ed4 + a8deb66 commit 43bea6b

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repositories {
1111

1212
allprojects {
1313
group = 'com.launchdarkly'
14-
version = "0.4.0"
14+
version = "0.4.1"
1515
sourceCompatibility = 1.6
1616
targetCompatibility = 1.6
1717
}

src/main/java/com/launchdarkly/client/EventProcessor.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ class EventProcessor implements Closeable {
2121
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new DaemonThreadFactory());
2222
private final BlockingQueue<Event> queue;
2323
private final String apiKey;
24+
private final Consumer consumer;
2425

2526
EventProcessor(String apiKey, LDConfig config) {
2627
this.apiKey = apiKey;
2728
this.queue = new ArrayBlockingQueue<Event>(config.capacity);
28-
this.scheduler.scheduleAtFixedRate(new Consumer(config), 0, config.flushInterval, TimeUnit.SECONDS);
29+
this.consumer = new Consumer(config);
30+
this.scheduler.scheduleAtFixedRate(consumer, 0, config.flushInterval, TimeUnit.SECONDS);
2931
}
3032

3133
boolean sendEvent(Event e) {
@@ -35,6 +37,11 @@ boolean sendEvent(Event e) {
3537
@Override
3638
public void close() throws IOException {
3739
scheduler.shutdown();
40+
this.flush();
41+
}
42+
43+
public void flush() {
44+
this.consumer.flush();
3845
}
3946

4047
static class DaemonThreadFactory implements ThreadFactory {
@@ -59,6 +66,10 @@ class Consumer implements Runnable {
5966

6067
@Override
6168
public void run() {
69+
flush();
70+
}
71+
72+
public void flush() {
6273
List<Event> events = new ArrayList<Event>(queue.size());
6374
queue.drainTo(events);
6475

src/main/java/com/launchdarkly/client/LDClient.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.Closeable;
2121
import java.io.IOException;
2222
import java.lang.reflect.Type;
23-
import java.net.URI;
2423
import java.net.URL;
2524
import java.util.jar.Attributes;
2625
import java.util.jar.Manifest;
@@ -241,6 +240,9 @@ public void close() throws IOException {
241240
this.eventProcessor.close();
242241
}
243242

243+
public void flush() {
244+
this.eventProcessor.flush();
245+
}
244246

245247
/**
246248
* Puts the LaunchDarkly client in offline mode.

0 commit comments

Comments
 (0)