Skip to content

Commit 62cf680

Browse files
committed
added new sseClient status: FORCED_STOP
1 parent 1551fcf commit 62cf680

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

client/src/main/java/io/split/engine/common/SyncManagerImp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ private void startPollingMode() {
110110
_pushManager.start();
111111
break;
112112
case STREAMING_OFF:
113-
_pushManager.stop();
113+
_pushManager.stopWorkers();
114114
_synchronizer.startPeriodicFetching();
115115
if (null != _pushStatusMonitorTask) {
116116
_pushStatusMonitorTask.cancel(false);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ private AuthenticationResponse getSuccessResponse(String jsonContent) {
7272
expiration = response.getExpiration();
7373
}
7474

75-
return new AuthenticationResponse(response.isPushEnabled(), response.getToken(), channels, 3000/*expiration*/, false);
75+
return new AuthenticationResponse(response.isPushEnabled(), response.getToken(), channels, expiration, false);
7676
}
7777
}

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public synchronized void reset() {
3333

3434
@Override
3535
public void handleSseStatus(SSEClient.StatusMessage newStatus) {
36-
_log.debug(String.format("handleSseStatus new status: %s", newStatus.toString()));
37-
_log.debug(String.format("handleSseStatus current status: %s", _sseStatus.get().toString()));
36+
_log.debug(String.format("Current status: %s. New status: %s", _sseStatus.get().toString(), newStatus.toString()));
37+
3838
switch(newStatus) {
3939
case CONNECTED:
4040
if (_sseStatus.compareAndSet(SSEClient.StatusMessage.INITIALIZATION_IN_PROGRESS, SSEClient.StatusMessage.CONNECTED)
@@ -53,6 +53,13 @@ public void handleSseStatus(SSEClient.StatusMessage newStatus) {
5353
_statusMessages.offer(PushManager.Status.STREAMING_OFF);
5454
}
5555
break;
56+
case FORCED_STOP:
57+
if (_sseStatus.compareAndSet(SSEClient.StatusMessage.CONNECTED, SSEClient.StatusMessage.FORCED_STOP)
58+
|| _sseStatus.compareAndSet(SSEClient.StatusMessage.RETRYABLE_ERROR, SSEClient.StatusMessage.FORCED_STOP)
59+
|| _sseStatus.compareAndSet(SSEClient.StatusMessage.INITIALIZATION_IN_PROGRESS, SSEClient.StatusMessage.FORCED_STOP)) {
60+
_statusMessages.offer(PushManager.Status.STREAMING_DOWN);
61+
}
62+
break;
5663
case INITIALIZATION_IN_PROGRESS: // Restore initial status
5764
reset();
5865
break;
@@ -62,6 +69,7 @@ public void handleSseStatus(SSEClient.StatusMessage newStatus) {
6269
@Override
6370
public void handleIncomingControlEvent(ControlNotification controlNotification) {
6471
_log.debug(String.format("handleIncomingOccupancyEvent: %s", controlNotification.getControlType()));
72+
6573
if (_backendStatus.get().equals(ControlType.STREAMING_DISABLED)) {
6674
return;
6775
}
@@ -88,6 +96,7 @@ public void handleIncomingControlEvent(ControlNotification controlNotification)
8896
@Override
8997
public void handleIncomingOccupancyEvent(OccupancyNotification occupancyNotification) {
9098
_log.debug(String.format("handleIncomingOccupancyEvent: publishers=%d", occupancyNotification.getMetrics().getPublishers()));
99+
91100
int publishers = occupancyNotification.getMetrics().getPublishers();
92101
if (publishers <= 0 && _publishersOnline.compareAndSet(true, false) && _backendStatus.get().equals(ControlType.STREAMING_RESUMED)) {
93102
_statusMessages.offer(PushManager.Status.STREAMING_DOWN);
@@ -99,6 +108,7 @@ public void handleIncomingOccupancyEvent(OccupancyNotification occupancyNotifica
99108
@Override
100109
public void handleIncomingAblyError(ErrorNotification notification) {
101110
_log.debug(String.format("handleIncomingAblyError: %s", notification.getMessage()));
111+
102112
if (_backendStatus.get().equals(ControlType.STREAMING_DISABLED)) {
103113
return; // Ignore
104114
}
@@ -113,6 +123,7 @@ public void handleIncomingAblyError(ErrorNotification notification) {
113123
@Override
114124
public synchronized void forcePushDisable() {
115125
_log.debug("forcePushDisable");
126+
116127
_publishersOnline.set(false);
117128
_sseStatus.set(SSEClient.StatusMessage.INITIALIZATION_IN_PROGRESS);
118129
_backendStatus.set(ControlType.STREAMING_DISABLED);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.split.engine.sse.client;
22

33
import com.google.common.base.Strings;
4-
import io.split.engine.sse.exceptions.EventParsingException;
54
import org.apache.http.client.config.RequestConfig;
65
import org.apache.http.client.methods.CloseableHttpResponse;
76
import org.apache.http.client.methods.HttpGet;
@@ -32,7 +31,8 @@ public enum StatusMessage {
3231
CONNECTED,
3332
RETRYABLE_ERROR,
3433
NONRETRYABLE_ERROR,
35-
INITIALIZATION_IN_PROGRESS
34+
INITIALIZATION_IN_PROGRESS,
35+
FORCED_STOP
3636
}
3737

3838
private enum ConnectionState {
@@ -117,7 +117,7 @@ private void connectAndLoop(URI uri, CountDownLatch signal) {
117117
_statusCallback.apply(StatusMessage.RETRYABLE_ERROR);
118118
} catch (SocketException exc) { // Connection closed by us
119119
if ("Socket closed".equals(exc.getMessage())) {
120-
_statusCallback.apply(StatusMessage.NONRETRYABLE_ERROR);
120+
_statusCallback.apply(StatusMessage.FORCED_STOP);
121121
return;
122122
}
123123

0 commit comments

Comments
 (0)