Search in sources :

Example 1 with IUI

use of com.github.mob41.osumer.rmi.IUI in project osumer by mob41.

the class AppMain method start.

@Override
public void start(Stage primaryStage) {
    this.primaryStage = primaryStage;
    try {
        DumpManager.init(Osumer.getVersionString(), Osumer.getVersionString());
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("DumpManager: Error initializing dump manager");
        Alert alert = new Alert(AlertType.ERROR, e.getMessage(), ButtonType.OK);
        alert.setHeaderText("Error initializing dump manager");
        alert.showAndWait();
        Platform.exit();
        System.exit(-1);
        return;
    }
    // Arg is handled by osumer-launcher
    String configPath = Osumer.isWindows() ? System.getenv("localappdata") + "\\osumerExpress" : "";
    config = new Configuration(configPath, Configuration.DEFAULT_DATA_FILE_NAME);
    try {
        config.load();
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Unable to load configuration");
        DumpManager.addDump(new DebugDump(null, "Initialize Configuration", "Load configuration from file", "Set uiSuffix", "Unable to load configuration", false, e));
        Alert alert = new Alert(AlertType.ERROR, e.getMessage(), ButtonType.OK);
        alert.setHeaderText("Could not load configuration");
        alert.showAndWait();
        DumpManager.forceMetricsReport();
        Platform.exit();
        System.exit(-1);
        return;
    }
    String uiSuffix = RMI_UI_PORT + "/" + RMI_UI_PATH;
    String daemonSuffix = RMI_DAEMON_PORT + "/" + RMI_DAEMON_PATH;
    ui = null;
    try {
        // Find any running UI
        ui = (IUI) Naming.lookup("rmi://localhost:" + uiSuffix);
    } catch (Exception ignore) {
    }
    if (ui != null) {
        try {
            ui.wake();
        } catch (RemoteException e) {
            e.printStackTrace();
            String msg = "Unable to wake up the UI:\n" + e.getMessage();
            System.err.println(msg);
            DumpManager.addDump(new DebugDump(null, "Check if ui is not null", "Call ui to wake", "Stop this UI", msg, false, e));
            Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
            alert.setHeaderText("osumer RMI Connection Error");
            alert.showAndWait();
            DumpManager.forceMetricsReport();
            Platform.exit();
            System.exit(-1);
            return;
        }
        try {
            stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return;
    }
    d = null;
    try {
        // Contact the daemon via RMI
        d = (IDaemon) Naming.lookup("rmi://localhost:" + daemonSuffix);
    } catch (Exception e) {
        e.printStackTrace();
        String msg = "Could not connect to daemon! Please ensure osumer-daemon is running properly.\n" + "Instead of starting directly with \"osumer-ui.exe\", please use \"osumer.exe\" to launch osumer.";
        System.err.println(msg);
        DumpManager.addDump(new DebugDump(null, "Set d as null", "Look for running daemon", "Create RMI Registry for UI", msg, false, e));
        Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
        alert.setHeaderText("osumer RMI Connection Error");
        alert.showAndWait();
        DumpManager.forceMetricsReport();
        Platform.exit();
        System.exit(-1);
        return;
    }
    try {
        LocateRegistry.createRegistry(RMI_UI_PORT);
        ui = new UI(this);
        Naming.bind("rmi://localhost:" + uiSuffix, ui);
    } catch (Exception e) {
        e.printStackTrace();
        String msg = "Could not register UI RMI registry on port " + RMI_UI_PORT + ":\n" + e.getMessage();
        System.err.println(msg);
        DumpManager.addDump(new DebugDump(null, "Look for running daemon", "Create RMI Registry for UI", "Register UI to daemon", msg, false, e));
        Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
        alert.setHeaderText("osumer RMI Initialization Error");
        alert.showAndWait();
        DumpManager.forceMetricsReport();
        Platform.exit();
        System.exit(-1);
        return;
    }
    try {
        d.registerUi(ui);
    } catch (RemoteException e) {
        e.printStackTrace();
        String msg = "Could not register UI to daemon\n" + e.getMessage();
        System.err.println(msg);
        DumpManager.addDump(new DebugDump(null, "Create RMI Registry for UI", "Register UI to daemon", "Set stage title", msg, false, e));
        Alert alert = new Alert(AlertType.ERROR, msg, ButtonType.OK);
        alert.setHeaderText("osumer RMI Initialization Error");
        alert.showAndWait();
        DumpManager.forceMetricsReport();
        Platform.exit();
        System.exit(-1);
        return;
    }
    primaryStage.setTitle("osumer2");
    primaryStage.getIcons().add(new Image(AppMain.class.getResourceAsStream("/image/osumerIcon_64px.png")));
    // TODO Use new parser
    osums = new OsumsOldParser();
    // osums = config.isUseOldParser() ? new OsumsOldParser() : new OsumsNewParser();
    initRootLayout();
    DumpManager.reportEvent("active", "ui");
}
Also used : Configuration(com.github.mob41.osumer.Configuration) IUI(com.github.mob41.osumer.rmi.IUI) OsumsOldParser(com.github.mob41.osums.OsumsOldParser) Alert(javafx.scene.control.Alert) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) Image(javafx.scene.image.Image) DebugDump(com.github.mob41.osumer.debug.DebugDump) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Example 2 with IUI

use of com.github.mob41.osumer.rmi.IUI in project osumer by mob41.

the class Main method runUi.

private static void runUi(Configuration config, String[] args, ArgParser ap, IDaemon d) {
    IUI ui = null;
    try {
        // Contact the ui via RMI
        ui = (IUI) Naming.lookup("rmi://localhost:46727/ui");
    } catch (Exception e) {
    }
    if (ui == null) {
        try {
            Runtime.getRuntime().exec("\"" + OsumerNative.getProgramFiles() + "\\osumer2\\osumer-ui.exe\"");
        } catch (IOException e) {
            e.printStackTrace();
            DumpManager.addDump(new DebugDump(null, "Check if \"ui\" is null", "Execute osumer-ui.exe", "Initialize \"c\" as 0", "Could not start UI. Terminating", false, e));
            DumpManager.forceMetricsReport();
            JOptionPane.showMessageDialog(null, "Could not start UI. For more details, check dump. Terminating:\n" + e, "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
            System.exit(-1);
            return;
        }
        int c = 0;
        while (c < 20) {
            try {
                // Contact the ui via RMI
                ui = (IUI) Naming.lookup("rmi://localhost:46727/ui");
            } catch (Exception e) {
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                break;
            }
            c++;
        }
    }
    if (ui == null) {
        DumpManager.addDump(new DebugDump(null, "(While-loop) Look up UI RMI", "Check if \\\"ui\\\" is null", "Try to wake up UI", false, "Could not connect to UI. Terminating"));
        DumpManager.forceMetricsReport();
        JOptionPane.showMessageDialog(null, "Could not connect to UI. For more details, check dump. Terminating", "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
        System.exit(-1);
        return;
    }
    try {
        ui.wake();
    } catch (RemoteException e) {
        e.printStackTrace();
        DumpManager.addDump(new DebugDump(null, "Check if \\\\\\\"ui\\\\\\\" is null", "Try to wake up UI", "End of runUi()", "Could not connect or wake UI", false, e));
        DumpManager.forceMetricsReport();
        JOptionPane.showMessageDialog(null, "Could not connect or wake UI. For more details, check dump:\n" + e, "osumer launcher Error", JOptionPane.ERROR_MESSAGE);
        System.exit(-1);
        return;
    }
}
Also used : IOException(java.io.IOException) IUI(com.github.mob41.osumer.rmi.IUI) RemoteException(java.rmi.RemoteException) DebugDump(com.github.mob41.osumer.debug.DebugDump) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Aggregations

DebugDump (com.github.mob41.osumer.debug.DebugDump)2 IUI (com.github.mob41.osumer.rmi.IUI)2 IOException (java.io.IOException)2 RemoteException (java.rmi.RemoteException)2 Configuration (com.github.mob41.osumer.Configuration)1 OsumsOldParser (com.github.mob41.osums.OsumsOldParser)1 Alert (javafx.scene.control.Alert)1 Image (javafx.scene.image.Image)1