I used Runtime.getRuntime().exec() to start external program in GREG handler, and get its pid. But how I can detect when the GREG stopping or restarting , that I can stop or restart the external program.
2 Answers
There is no documented mechanism of doing this. There are some internal mechanisms within the OSGi space where the components can define dependancies to detest if those are started. However, I do not think those are exposed to handler API.
One way to do is to check if you can access a resource successfully from within the handler, and if so, then start the program.

- 1,012
- 1
- 10
- 19
If you want to do execute some custom logic during startup or shutdown phases you can use handlers provided in org.wso2.carbon.core package
e.g.
ServerStartupHandler - https://github.com/wso2/carbon-kernel/blob/4.4.x/core/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/ServerStartupHandler.java
ServerShutdownHandler - https://github.com/wso2/carbon-kernel/blob/4.4.x/core/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/ServerShutdownHandler.java
ServerRestartHandler - https://github.com/wso2/carbon-kernel/blob/4.4.x/core/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/ServerRestartHandler.java
Also you may use https://github.com/wso2/carbon-kernel/blob/4.4.x/core/org.wso2.carbon.core/src/main/java/org/wso2/carbon/core/ServerStartupObserver.java to listen to startup events

- 5,666
- 4
- 42
- 69