cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

Translate the entire conversation x

Java AddingActionListener to Terminate Creo Session Not Working

AT_13484045
3-Newcomer

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 4

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?

RPN
17-Peridot
17-Peridot
(To:AT_13484045)

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.

*/

AT_13484045
3-Newcomer
(To:RPN)

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.

RPN
17-Peridot
17-Peridot
(To:AT_13484045)

But I guess theirs is a similar call in Java. At the end it is the same, regardless of the API. 
Do you have your own event loop? Or is the loop automatically given on Connect, what I don’t believe. Your session may idle after connecting. 

Announcements


Top Tags