-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide an equivalent of Jersey's CloseableService #31213
Comments
I wonder if we can come up with some better API. @FroMage WDYT? |
Accepting |
Just out of curiosity - what exactly does call @geoand The |
@mkouba that sounds interesting although I have not had time to look into it, but it does sound like a nice solution |
It is usually called inside the resource method if try/catch cannot be used. |
@matthias-mueller do you have any real world examples to point to? |
Ok, so you could still use the @RequestScoped
public class CloseableServices {
private final List<Closable> closables = new ArrayList();
public void add(Closable closable) {
// ...
}
@PreDestroy // this will be automatically called by the container when the request is destroyed
void destroy() {
// iterate over closables and close them
}
} and then in your resource |
Very nice @mkouba! It can also be used as |
@geoand : Have a look at the example in the first post
For testing, you can simply write a simple implementation of
In any of these cases, you don't want to have dangling I/O handles (e.g. on files or databases). |
Yeah, I would like to not have to come up with the use case, but would much rather just copy one :) |
All I have here is proprietary application code, sorry :) . |
Understood, thanks! |
@mkouba one surprising thing that I found while cooking this up is that |
Yes, that's expected because the container does not control instantiation/destruction of the bean instance (no injection, no interception, no callbacks). For a producer you'll need to provide a disposer method. |
Aha, very interesting, thanks! |
Add a way for RESTEasy Reactive to close arbitrary Closeable services
That was quick! |
⚡ |
Description
(First posted on Stackoverflow then moved to GH as suggested by @geoand)
I am migrating a REST-Service from Jersey to Quarkus/RestEasy. Jersey can inject different Context objects into the Resource classes, among them is a CloseableService that you can use to robustly handle Closeable resources, no matter what goes wrong with the request (Runtime Exceptions, Aborted Connections, etc.).
The signature of a resource method looks roughly like this:
Currently, there is no equivalent to CloseableService in Quarkus.
p.s.: I am not sure whether this really is a quarkus issue or something that should be addressed by RestEasy.
Implementation ideas
No response
The text was updated successfully, but these errors were encountered: