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

Commit 3a35a77

Browse files
committed
Bump to a non-snapshot release. Name the heartbeat thread.
1 parent 654ea58 commit 3a35a77

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dependencies {
3232
compile "com.google.guava:guava:19.0"
3333
compile "joda-time:joda-time:2.9.3"
3434
compile "org.slf4j:slf4j-api:1.7.21"
35-
compile group: "com.launchdarkly", name: "okhttp-eventsource", version: "1.0.0-SNAPSHOT", changing: true
35+
compile group: "com.launchdarkly", name: "okhttp-eventsource", version: "1.0.0", changing: true
3636
compile "redis.clients:jedis:2.8.1"
3737
testCompile "org.easymock:easymock:3.4"
3838
testCompile 'junit:junit:4.12'

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.launchdarkly.client;
22

3+
import com.google.common.util.concurrent.ThreadFactoryBuilder;
34
import com.google.gson.Gson;
45
import com.launchdarkly.eventsource.EventHandler;
56
import com.launchdarkly.eventsource.EventSource;
@@ -12,10 +13,7 @@
1213

1314
import java.io.IOException;
1415
import java.net.URI;
15-
import java.util.concurrent.Executors;
16-
import java.util.concurrent.Future;
17-
import java.util.concurrent.ScheduledExecutorService;
18-
import java.util.concurrent.TimeUnit;
16+
import java.util.concurrent.*;
1917
import java.util.concurrent.atomic.AtomicBoolean;
2018

2119
class StreamProcessor implements UpdateProcessor {
@@ -32,7 +30,7 @@ class StreamProcessor implements UpdateProcessor {
3230
private final String sdkKey;
3331
private final FeatureRequestor requestor;
3432
private final ScheduledExecutorService heartbeatDetectorService;
35-
private DateTime lastHeartbeat;
33+
private volatile DateTime lastHeartbeat;
3634
private volatile EventSource es;
3735
private AtomicBoolean initialized = new AtomicBoolean(false);
3836

@@ -42,7 +40,10 @@ class StreamProcessor implements UpdateProcessor {
4240
this.config = config;
4341
this.sdkKey = sdkKey;
4442
this.requestor = requestor;
45-
this.heartbeatDetectorService = Executors.newScheduledThreadPool(1);
43+
ThreadFactory threadFactory = new ThreadFactoryBuilder()
44+
.setNameFormat("LaunchDarkly-HeartbeatDetector-%d")
45+
.build();
46+
this.heartbeatDetectorService = Executors.newSingleThreadScheduledExecutor(threadFactory);
4647
heartbeatDetectorService.scheduleAtFixedRate(new HeartbeatDetector(), 1, 1, TimeUnit.MINUTES);
4748
}
4849

@@ -200,8 +201,10 @@ private final class HeartbeatDetector implements Runnable {
200201

201202
@Override
202203
public void run() {
203-
DateTime fiveMinutesAgo = DateTime.now().minusSeconds(DEAD_CONNECTION_INTERVAL_SECONDS);
204-
if (lastHeartbeat.isBefore(fiveMinutesAgo) && es.getState() == ReadyState.OPEN) {
204+
DateTime reconnectThresholdTime = DateTime.now().minusSeconds(DEAD_CONNECTION_INTERVAL_SECONDS);
205+
// We only want to force the reconnect if the ES connection is open. If not, it's already trying to
206+
// connect anyway, or this processor was shut down
207+
if (lastHeartbeat.isBefore(reconnectThresholdTime) && es.getState() == ReadyState.OPEN) {
205208
try {
206209
logger.info("Stream stopped receiving heartbeats- reconnecting.");
207210
es.close();

0 commit comments

Comments
 (0)