Move ActorSystem shutdown logic out of SystemTray

This commit is contained in:
Chris Beams 2014-11-03 20:27:42 +01:00
parent fa7d7a08a5
commit b9e9882865
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
3 changed files with 21 additions and 19 deletions

View File

@ -43,7 +43,6 @@ import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import akka.actor.ActorSystem;
import lighthouse.files.AppDirectory;
public class BitsquareUI extends Application {
@ -110,7 +109,7 @@ public class BitsquareUI extends Application {
// configure the system tray
SystemTray systemTray = new SystemTray(primaryStage, injector.getInstance(ActorSystem.class), this);
SystemTray systemTray = new SystemTray(primaryStage, this);
primaryStage.setOnCloseRequest(e -> systemTray.hideStage());
scene.setOnKeyReleased(keyEvent -> {
if (new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN).match(keyEvent))

View File

@ -29,12 +29,20 @@ import io.bitsquare.trade.TradeModule;
import io.bitsquare.user.User;
import io.bitsquare.util.ConfigLoader;
import com.google.inject.Injector;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import akka.actor.ActorSystem;
import scala.concurrent.duration.Duration;
public class BitsquareModule extends AbstractBitsquareModule {
private static final Logger log = LoggerFactory.getLogger(BitsquareModule.class);
public BitsquareModule() {
this(ConfigLoader.loadConfig());
}
@ -77,5 +85,16 @@ public class BitsquareModule extends AbstractBitsquareModule {
protected GuiModule guiModule() {
return new GuiModule(properties);
}
@Override
protected void doClose(Injector injector) {
ActorSystem actorSystem = injector.getInstance(ActorSystem.class);
actorSystem.shutdown();
try {
actorSystem.awaitTermination(Duration.create(5L, "seconds"));
} catch (Exception ex) {
log.error("Actor system failed to shut down properly", ex);
}
}
}

View File

@ -22,8 +22,6 @@ import io.bitsquare.gui.util.ImageUtil;
import java.awt.*;
import java.util.concurrent.TimeoutException;
import javax.swing.*;
import javafx.application.Platform;
@ -32,9 +30,6 @@ import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import akka.actor.ActorSystem;
import scala.concurrent.duration.Duration;
/**
* There is no JavaFX support yet, so we need to use AWT.
*/
@ -48,14 +43,12 @@ public class SystemTray {
public static final String HIDE_WINDOW_LABEL = "Hide exchange window";
private final Stage stage;
private final ActorSystem actorSystem;
private final BitsquareUI application;
private final TrayIcon trayIcon = createTrayIcon();
private final MenuItem toggleShowHideItem = new MenuItem(HIDE_WINDOW_LABEL);
public SystemTray(Stage stage, ActorSystem actorSystem, BitsquareUI application) {
public SystemTray(Stage stage, BitsquareUI application) {
this.stage = stage;
this.actorSystem = actorSystem;
this.application = application;
init();
}
@ -102,15 +95,6 @@ public class SystemTray {
exitItem.addActionListener(e -> {
self.remove(trayIcon);
actorSystem.shutdown();
try {
actorSystem.awaitTermination(Duration.create(5L, "seconds"));
} catch (Exception ex) {
if (ex instanceof TimeoutException)
log.error("ActorSystem did not shutdown properly.");
else
log.error(ex.getMessage());
}
try {
application.stop();
} catch (Exception ex) {