Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Graceful shutdown for custom connections

Hi Greg,

Thanks for the response.  In my case, I'm not using HTTP and it is Jetty 9 (so I think StatsHandler doesn't help me as it will not see my requests).  But you gave me an idea for a workaround - my thought is to create a dummy handler:

   public class ShutDownHandler extends AbstractHandler implements Graceful

Its handle() method can do nothing.  The call to shutdown() will return my own Future that starts my own shutdown process and waits for current requests to end.  My Connection implementation (unlike HttpConnection) has a flag that indicates if it is currently processing a request or not.   

I did a rough prototype and it seems to get called at the right time.  

Again, thank you for the response.

Josh







On Wed, Jan 6, 2021 at 12:12 AM Greg Wilkins <gregw@xxxxxxxxxxx> wrote:

Josh,

it is a little different in Jetty-9 vs jetty-10, but we may backport 10 changes to 9, so I will describe those.

Typically a connector does not track requests, so it is not the connector that waits for requests to drain, but the StatsHandler instead.

Any object in the component tree (the addBean, addHandler etc. on ContainerLifeCycle that is the server and it's handlers) may implement the Graceful interface and it will be called to obtain a Future that will be completed once it has gracefully shutdown.

Some components just switch to a different mode - ie responses are now sent with Connection:close so connections are not persistent, whilst others take time: eg statshandler waits for dispatched request count to go to zero

So you may need nothing more than to deploy the statshandler.  But if you have special stuff in your connector, then implement Graceful and you should be called.

cheers













On Wed, 6 Jan 2021 at 01:27, Josh Spiegel <joshlakewg@xxxxxxxxx> wrote:
Hi,

I've implemented a custom ConnectionFactory and Connection for a custom protocol (not http).  I've been using them with Server and ServerConnector.  I'd like to hook my connections into the Graceful shutdown process that is already in place.  i.e. I'd like to give my connections a chance to write final responses within the getStopTimeout() window.  

I'm not sure how I can add a Graceful instance into this process.  Does anybody know how to do this?

Thanks,
Josh


_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users


--
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top