Reputation: 570
I have written tcp server using spring integration. Thanks to excellent sample https://github.com/spring-projects/spring-integration-samples/tree/master/basic/tcp-client-server Sample server stops if the user pressed q on the console.
TCP Server is a stand alone application and runs perfectly fine accepting requests and sending responses. I would like to add orderly shutdown of the server because Console access is not possible if the server is started as a background process.
is there a way for the server to wait for events? If the shutdown event comes then I can call applicationContext.stop().
I would appreciate if you can suggest any ideas on orderly shutdown process.
Thanks
Upvotes: 2
Views: 305
Reputation: 174504
I am not sure what kind of "event" you are talking about but there are a number of things you can do.
If you enable JMX, the IntegrationMBeanExporter
provides for orderly shutdown.
In the case of TCP, this stops it from accepting new connections, drops any new requests and gives you time to wait for any in-process requests to terminate).
You can use a control-bus to send a stop request to the inbound endpoint.
The source for the control bus message could be anything you want - another tcp adapter...
telnet 123.123.123.123
bar.stop()
or using any other messaging technology.
Or you could just use the OS to kill the JVM.
Upvotes: 1