On Aug 17, 2010, at 4:45 AM, Delos wrote: > > For some reasons, we often need to know if there is a running server > instance. By establishing a connection to a specific port such as 1099, we > may get the status of server. However, the method doesn't work if default > port number is changed, especially in multi-instances scenario. In > multi-instances scenario, we hope to know if any instance is running.
I think we'd better do a better job of defining some requirements. I'm not sure I understand precisely what you're trying to accomplish. Some off-hand thoughts: 1) Users want to know when a server is up and running and ready to process user requests (at least that's what users have asked me for, in the past). So, the fact that a process has been started is probably not sufficient 2) I think most users will want information on a specific server, not *any* server 3) If determining the proper port to be used is a problem (and I think we should make this simpler), then the problem applies to any command stop-server, wait-for-server, deploy, list-modules, etc. > > Below is my thoughts about the solution. Any comments or suggestions, please > feel free to tell me. It will be appreciated if any better solution could be > provided. > > Possible solution: > > We may create flag file for each instance and lock the file with > FileChannel.lock() when a server instance is starting up. It will be > unlocked and deleted when the server is stopped. Unlocking will be > automatically done when JVM exits; deleting the file can be done in shutdown > hook in FrameworkLauncher.launch(). > > In this way, if any flag file has been locked, we may deduce that there is at > least one running server instance; if no locked files found, we may think all > server instances are stopped. We can put all the flag files in a same > directory for us to track. It's been a while since I looked at similar issues, but I'm not very trusting about how much work a Java process can be guaranteed to perform on shutdown. Normal shutdown situations work fine. But what happens when the JVM catches an abnormal signal and just exits? I'd want to see thorough testing of any file locking/file deleting technique (especially if appropriate file manipulation was required to start/restart the server). --kevan
