Skip to content

Commit

Permalink
Fix issue that stream could be started before stopping when calling i…
Browse files Browse the repository at this point in the history
…dentify. (#122)
  • Loading branch information
gwhelanLD authored May 2, 2019
1 parent 2215275 commit fdede38
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void run() {
connectionInformation.getConnectionMode().toString(),
lastSuccess == null ? "Never" : new Date(lastSuccess).toString(),
lastFailure == null ? "Never" : new Date(lastFailure).toString(),
lastFailure != null ?
connectionInformation.getLastFailure() != null ?
connectionInformation.getLastFailure().getFailureType()
: "");
connection.setText(result);
Expand Down
5 changes: 0 additions & 5 deletions launchdarkly-android-client-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ android {
execution 'ANDROID_TEST_ORCHESTRATOR'
}

lintOptions {
// TODO: fix things and set this to true
abortOnError false
}

configurations {
javadocDeps
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,15 @@ private void startBackgroundPolling() {

private void stopStreaming() {
if (streamUpdateProcessor != null) {
streamUpdateProcessor.stop();
streamUpdateProcessor.stop(null);
}
}

private void stopStreaming(final Util.ResultCallback<Void> onCompleteListener) {
if (streamUpdateProcessor != null) {
streamUpdateProcessor.stop(onCompleteListener);
} else {
onCompleteListener.onSuccess(null);
}
}

Expand Down Expand Up @@ -318,13 +326,22 @@ boolean isOffline() {
return setOffline;
}

synchronized void reloadUser(Util.ResultCallback<Void> onCompleteListener) {
synchronized void reloadUser(final Util.ResultCallback<Void> onCompleteListener) {
throttler.cancel();
removeForegroundListener();
removeNetworkListener();
stopPolling();
stopStreaming();
startUp(onCompleteListener);
stopStreaming(new Util.ResultCallback<Void>() {
@Override
public void onSuccess(Void result) {
startUp(onCompleteListener);
}

@Override
public void onError(Throwable e) {
startUp(onCompleteListener);
}
});
}

private synchronized void updateConnectionMode(ConnectionMode connectionMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class StreamUpdateProcessor {

synchronized void start() {
if (!running && !connection401Error) {
stop();
Timber.d("Starting.");
Headers headers = new Headers.Builder()
.add("Authorization", LDConfig.AUTH_SCHEME + config.getMobileKeys().get(environmentName))
Expand Down Expand Up @@ -99,7 +98,7 @@ public void onError(Throwable t) {
Timber.e(e, "Client unavailable to be set offline");
}
}
stop();
stop(null);
} else {
notifier.onError(new LDInvalidResponseCodeFailure("Unexpected Response Code From Stream Connection", t, code, true));
}
Expand Down Expand Up @@ -170,7 +169,7 @@ public Void call() {
}
}

synchronized void stop() {
synchronized void stop(final Util.ResultCallback<Void> onCompleteListener) {
Timber.d("Stopping.");
if (es != null) {
// We do this in a separate thread because closing the stream involves a network
Expand All @@ -179,6 +178,9 @@ synchronized void stop() {
@Override
public void run() {
stopSync();
if (onCompleteListener != null) {
onCompleteListener.onSuccess(null);
}
}
});
}
Expand All @@ -192,15 +194,4 @@ private synchronized void stopSync() {
es = null;
Timber.d("Stopped.");
}

synchronized void restart() {
executor.execute(new Runnable() {
@Override
public void run() {
StreamUpdateProcessor.this.stopSync();
StreamUpdateProcessor.this.start();
}
});
}

}
}

0 comments on commit fdede38

Please sign in to comment.