Revert "GH-355 Added support for deffered initialization of Function Catalog"
This reverts commit cd0ca2f7dc.
This commit is contained in:
@@ -77,12 +77,9 @@ public abstract class AbstractComposableFunctionRegistry implements FunctionRegi
|
|||||||
|
|
||||||
protected ApplicationEventPublisher applicationEventPublisher;
|
protected ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
private AtomicBoolean initialized = new AtomicBoolean();
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T> T lookup(Class<?> type, String name) {
|
public <T> T lookup(Class<?> type, String name) {
|
||||||
initializeIfNecessary();
|
|
||||||
String functionDefinitionName = !StringUtils.hasText(name)
|
String functionDefinitionName = !StringUtils.hasText(name)
|
||||||
&& this.environment.containsProperty("spring.cloud.function.definition")
|
&& this.environment.containsProperty("spring.cloud.function.definition")
|
||||||
? this.environment.getProperty("spring.cloud.function.definition")
|
? this.environment.getProperty("spring.cloud.function.definition")
|
||||||
@@ -93,7 +90,6 @@ public abstract class AbstractComposableFunctionRegistry implements FunctionRegi
|
|||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@Override
|
@Override
|
||||||
public Set<String> getNames(Class<?> type) {
|
public Set<String> getNames(Class<?> type) {
|
||||||
initializeIfNecessary();
|
|
||||||
if (type == null) {
|
if (type == null) {
|
||||||
return new HashSet<String>(getSupplierNames()) {
|
return new HashSet<String>(getSupplierNames()) {
|
||||||
{
|
{
|
||||||
@@ -115,7 +111,6 @@ public abstract class AbstractComposableFunctionRegistry implements FunctionRegi
|
|||||||
* @return immutable {@link Set} of available {@link Supplier} names.
|
* @return immutable {@link Set} of available {@link Supplier} names.
|
||||||
*/
|
*/
|
||||||
public Set<String> getSupplierNames() {
|
public Set<String> getSupplierNames() {
|
||||||
initializeIfNecessary();
|
|
||||||
return this.functions.entrySet().stream()
|
return this.functions.entrySet().stream()
|
||||||
.filter(entry -> entry.getValue() instanceof Supplier)
|
.filter(entry -> entry.getValue() instanceof Supplier)
|
||||||
.map(entry -> entry.getKey())
|
.map(entry -> entry.getKey())
|
||||||
@@ -127,7 +122,6 @@ public abstract class AbstractComposableFunctionRegistry implements FunctionRegi
|
|||||||
* @return immutable {@link Set} of available {@link Function} names.
|
* @return immutable {@link Set} of available {@link Function} names.
|
||||||
*/
|
*/
|
||||||
public Set<String> getFunctionNames() {
|
public Set<String> getFunctionNames() {
|
||||||
initializeIfNecessary();
|
|
||||||
return this.functions.entrySet().stream()
|
return this.functions.entrySet().stream()
|
||||||
.filter(entry -> !(entry.getValue() instanceof Supplier))
|
.filter(entry -> !(entry.getValue() instanceof Supplier))
|
||||||
.map(entry -> entry.getKey())
|
.map(entry -> entry.getKey())
|
||||||
@@ -135,12 +129,10 @@ public abstract class AbstractComposableFunctionRegistry implements FunctionRegi
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasSuppliers() {
|
public boolean hasSuppliers() {
|
||||||
initializeIfNecessary();
|
|
||||||
return !CollectionUtils.isEmpty(getSupplierNames());
|
return !CollectionUtils.isEmpty(getSupplierNames());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasFunctions() {
|
public boolean hasFunctions() {
|
||||||
initializeIfNecessary();
|
|
||||||
return !CollectionUtils.isEmpty(getFunctionNames());
|
return !CollectionUtils.isEmpty(getFunctionNames());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,12 +144,10 @@ public abstract class AbstractComposableFunctionRegistry implements FunctionRegi
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int size() {
|
public int size() {
|
||||||
initializeIfNecessary();
|
|
||||||
return this.functions.size();
|
return this.functions.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public FunctionType getFunctionType(String name) {
|
public FunctionType getFunctionType(String name) {
|
||||||
initializeIfNecessary();
|
|
||||||
return this.types.get(name);
|
return this.types.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +158,6 @@ public abstract class AbstractComposableFunctionRegistry implements FunctionRegi
|
|||||||
* @return the name of the function or null.
|
* @return the name of the function or null.
|
||||||
*/
|
*/
|
||||||
public String lookupFunctionName(Object function) {
|
public String lookupFunctionName(Object function) {
|
||||||
initializeIfNecessary();
|
|
||||||
return this.names.containsKey(function) ? this.names.get(function) : null;
|
return this.names.containsKey(function) ? this.names.get(function) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +174,6 @@ public abstract class AbstractComposableFunctionRegistry implements FunctionRegi
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FunctionRegistration<?> getRegistration(Object function) {
|
public FunctionRegistration<?> getRegistration(Object function) {
|
||||||
initializeIfNecessary();
|
|
||||||
String functionName = function == null ? null
|
String functionName = function == null ? null
|
||||||
: this.lookupFunctionName(function);
|
: this.lookupFunctionName(function);
|
||||||
if (StringUtils.hasText(functionName)) {
|
if (StringUtils.hasText(functionName)) {
|
||||||
@@ -201,19 +189,10 @@ public abstract class AbstractComposableFunctionRegistry implements FunctionRegi
|
|||||||
public <T> void register(FunctionRegistration<T> functionRegistration) {
|
public <T> void register(FunctionRegistration<T> functionRegistration) {
|
||||||
Assert.notEmpty(functionRegistration.getNames(),
|
Assert.notEmpty(functionRegistration.getNames(),
|
||||||
"'registration' must contain at least one name before it is registered in catalog.");
|
"'registration' must contain at least one name before it is registered in catalog.");
|
||||||
initializeIfNecessary();
|
|
||||||
register(functionRegistration, functionRegistration.getNames().iterator().next());
|
register(functionRegistration, functionRegistration.getNames().iterator().next());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeIfNecessary() {
|
|
||||||
if (initialized.compareAndSet(false, true)) {
|
|
||||||
doInitialize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void doInitialize() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers function wrapped by the provided FunctionRegistration with
|
* Registers function wrapped by the provided FunctionRegistration with
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import com.google.gson.Gson;
|
|||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.BeanFactoryAware;
|
import org.springframework.beans.factory.BeanFactoryAware;
|
||||||
|
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
@@ -85,7 +86,7 @@ public class ContextFunctionCatalogAutoConfiguration {
|
|||||||
|
|
||||||
protected static class BeanFactoryFunctionCatalog
|
protected static class BeanFactoryFunctionCatalog
|
||||||
extends AbstractComposableFunctionRegistry
|
extends AbstractComposableFunctionRegistry
|
||||||
implements BeanFactoryAware {
|
implements SmartInitializingSingleton, BeanFactoryAware {
|
||||||
|
|
||||||
private ApplicationEventPublisher applicationEventPublisher;
|
private ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
@@ -95,21 +96,18 @@ public class ContextFunctionCatalogAutoConfiguration {
|
|||||||
* Will collect all suppliers, functions, consumers and function registration as
|
* Will collect all suppliers, functions, consumers and function registration as
|
||||||
* late as possible in the lifecycle.
|
* late as possible in the lifecycle.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
@Override
|
@Override
|
||||||
protected void doInitialize() {
|
public void afterSingletonsInstantiated() {
|
||||||
if (this.beanFactory != null) {
|
Map<String, Supplier> supplierBeans = this.beanFactory
|
||||||
Map<String, Supplier> supplierBeans = this.beanFactory
|
.getBeansOfType(Supplier.class);
|
||||||
.getBeansOfType(Supplier.class);
|
Map<String, Function> functionBeans = this.beanFactory
|
||||||
Map<String, Function> functionBeans = this.beanFactory
|
.getBeansOfType(Function.class);
|
||||||
.getBeansOfType(Function.class);
|
Map<String, Consumer> consumerBeans = this.beanFactory
|
||||||
Map<String, Consumer> consumerBeans = this.beanFactory
|
.getBeansOfType(Consumer.class);
|
||||||
.getBeansOfType(Consumer.class);
|
Map<String, FunctionRegistration> functionRegistrationBeans = this.beanFactory
|
||||||
Map<String, FunctionRegistration> functionRegistrationBeans = this.beanFactory
|
.getBeansOfType(FunctionRegistration.class);
|
||||||
.getBeansOfType(FunctionRegistration.class);
|
this.doMerge(functionRegistrationBeans, consumerBeans, supplierBeans,
|
||||||
this.doMerge(functionRegistrationBeans, consumerBeans, supplierBeans,
|
functionBeans);
|
||||||
functionBeans);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -297,7 +297,6 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
|||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void monoToMonoNonVoidFunction() {
|
public void monoToMonoNonVoidFunction() {
|
||||||
create(MonoToMonoNonVoidConfiguration.class);
|
create(MonoToMonoNonVoidConfiguration.class);
|
||||||
this.catalog.lookup("anything-doesn't-matter");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user