Skip to content
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

Enforce ordering when ObjectProvider is used #18333

Closed
wants to merge 1 commit into from

Conversation

ttddyy
Copy link
Contributor

@ttddyy ttddyy commented Sep 24, 2019

Fix to enforce ordering when ObjectProvider is used for retrieving multiple objects.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 24, 2019
Copy link
Member

@wilkinsona wilkinsona left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for the PR, @ttddyy. I've left a few comments for your consideration when you have a moment.

@@ -62,9 +62,9 @@ public SpringApplicationAdminMXBeanRegistrar springApplicationAdminRegistrar(
ObjectProvider<MBeanExporter> mbeanExporters, Environment environment) throws MalformedObjectNameException {
String jmxName = environment.getProperty(JMX_NAME_PROPERTY, DEFAULT_JMX_NAME);
if (mbeanExporters != null) { // Make sure to not register that MBean twice
for (MBeanExporter mbeanExporter : mbeanExporters) {
mbeanExporters.orderedStream().forEach(mbeanExporter -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the ordering is important here.

@@ -123,7 +123,7 @@ public Flyway flyway(FlywayProperties properties, DataSourceProperties dataSourc
configureCallbacks(configuration, orderedCallbacks);
fluentConfigurationCustomizers.orderedStream().forEach((customizer) -> customizer.customize(configuration));
configureFlywayCallbacks(configuration, orderedCallbacks);
List<JavaMigration> migrations = javaMigrations.stream().collect(Collectors.toList());
List<JavaMigration> migrations = javaMigrations.orderedStream().collect(Collectors.toList());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ordering doesn't matter as Flyway orders them itself based on MigrationVersion returned from getVersion().

@@ -68,7 +68,7 @@
@Autowired
void bindDataSourcesToRegistry(Map<String, DataSource> dataSources, MeterRegistry registry,
ObjectProvider<DataSourcePoolMetadataProvider> metadataProviders) {
List<DataSourcePoolMetadataProvider> metadataProvidersList = metadataProviders.stream()
List<DataSourcePoolMetadataProvider> metadataProvidersList = metadataProviders.orderedStream()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does ordering matter here? The providers are used in a first wins manner. For the ordering to be important there would have to be overlap between providers.

@@ -67,7 +68,7 @@ public TaskExecutorBuilder taskExecutorBuilder(TaskExecutionProperties propertie
builder = builder.awaitTermination(shutdown.isAwaitTermination());
builder = builder.awaitTerminationPeriod(shutdown.getAwaitTerminationPeriod());
builder = builder.threadNamePrefix(properties.getThreadNamePrefix());
builder = builder.customizers(taskExecutorCustomizers);
builder = builder.customizers(taskExecutorCustomizers.orderedStream().collect(Collectors.toList()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@philwebb philwebb added the status: waiting-for-feedback We need additional information before we can continue label Sep 24, 2019
Enforce ordering of customizer in "TaskExecutionAutoConfiguration".
Also, add comments on non ordered usage of ObjectProvider.
@ttddyy
Copy link
Contributor Author

ttddyy commented Sep 24, 2019

@wilkinsona
Ok, updated the PR.
I have added comments on the usage of non ordering ObjectProvider based on your comments.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Sep 24, 2019
@snicoll
Copy link
Member

snicoll commented Sep 27, 2019

@ttddyy thanks for the update but I am not big fan of the comments you've added. We usually don't add those and I don't think it's warranted. I've flagged this one to see what the rest of the team thinks.

@snicoll snicoll added the for: team-attention An issue we'd like other members of the team to review label Sep 27, 2019
@philwebb
Copy link
Member

Yeah, we'll drop those when we merge it

@philwebb philwebb added type: bug A general bug and removed for: team-attention An issue we'd like other members of the team to review status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Sep 27, 2019
@philwebb philwebb added this to the 2.1.x milestone Sep 27, 2019
@philwebb philwebb added the for: merge-with-amendments Needs some changes when we merge label Sep 27, 2019
philwebb pushed a commit that referenced this pull request Sep 29, 2019
Use an ordered stream in `TaskExecutionAutoConfiguration` when
obtaining the TaskExecutor customizers.

See gh-18333
@philwebb philwebb closed this in 89e7d5f Sep 29, 2019
@philwebb philwebb modified the milestones: 2.1.x, 2.1.9 Sep 29, 2019
@philwebb
Copy link
Member

Thanks for the fix @ttddyy, I've dropped the comments but and merged to 2.1 and 2.2. I also used a method reference trick to save needing to call a collector. The code now looks like this:

builder = builder.customizers(this.taskExecutorCustomizers.orderedStream()::iterator);

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: merge-with-amendments Needs some changes when we merge type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants