Search in sources :

Example 11 with Configuration

use of com.github.mob41.osumer.Configuration 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)

Example 12 with Configuration

use of com.github.mob41.osumer.Configuration in project osumer by mob41.

the class PreferencesController method applyChanges.

private void applyChanges() {
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(AppMain.class.getResource("/view/ProgressDialogLayout.fxml"));
    DialogPane progressPane = null;
    try {
        progressPane = (DialogPane) loader.load();
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    ProgressDialogController progressController = loader.getController();
    progressController.getHeaderText().setText("Applying Changes");
    progressController.getStatusText().setText("Status: Writing configuration...");
    progressController.getProgressBar().setProgress(-1);
    Alert progressDialog = new Alert(AlertType.NONE);
    progressDialog.initStyle(StageStyle.UTILITY);
    progressDialog.initModality(Modality.APPLICATION_MODAL);
    progressDialog.setTitle("");
    progressDialog.setDialogPane(progressPane);
    progressDialog.getButtonTypes().add(ButtonType.CANCEL);
    Thread thread = new Thread() {

        public void run() {
            try {
                config.write();
            } catch (IOException e) {
                e.printStackTrace();
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        progressDialog.close();
                        Alert alert = new Alert(AlertType.ERROR, "Could not write configuration:\n" + e.getMessage(), ButtonType.OK);
                        alert.showAndWait();
                    }
                });
            }
            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    progressController.getStatusText().setText("Status: Reloading daemon configuration...");
                }
            });
            try {
                d.reloadConfiguration();
            } catch (Exception e) {
                e.printStackTrace();
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        progressDialog.close();
                        Alert alert = new Alert(AlertType.ERROR, "Could not reload daemon configuration:\n" + e.getMessage(), ButtonType.OK);
                        alert.showAndWait();
                    }
                });
            }
            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    progressDialog.close();
                }
            });
        }
    };
    thread.start();
    progressDialog.showAndWait();
}
Also used : DialogPane(javafx.scene.control.DialogPane) Alert(javafx.scene.control.Alert) IOException(java.io.IOException) FXMLLoader(javafx.fxml.FXMLLoader) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) WithDumpException(com.github.mob41.osumer.debug.WithDumpException)

Aggregations

IOException (java.io.IOException)11 DebugDump (com.github.mob41.osumer.debug.DebugDump)4 RemoteException (java.rmi.RemoteException)4 Configuration (com.github.mob41.osumer.Configuration)3 Alert (javafx.scene.control.Alert)3 DebuggableException (com.github.mob41.organdebug.exceptions.DebuggableException)2 WithDumpException (com.github.mob41.osumer.debug.WithDumpException)2 IUI (com.github.mob41.osumer.rmi.IUI)2 SockThread (com.github.mob41.osumer.sock.SockThread)2 ErrorDumpDialog (com.github.mob41.osumer.ui.ErrorDumpDialog)2 AWTException (java.awt.AWTException)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 PrintWriter (java.io.PrintWriter)2 MalformedURLException (java.net.MalformedURLException)2 JFXPanel (javafx.embed.swing.JFXPanel)2 FXMLLoader (javafx.fxml.FXMLLoader)2 DialogPane (javafx.scene.control.DialogPane)2 DebugDump (com.github.mob41.organdebug.DebugDump)1