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
Replace Optional with Spring's ObjectProvider to manage the optionali… #5573
Conversation
c163eda
to
5814bea
Compare
…ty of injection points more clearly.
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.
Nice 👍 Left a super-nit optional comment. Thanks for the quick fix @kratosmy 🙇 👍 🙇
if (!armeriaServerConfigurators.stream().findAny().isPresent() && | ||
!armeriaServerBuilderConsumers.stream().findAny().isPresent()) { |
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.
Optional) Not strong on this, but intelliJ is complaining and generally inverse conditions are slightly harder to reason about (although I think this case is simple enough)
if (!armeriaServerConfigurators.stream().findAny().isPresent() && | |
!armeriaServerBuilderConsumers.stream().findAny().isPresent()) { | |
if (armeriaServerConfigurators.stream().findAny().isEmpty() && | |
armeriaServerBuilderConsumers.stream().findAny().isEmpty()) { |
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.
Thanks for your suggestion and yes I have used isEmpty()
at first, but local test failed due to this, not sure the exact reason because error message is garbled characters.
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.
Optional.isEmpty()
is introduced in Java 11 but our baseline of Java is 8.
@@ -69,16 +69,16 @@ public Server armeriaServer( | |||
ArmeriaSettings armeriaSettings, | |||
InternalServices internalService, | |||
Optional<MeterRegistry> meterRegistry, | |||
Optional<List<MetricCollectingServiceConfigurator>> metricCollectingServiceConfigurators, | |||
ObjectProvider<MetricCollectingServiceConfigurator> metricCollectingServiceConfigurators, |
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.
Note: This API has been around since 4.3, so there's probably next to no user impact. The change is now that beans are correctly ordered by spring's priority system
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.
Looks great! 👍🙇♂️
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.
Thanks for fixing this, @kratosmy 🙇
@@ -69,16 +69,16 @@ public Server armeriaServer( | |||
ArmeriaSettings armeriaSettings, | |||
InternalServices internalService, | |||
Optional<MeterRegistry> meterRegistry, |
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.
Question: Can we also use ObjectProvider
for this type?
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.
Yes, we can. But it may require something like meterIdPrefixFunction.getIfAvailable() ? meterIdPrefixFunction.getIfAvailable() : MeterIdPrefixFunction.ofDefault("armeria.server")
, seems not so concise.
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.
Yeah, let's keep it as is. Thanks!
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.
Thanks a lot, @kratosmy! 👍 👍 👍
Motivation:
Optional is not as compatible as ObjectProvider, which is included in Spring Framework since Spring 4.3, so use ObjectProvider would improve the programmatic resolution of Beans.
Modifications:
Two file are affected, AbstractArmeriaAutoConfiguration.java and ArmeriaReactiveWebServerFactoryAutoConfiguration.java
Result:
Closes #5527 .