You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by bh...@apache.org on 2010/12/03 22:21:35 UTC
svn commit: r1042010 -
/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceController.java
Author: bhavani
Date: Fri Dec 3 21:20:47 2010
New Revision: 1042010
URL: http://svn.apache.org/viewvc?rev=1042010&view=rev
Log:
UIMA-1963 fixed shutdown hook so that C++ process is stopped when Java process is killed.
Modified:
uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceController.java
Modified: uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceController.java
URL: http://svn.apache.org/viewvc/uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceController.java?rev=1042010&r1=1042009&r2=1042010&view=diff
==============================================================================
--- uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceController.java (original)
+++ uima/uima-as/trunk/uimaj-as-core/src/main/java/org/apache/uima/aae/controller/UimacppServiceController.java Fri Dec 3 21:20:47 2010
@@ -71,7 +71,7 @@ public class UimacppServiceController ex
private Socket commandConnection;
- private Process uimacppProcess;
+ protected Process uimacppProcess;
private LoggerHandler loggerHandler;
@@ -97,7 +97,7 @@ public class UimacppServiceController ex
private org.apache.uima.util.Logger uimaLogger;
- private UimacppServiceManagement mbean;
+ protected UimacppServiceManagement mbean;
private JmxManagement jmxMgmt;
@@ -558,8 +558,13 @@ public class UimacppServiceController ex
}
builder.directory(startingDir);
}
-
+ /* add the shutdown hook */
+ shutdownHook = new UimacppShutdownHook(this, commandConnection, uimaLogger);
+ Runtime.getRuntime().addShutdownHook(shutdownHook);
+
+ /* fork the C++ process */
uimacppProcess = builder.start();
+
if (uimacppProcess == null) {
throw new UIMAException(new Throwable("Could not fork process."));
}
@@ -583,10 +588,6 @@ public class UimacppServiceController ex
}
}
- /* add the shutdown hook */
- shutdownHook = new UimacppShutdownHook(uimacppProcess, commandConnection, uimaLogger);
- Runtime.getRuntime().addShutdownHook(shutdownHook);
-
if (uimacppProcess != null) {
// wait for C++ process to report initialization status.
System.out.println("Waiting for Uima C++ service to report init status...");
@@ -1060,18 +1061,31 @@ class WaitThread implements Runnable {
*/
class UimacppShutdownHook extends Thread {
- public Process uimacppProcess;
-
+ public UimacppServiceController controller;
+
private org.apache.uima.util.Logger uimaLogger;
+
- public UimacppShutdownHook(Process aprocess, Socket socket, org.apache.uima.util.Logger logger)
+ public UimacppShutdownHook(UimacppServiceController controller, Socket socket, org.apache.uima.util.Logger logger)
throws IOException {
- this.uimacppProcess = aprocess;
+ this.controller = controller;
this.uimaLogger = logger;
}
public void run() {
uimaLogger.log(Level.INFO, "UimacppShutdownHook sending shutdown message.");
- uimacppProcess.destroy();
+ if (controller.mbean != null)
+ try {
+ System.out.println("UimacppShutdownHook sending quiesce message");
+ controller.mbean.quiesceAndShutdown();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ if (controller.uimacppProcess != null) {
+ System.out.println("UimacppShutdownHook destroy C++ process");
+ controller.uimacppProcess.destroy();
+ }
}
} // shutdownhook