Skip to content

Commit 42ff3e2

Browse files
authored
Merge pull request #171 from splitio/release/4.1.3
Release/4.1.3
2 parents cf784b0 + fd3f0d5 commit 42ff3e2

File tree

7 files changed

+30
-22
lines changed

7 files changed

+30
-22
lines changed

client/CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
CHANGES
22

3+
4.1.3 (Dec 2, 2020)
4+
- Fix Issue when closing SSE Connection
5+
- Updated log-level for some messages
6+
37
4.1.2 (Nov 25, 2020)
48
- Updated junit from 4.12 to 4.13.1
59
- Updated HttpClient from 4.5.2 to 5.0.3

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>io.split.client</groupId>
77
<artifactId>java-client-parent</artifactId>
8-
<version>4.1.2</version>
8+
<version>4.1.3</version>
99
</parent>
1010
<artifactId>java-client</artifactId>
1111
<packaging>jar</packaging>

client/src/main/java/io/split/engine/sse/AuthApiClientImp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ public AuthenticationResponse Authenticate() {
4646
return getSuccessResponse(jsonContent);
4747
}
4848

49-
_log.debug(String.format("Problem to connect to : %s. Response status: %s", _target, statusCode));
49+
_log.error(String.format("Problem to connect to : %s. Response status: %s", _target, statusCode));
5050
if (statusCode >= HttpStatus.SC_BAD_REQUEST && statusCode < HttpStatus.SC_INTERNAL_SERVER_ERROR) {
5151
return new AuthenticationResponse(false,false);
5252
}
5353

5454
return new AuthenticationResponse(false,true);
5555
} catch (Exception ex) {
56-
_log.debug(ex.getMessage());
56+
_log.error(ex.getMessage());
5757
return new AuthenticationResponse(false,true);
5858
}
5959
}

client/src/main/java/io/split/engine/sse/EventSourceClientImp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@ public boolean start(String channelList, String token) {
6565
try {
6666
return _sseClient.open(buildUri(channelList, token));
6767
} catch (URISyntaxException e) {
68-
_log.debug("Error building Streaming URI: " + e.getMessage());
68+
_log.error("Error building Streaming URI: " + e.getMessage());
6969
return false;
7070
}
7171
}
7272

