I don’t know integrant, but I’m assuming it defines a tree-like system? Wouldn’t that naturally fit with having it reverse shutdown up to a node and restart?
But to be honest, I think the mistake here is treating the connection as a singleton, you probably want a connection per-request, not a connection per-component.
So on each request simply acquire a working connection (new one or from a pool) and inject it down, and release it at the end of the request.
Edit: Well I see in the doc it mentions:
Both init
and halt!
can take a second argument of a collection of keys. If this is supplied, the functions will only initiate or halt the supplied keys (and any referenced keys).
So it seems you can selectively halt! and init! specific parts of the system.
I think the challenge is how do you handle transient requests and incoming requests while you’re resetting a part of the system.
Maybe jetty depends on a handler, the handler depends on a Cassandra connection pool, you’ve got ongoing requests being handled by jetty, one of them throws an error on stale connection, you’d want to halt! the pool and init! it again…
That means halt! would go in reverse order, so halt jetty, halt the handlers, halt the pool. Then init! would init the pool, init the handler, init jetty.
You’d need to make sure that your jetty component when halted gracefully terminates all requests, there might be a weird deadlock against the request which called halt!
to begin with, probably you want it doing that in a background task, so it could return to jetty.
So jetty component would wait for all enqueued requests to terminate, then shut itself down, during that time you’ll probably time-out to all incoming requests, or something there might break, etc.
I’m thinking a supervisor chain like that might be to coarse maybe?
Seems it be simpler to have a connection provider like someone before said, and each request can try to acquire a connection themselves and retry to do so until they get a good one or failed too many times. Only in the latter “fail all retries” would you might want to do a full halt! and init! to recover.