Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to setup Grizzly for graceful shutdown?

I have a Jersey application running on embedded Grizzly, that is initialized like the following:

HttpServer httpServer = GrizzlyServerFactory.createHttpServer(BASE_URI, rc);

What i want to achieve is let the running requests finish when shutting down, but not let new requests in. I couldn't find a way to achieve this through public methods of HttpServer, or not even with private methods and such (although it is not nice, a solution by accessing private stuff through reflection is also ok)

Does anyone know how this is possible?

like image 787
lithium Avatar asked Sep 18 '12 14:09

lithium


1 Answers

Using Grizzly 2.3.4 it is possible; see the post on Gracefully Terminating a Grizzly Transport. In short, implement a GracefulShutdownListener registered using Transport.addShutdownListener() upon the implementation-specific transport mechanism (such as NIOTransport, TCPNIOTransport, or UDPNIOTransport).

like image 161
odiszapc Avatar answered Sep 28 '22 07:09

odiszapc