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);
}
}
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 Synonym
Rational Rhapsody
Was this topic helpful?
Document Information
Modified date:
27 May 2022
UID
swg21978877