Skip to content
Snippets Groups Projects
Commit 94b245e9 authored by Sebastian Kürten's avatar Sebastian Kürten
Browse files

Improve concurrency safety

parent 747a85b5
No related branches found
No related tags found
1 merge request!6ViewModel cleanup
......@@ -11,6 +11,7 @@ import org.briarproject.hotspot.HotspotState.StartingHotspot;
import java.util.logging.Logger;
import androidx.annotation.NonNull;
import androidx.annotation.UiThread;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
......@@ -110,17 +111,18 @@ public class MainViewModel extends AndroidViewModel
@Override
public void onWebServerStarted() {
webServerStatus.setValue(STARTED);
webServerStatus.postValue(STARTED);
}
@Override
@UiThread
public void onWebServerStopped() {
webServerStatus.setValue(STOPPED);
}
@Override
public void onWebServerError() {
webServerStatus.setValue(ERROR);
webServerStatus.postValue(ERROR);
}
}
......@@ -5,6 +5,8 @@ import android.content.Context;
import java.io.IOException;
import java.util.logging.Logger;
import androidx.annotation.UiThread;
import static java.util.logging.Level.WARNING;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.hotspot.LogUtils.logException;
......@@ -15,6 +17,7 @@ class WebServerManager {
void onWebServerStarted();
@UiThread
void onWebServerStopped();
void onWebServerError();
......@@ -33,13 +36,16 @@ class WebServerManager {
}
void startWebServer() {
try {
webServer.start();
// TODO: offload this to the IoExecutor
new Thread(() -> {
try {
webServer.start();
} catch (IOException e) {
logException(LOG, WARNING, e);
listener.onWebServerError();
}
listener.onWebServerStarted();
} catch (IOException e) {
logException(LOG, WARNING, e);
listener.onWebServerError();
}
}).start();
}
void stopWebServer() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment