-
-
Notifications
You must be signed in to change notification settings - Fork 797
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
fix external pool pluggability #1106
Conversation
@@ -41,7 +45,7 @@ private void checkBufferRecyclerPoolImpl(BufferRecyclerPool pool, boolean checkP | |||
|
|||
if (checkPooledResource) { | |||
// acquire the pooled BufferRecycler again and check if it is the same instance used before | |||
BufferRecycler pooledBufferRecycler = pool.acquireBufferRecycler(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance we could verify life-cycle without directly calling internal method(s)?
@mariofusco Ok, just to make sure I understand: your concern is that expecting external implementations to know not just to acquire (possibly) pooled I think I'll change the naming/structure a bit though: sort of reversing naming you suggest. So externally called (public) method remains what it was, and we'll just introduce another protected method... oh shoot. Interfaces don't allow protected. This is actually one reason to prefer abstract classes. |
@mariofusco Apologies for significant rewrite here; I realized I'd want to hide the new internal method, expose existing Acquire-method, and things went bit further from there. |
That's entirely correct. Also consider that the |
Hi @cowtowncoder, you understood correctly the reasons why I sent this pull request, but in all honesty there are 2 things that I don't like with your changes. The first one (ugly but I could live with this) is that now you're asking to external pool implementors to extend an abstract class instead of implementing an interface. This is a bit limiting due to Java single inheritance (implementors may want for instance to extend an existing data structure, maybe taken from an external library and just implement the The second one (even worse than the other) is the asymmetry imposed to a pool implementor that when extending your abstract class now has to implement 2 methods: In essence my point of view is the following: designing an API sometimes requires some trade-off and when you need to do so it is clearly better to accept some inconvenience to the private part of the API, leaving a nicer look to the public part. I believe that in this case you mistakenly swap those private and public parts. In this situation the public part (what the user is supposed to do) is developing a new implementation of the pool, while the private part (what Please let me know if my analysis makes sense. |
@cowtowncoder This is an alternative solution. Let me know which one you prefer. |
Hmmh. Interesting suggestion wrt private vs public part. To me, public part is the thing called from external entity, in this case jackson-core components ( Abstract class vs interface is trickier: I really dislike full public-ness of Let me think about this for a moment. |
Ok. I prefer this approach.
Possible naming for 2 acquire-related methods:
Alternatively we could also always use default impl for (2): even if no recycling occurs it's fine to call "release"-method as pool will just ignore it. If I have time today I will do changes above. |
What you're suggesting is not that far from my original implementation, so ok for me. I will wait for your changes and give one final review. Let me know if I could do something else. |
@mariofusco Thank you & sorry for the mess. I should have discussed my idea before making changes here. |
@mariofusco Ok, here you go. Please make any changes you think are needed, let me know once this is ready to be merged from your perspective. |
src/main/java/com/fasterxml/jackson/core/util/BufferRecyclerPool.java
Outdated
Show resolved
Hide resolved
This looks almost identical to my original implementation with the only (relevant and nice) difference that the method that I called I'm happy with this so please feel free to merge this pull request asap. I will close the other pull request implementing my alternative solution. |
Done; merged into 2.16, forward to master (3.0); all tests passing. Also realized that 2 of dataformats have |
And https://github.com/FasterXML/jackson-jaxrs-providers/blob/f8dd37d5a263886b476c86f60bc6970ed6de99fc/base/src/main/java/com/fasterxml/jackson/jaxrs/cfg/ObjectWriterInjector.java#L16 (plus its jakarta fork) And yaml format too - https://github.com/search?q=repo%3AFasterXML%2Fjackson-dataformats-text+ThreadLocal+language%3AJava&type=code&l=Java |
Trying to plug external pools from Quarkus I found that I made a terrible mistake so that external pools are never registered on the pooled
BufferRecycler
and then it never gets released to the pool. This pull request is intended to fix this bug.@cowtowncoder @pjfanning Sorry about this, but please try to give it the highest possible priority. Let me know if you have any question.
/cc @franz1981