Skip to content

Commit fdede38

Browse files
authored
Fix issue that stream could be started before stopping when calling identify. (#122)
1 parent 2215275 commit fdede38

File tree

4 files changed

+28
-25
lines changed

4 files changed

+28
-25
lines changed

example/src/main/java/com/launchdarkly/example/MainActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void run() {
5858
connectionInformation.getConnectionMode().toString(),
5959
lastSuccess == null ? "Never" : new Date(lastSuccess).toString(),
6060
lastFailure == null ? "Never" : new Date(lastFailure).toString(),
61-
lastFailure != null ?
61+
connectionInformation.getLastFailure() != null ?
6262
connectionInformation.getLastFailure().getFailureType()
6363
: "");
6464
connection.setText(result);

launchdarkly-android-client-sdk/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ android {
4040
execution 'ANDROID_TEST_ORCHESTRATOR'
4141
}
4242

43-
lintOptions {
44-
// TODO: fix things and set this to true
45-
abortOnError false
46-
}
47-
4843
configurations {
4944
javadocDeps
5045
}

launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/ConnectivityManager.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,15 @@ private void startBackgroundPolling() {
184184

185185
private void stopStreaming() {
186186
if (streamUpdateProcessor != null) {
187-
streamUpdateProcessor.stop();
187+
streamUpdateProcessor.stop(null);
188+
}
189+
}
190+
191+
private void stopStreaming(final Util.ResultCallback<Void> onCompleteListener) {
192+
if (streamUpdateProcessor != null) {
193+
streamUpdateProcessor.stop(onCompleteListener);
194+
} else {
195+
onCompleteListener.onSuccess(null);
188196
}
189197
}
190198

@@ -318,13 +326,22 @@ boolean isOffline() {
318326
return setOffline;
319327
}
320328

321-
synchronized void reloadUser(Util.ResultCallback<Void> onCompleteListener) {
329+
synchronized void reloadUser(final Util.ResultCallback<Void> onCompleteListener) {
322330
throttler.cancel();
323331
removeForegroundListener();
324332
removeNetworkListener();
325333
stopPolling();
326-
stopStreaming();
327-
startUp(onCompleteListener);
334+
stopStreaming(new Util.ResultCallback<Void>() {
335+
@Override
336+
public void onSuccess(Void result) {
337+
startUp(onCompleteListener);
338+
}
339+
340+
@Override
341+
public void onError(Throwable e) {
342+
startUp(onCompleteListener);
343+
}
344+
});
328345
}
329346

330347
private synchronized void updateConnectionMode(ConnectionMode connectionMode) {

launchdarkly-android-client-sdk/src/main/java/com/launchdarkly/android/StreamUpdateProcessor.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class StreamUpdateProcessor {
5151

5252
synchronized void start() {
5353
if (!running && !connection401Error) {
54-
stop();
5554
Timber.d("Starting.");
5655
Headers headers = new Headers.Builder()
5756
.add("Authorization", LDConfig.AUTH_SCHEME + config.getMobileKeys().get(environmentName))
@@ -99,7 +98,7 @@ public void onError(Throwable t) {
9998
Timber.e(e, "Client unavailable to be set offline");
10099
}
101100
}
102-
stop();
101+
stop(null);
103102
} else {
104103
notifier.onError(new LDInvalidResponseCodeFailure("Unexpected Response Code From Stream Connection", t, code, true));
105104
}
@@ -170,7 +169,7 @@ public Void call() {
170169
}
171170
}
172171

173-
synchronized void stop() {
172+
synchronized void stop(final Util.ResultCallback<Void> onCompleteListener) {
174173
Timber.d("Stopping.");
175174
if (es != null) {
176175
// We do this in a separate thread because closing the stream involves a network
@@ -179,6 +178,9 @@ synchronized void stop() {
179178
@Override
180179
public void run() {
181180
stopSync();
181+
if (onCompleteListener != null) {
182+
onCompleteListener.onSuccess(null);
183+
}
182184
}
183185
});
184186
}
@@ -192,15 +194,4 @@ private synchronized void stopSync() {
192194
es = null;
193195
Timber.d("Stopped.");
194196
}
195-
196-
synchronized void restart() {
197-
executor.execute(new Runnable() {
198-
@Override
199-
public void run() {
200-
StreamUpdateProcessor.this.stopSync();
201-
StreamUpdateProcessor.this.start();
202-
}
203-
});
204-
}
205-
206-
}
197+
}

0 commit comments

Comments
 (0)