Allow registering ContextStorage wrappers with code to avoid requirin…#2044
Conversation
…g SPI for listening to events.
Codecov Report
@@ Coverage Diff @@
## master #2044 +/- ##
=========================================
Coverage ? 85.17%
Complexity ? 1982
=========================================
Files ? 228
Lines ? 7827
Branches ? 831
=========================================
Hits ? 6667
Misses ? 848
Partials ? 312
Continue to review full report at Codecov.
|
| private static final List<Function<? super ContextStorage, ? extends ContextStorage>> wrappers = | ||
| new ArrayList<>(); | ||
|
|
||
| static synchronized void addWrapper( |
There was a problem hiding this comment.
It probably doesn't matter too much, since this class isn't public, but exposing synchronized methods is generally a bad practice, as it could allow accidental deadlocking if someone synchronizes on this class.
There was a problem hiding this comment.
Yeah figured it's ok due to the privateness but went with consistency.
|
Thanks for doing this @anuraaga I think this looks like something that would be easy to use. Would it make sense to have to be able to register a SPI similar to what is used for the contextstorage and thus instead of manually coding things the ContextStorage init code would scan the class/module path for any classes implementing the ContextStorageWrapper and add those? |
@sfriberg can you log an issue for this, if you think it's a good idea yourself? Thanks! |
…g SPI for listening to events.
@sfriberg reached out in wanting to be able to listen
ContextStorageevents without overriding the detected storage mechanism, and I think being able to register listeners with code is important in any case. It was the first feature request we got in Armeria after adding theContextStorageSPI since SPI is too tedious to just do something like pushing MDC.Fixes #922