IBM Support

How to manage the Rhapsody process from within a JavaFX application

Question & Answer


Question

How do I properly terminate the IBM Rational Rhapsody process from within a JavaFX application?

Cause

You have observed that the Rhapsody process does not terminate when:

  • Closing the JavaFX application via its window close button
  • Using the Rhapsody API method IRPApplication.quit()

Answer

You should call both IRPApplication.quit() and RhapsodyAppServer.CloseSession() methods to properly terminate the Rhapsody process and the RhapsodyAppServer session.

You can also use the JavaFX EventHandler interface so that the above methods are called when the "X" close button is clicked in the window user interface.


package application;

import com.telelogic.rhapsody.core.IRPApplication;
import com.telelogic.rhapsody.core.RhapsodyAppServer;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import javafx.stage.WindowEvent;


public class Main extends Application {

IRPApplication app = null;

@Override
public void start(Stage primaryStage) {
try {
// create Rhapsody session and IRPApplication object
app = RhapsodyAppServer.createRhapsodyApplication();

BorderPane root = new BorderPane();
Scene scene = new Scene(root,400,400);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
if (app != null) {
primaryStage.setTitle("Connected to Rhapsody (" + app.getBuildNo() + ")");
}
primaryStage.show();

// Window OnClose event
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent we) {
// close the Rhapsody application object
app.quit();
// terminate the Rhapsody session
RhapsodyAppServer.CloseSession();

}
});
}
catch(Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
// launch the JavaFX Application object
launch(args);
}
}

Disclaimer:

All source code and/or binaries attached to this document are referred to here as "the Program". IBM is not providing program services of any kind for the Program. IBM is providing the Program on an "AS IS" basis without warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL, DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM, OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

[{"Product":{"code":"SSB2MU","label":"IBM Engineering Systems Design Rhapsody"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Integrations - 3rd Party","Platform":[{"code":"PF016","label":"Linux"},{"code":"PF033","label":"Windows"}],"Version":"8.0;8.0.1;8.0.2;8.0.3;8.0.4;8.0.5;8.0.6;8.1;8.1.1;8.1.2;8.1.2.1;8.1.3;8.1.4","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

Product Synonym

Rational Rhapsody

Document Information

Modified date:
27 May 2022

UID

swg21978877