More Graal native compilation support in core
More native compilation support for Kafka Streams and multi binder environments. Although these changes directly do not reflect anything native related, these are mainly to support the usage of spring.factories in Kafka Streams binder instead of spring.binders. We are only supporting the spring.factories model for finding the binders in spring-native based Spring Cloud Stream applications. resolves https://github.com/spring-cloud/spring-cloud-stream/issues/2161 Resolves #2162
This commit is contained in:
committed by
Oleg Zhurakousky
parent
36b66cf69c
commit
d9f8653e42
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2020 the original author or authors.
|
||||
* Copyright 2015-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,6 +26,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
@@ -129,24 +130,44 @@ public class DefaultBinderFactory implements BinderFactory, DisposableBean, Appl
|
||||
Map<String, Binder> binders = this.context == null ? Collections.emptyMap()
|
||||
: this.context.getBeansOfType(Binder.class);
|
||||
Binder<T, ConsumerProperties, ProducerProperties> binder;
|
||||
if (StringUtils.hasText(binderName) && binders.containsKey(binderName)) {
|
||||
binder = (Binder<T, ConsumerProperties, ProducerProperties>) this.context
|
||||
.getBean(binderName);
|
||||
|
||||
String bindingTargetTypeName = StringUtils.hasText(name) ? name : bindingTargetType.getSimpleName().toLowerCase();
|
||||
final BinderConfiguration binderConfiguration = this.binderConfigurations.get(name);
|
||||
if (binderConfiguration != null && binderConfiguration.getBinderType() != null) {
|
||||
bindingTargetTypeName = binderConfiguration.getBinderType();
|
||||
}
|
||||
else if (binders.size() == 1) {
|
||||
binder = binders.values().iterator().next();
|
||||
}
|
||||
else if (binders.size() > 1) {
|
||||
throw new IllegalStateException(
|
||||
"Multiple binders are available, however neither default nor "
|
||||
+ "per-destination binder name is provided. Available binders are "
|
||||
+ binders.keySet());
|
||||
|
||||
String[] bindingTargetTypeNameForLambda = new String[]{bindingTargetTypeName};
|
||||
final Optional<String> foundBinder = binders.keySet().stream().filter(b -> b.equals(bindingTargetTypeNameForLambda[0])).findFirst();
|
||||
if (foundBinder.isPresent()) { // found a match - now do all the customizations.
|
||||
binder = binders.get(foundBinder.get());
|
||||
if (!CollectionUtils.isEmpty(this.listeners)) {
|
||||
for (Listener binderFactoryListener : this.listeners) {
|
||||
binderFactoryListener.afterBinderContextInitialized(bindingTargetTypeName,
|
||||
this.context);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* This is the fall back to the old bootstrap that relies on spring.binders.
|
||||
*/
|
||||
binder = this.doGetBinder(binderName, bindingTargetType);
|
||||
if (StringUtils.hasText(binderName) && binders.containsKey(binderName)) {
|
||||
binder = (Binder<T, ConsumerProperties, ProducerProperties>) this.context
|
||||
.getBean(binderName);
|
||||
}
|
||||
else if (binders.size() == 1) {
|
||||
binder = binders.values().iterator().next();
|
||||
}
|
||||
else if (binders.size() > 1) {
|
||||
throw new IllegalStateException(
|
||||
"Multiple binders are available, however neither default nor "
|
||||
+ "per-destination binder name is provided. Available binders are "
|
||||
+ binders.keySet());
|
||||
}
|
||||
else {
|
||||
/*
|
||||
* This is the fall back to the old bootstrap that relies on spring.binders.
|
||||
*/
|
||||
binder = this.doGetBinder(binderName, bindingTargetType);
|
||||
}
|
||||
}
|
||||
if (this.binderCustomizer != null) {
|
||||
this.binderCustomizer.customize(binder, binderName);
|
||||
|
||||
Reference in New Issue
Block a user