Skip to main content
Jun 11, 2025 6:32 PM UTC
Question

Java AddingActionListener to Terminate Creo Session Not Working

Hi everyone,

 

I am working in Java with Creo's OTK, and through JLink, I was able to connect to the currently running Creo Session. I want to add an ActionListener to my session object that detects when the session terminates. So far, I have this:

class CreoTerminationListener extends ActionListener_u implements AsyncActionListener {
@Override
public void OnTerminate(TerminationStatus terminationStatus) {
System.out.println("Termination detected!");
}
}

After loading in the pfcasyncmt library, I retrieve the session as such:

AsyncConnection async = null;
try {
async = pfcAsyncConnection.AsyncConnection_Connect(null, null, null, 5);
} catch (Exception e) {
System.err.println(e);
}
if (async == null) {
System.err.println("Async connection to Creo not established!");
return;
}
Session sess = async.GetSession();
creoTerminationListener = new CreoTerminationListener();
sess.AddActionListener(creoTerminationListener);

Then, I start an HTTP server through Creoson which communicates with the Creo client. My goal is to automate the termination of the Creoson server by detecting that the active Creo session has terminated, but as of right now, when I terminate the Creo session, nothing happens. There are no errors or anything either, which leads me to think the listener isn't picking anything up, Am I setting up the Action Listener wrong, or is there something else that I'm doing incorrectly? Any feedback will be greatly appreciated!

4 replies

Jun 11, 2025 7:55 PM UTC

By the way, something I forgot to mention was that my Creo session is not running in asynchronous mode. If that's what's causing the problem then is there an alternative solution to detecting when the Creo session shuts down so that I can dynamically shut down my HTTP server?

Jun 12, 2025 2:31 PM UTC

In your asynchronous event loop you could use 

 

extern ProError ProEngineerStatusGet( void );
/*
Purpose: Determines whether the application is currently connected to a
Creo Parametric session, and if that session is responding to
requests.

Input Arguments:
None

Output Arguments:
None


Return Values:
PRO_TK_NO_ERROR - The Creo Parametric session is available.
PRO_TK_GENERAL_ERROR - There was no Creo Parametric session available, or
the session did not respond.

*/

Jun 12, 2025 2:53 PM UTC

Thanks for the reply. Your suggestion only applies in C++ right? I'm working in Java, and I don't think ProEngineerStatusGet() is a valid API for me.