7373
@Override
7474
public void stop() {
7575
if (!_sseClient.isOpen()) {
76-
_log.debug("Event Source Client is closed.");
76+
_log.info("Event Source Client is closed.");
7777
return;
7878
}
7979
_sseClient.close();

client/src/main/java/io/split/engine/sse/client/SSEClient.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package io.split.engine.sse.client;
22

33
import com.google.common.base.Strings;
4+
import com.google.common.util.concurrent.ThreadFactoryBuilder;
45
import org.apache.hc.client5.http.classic.methods.HttpGet;
5-
import org.apache.hc.client5.http.config.RequestConfig;
66
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
77
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
8-
import org.apache.hc.client5.http.impl.classic.HttpClients;
9-
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
10-
import org.apache.hc.core5.util.Timeout;
118
import org.slf4j.Logger;
129
import org.slf4j.LoggerFactory;
1310

@@ -19,6 +16,8 @@
1916
import java.net.SocketException;
2017
import java.net.URI;
2118
import java.util.concurrent.CountDownLatch;
19+
import java.util.concurrent.ExecutorService;
20+
import java.util.concurrent.Executors;
2221
import java.util.concurrent.TimeUnit;
2322
import java.util.concurrent.atomic.AtomicReference;
2423
import java.util.function.Function;
@@ -45,11 +44,16 @@ private enum ConnectionState {
4544
private final static long CONNECT_TIMEOUT = 30000;
4645
private static final Logger _log = LoggerFactory.getLogger(SSEClient.class);
4746

47+
private final ExecutorService _connectionExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder()
48+
.setDaemon(true)
49+
.setNameFormat("SPLIT-SSEConnection-%d")
50+
.build());
4851
private final CloseableHttpClient _client;
4952
private final Function<RawEvent, Void> _eventCallback;
5053
private final Function<StatusMessage, Void> _statusCallback;
5154
private final AtomicReference<ConnectionState> _state = new AtomicReference<>(ConnectionState.CLOSED);
5255
private final AtomicReference<CloseableHttpResponse> _ongoingResponse = new AtomicReference<>();
56+
private final AtomicReference<HttpGet> _ongoingRequest = new AtomicReference<>();
5357

5458
public SSEClient(Function<RawEvent, Void> eventCallback,
5559
Function<StatusMessage, Void> statusCallback,
@@ -61,23 +65,21 @@ public SSEClient(Function<RawEvent, Void> eventCallback,
6165

6266
public synchronized boolean open(URI uri) {
6367
if (isOpen()) {
64-
_log.debug("SSEClient already open.");
68+
_log.info("SSEClient already open.");
6569
return false;
6670
}
6771

6872
_statusCallback.apply(StatusMessage.INITIALIZATION_IN_PROGRESS);
6973

7074
CountDownLatch signal = new CountDownLatch(1);
71-
Thread thread = new Thread(() -> connectAndLoop(uri, signal));
72-
thread.setDaemon(true);
73-
thread.start();
75+
_connectionExecutor.submit(() -> connectAndLoop(uri, signal));
7476
try {
7577
if (!signal.await(CONNECT_TIMEOUT, TimeUnit.SECONDS)) {
7678
return false;
77-
};
79+
}
7880
} catch (InterruptedException e) {
7981
Thread.currentThread().interrupt();
80-
_log.debug(e.getMessage());
82+
_log.info(e.getMessage());
8183
return false;
8284
}
8385
return isOpen();
@@ -91,9 +93,10 @@ public synchronized void close() {
9193
if (_state.compareAndSet(ConnectionState.OPEN, ConnectionState.CLOSED)) {
9294
if (_ongoingResponse.get() != null) {
9395
try {
96+
_ongoingRequest.get().abort();
9497
_ongoingResponse.get().close();
9598
} catch (IOException e) {
96-
_log.debug(String.format("Error closing SSEClient: %s", e.getMessage()));
99+
_log.info(String.format("Error closing SSEClient: %s", e.getMessage()));
97100
}
98101
}
99102
}
@@ -124,7 +127,7 @@ private void connectAndLoop(URI uri, CountDownLatch signal) {
124127
_statusCallback.apply(StatusMessage.RETRYABLE_ERROR);
125128
return;
126129
} catch (IOException exc) { // Other type of connection error
127-
_log.debug(exc.getMessage());
130+
_log.info(String.format("SSE connection ended abruptly: %s. Retying", exc.getMessage()));
128131
_statusCallback.apply(StatusMessage.RETRYABLE_ERROR);
129132
return;
130133
}
@@ -145,17 +148,18 @@ private void connectAndLoop(URI uri, CountDownLatch signal) {
145148
}
146149

147150
private boolean establishConnection(URI uri, CountDownLatch signal) {
148-
HttpGet request = new HttpGet(uri);
151+
152+
_ongoingRequest.set(new HttpGet(uri));
149153

150154
try {
151-
_ongoingResponse.set(_client.execute(request));
155+
_ongoingResponse.set(_client.execute(_ongoingRequest.get()));
152156
if (_ongoingResponse.get().getCode() != 200) {
153157
return false;
154158
}
155159
_state.set(ConnectionState.OPEN);
156160
_statusCallback.apply(StatusMessage.CONNECTED);
157161
} catch (IOException exc) {
158-
_log.debug(String.format("Error establishConnection: %s", exc));
162+
_log.error(String.format("Error establishConnection: %s", exc));
159163
return false;
160164
} finally {
161165
signal.countDown();

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>io.split.client</groupId>
66
<artifactId>java-client-parent</artifactId>
7-
<version>4.1.2</version>
7+
<version>4.1.3</version>
88
<dependencyManagement>
99
<dependencies>
1010
<dependency>

testing/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.split.client</groupId>
88
<artifactId>java-client-parent</artifactId>
9-
<version>4.1.2</version>
9+
<version>4.1.3</version>
1010
</parent>
1111

1212
<artifactId>java-client-testing</artifactId>

0 commit comments

Comments
 (0)