BlockhoundIntegration SPI plugins ordering #327
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The BlockHound.loadIntegration() method is intended to control ordering of
BlockhoundIntegration.applyTo
calls with respect to other integrations plugins. So, loadIntegrations() first loads all SPI plugins from META-INF/services, then appends any optional plugins provided in the loadIntegration(...) arguments, and finally sort the list before invoking the plugins applyTo methods.However, by default, the BlockhoundIntegration.compareTo is implemented like this:
So, let's say we have these integration plugins being loaded from META-INF/services/... using the BlockHound.loadIntegrations() method:
Now, let's say one want to install two more SPI integration plugin I3,I4; but ensuring the following:
then one could write this:
The problem is that it does not work because CompareTo method is not transitive: when sorting, if
I1.compareTo(OrderedPlugin)
is called, then 0 is returned, hence we can't really sort the list like we want.as a work around, you need to programatically install I3, I4, like this: this will ensure that plugins will be applied in desired order: I1, I2, I3, I4, but you then can't declare I3, I4 as SPI plugins.
now, @johnrengelman suggests a simple patch from #273: in BlockHoundIntegration, introduce a new
getPriority
method that is called by default by thecompareTo
method:This resolves the issue, and plugins can simply refine the getPriority() method is they want to take control on the order, else , by default, plugins applyTo methods will be called in the order on which plugins are loaded (natural ordering).
One thing: in netty, the BlockHound integration is overriding the compareTo method , so, for completeness, a PR should be done on netty asking to not override the compareTo method.
Fixes #273