Minor refactoring in ContextFunctionRegistry
This commit is contained in:
@@ -36,15 +36,13 @@ import javax.annotation.PreDestroy;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
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.InitializingBean;
|
||||||
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;
|
||||||
@@ -172,9 +170,7 @@ public class ContextFunctionCatalogAutoConfiguration {
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
protected static class ContextFunctionRegistry
|
protected static class ContextFunctionRegistry
|
||||||
implements SmartInitializingSingleton, BeanFactoryAware {
|
implements InitializingBean, BeanFactoryAware {
|
||||||
|
|
||||||
private Log logger = LogFactory.getLog(ContextFunctionRegistry.class);
|
|
||||||
|
|
||||||
private ApplicationEventPublisher applicationEventPublisher;
|
private ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
@@ -196,7 +192,7 @@ public class ContextFunctionCatalogAutoConfiguration {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public void afterSingletonsInstantiated() {
|
public void afterPropertiesSet() throws Exception {
|
||||||
Map<String, Supplier> supplierBeans = beanFactory
|
Map<String, Supplier> supplierBeans = beanFactory
|
||||||
.getBeansOfType(Supplier.class);
|
.getBeansOfType(Supplier.class);
|
||||||
Map<String, Function> functionBeans = beanFactory
|
Map<String, Function> functionBeans = beanFactory
|
||||||
@@ -281,10 +277,6 @@ public class ContextFunctionCatalogAutoConfiguration {
|
|||||||
&& typeOfFunction.isAssignableFrom(function.getClass())) {
|
&& typeOfFunction.isAssignableFrom(function.getClass())) {
|
||||||
return function;
|
return function;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
logger.warn("The resulting composition is of type "
|
|
||||||
+ types.get(normalizeName(name)));
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +311,15 @@ public class ContextFunctionCatalogAutoConfiguration {
|
|||||||
.get(stages[stages.length - 1]);
|
.get(stages[stages.length - 1]);
|
||||||
this.types.put(name, FunctionType.compose(input, output));
|
this.types.put(name, FunctionType.compose(input, output));
|
||||||
this.names.put(composedFunction, name);
|
this.names.put(composedFunction, name);
|
||||||
lookup.put(name, composedFunction);
|
if (composedFunction instanceof Function) {
|
||||||
|
this.functions.put(name, composedFunction);
|
||||||
|
}
|
||||||
|
else if (composedFunction instanceof Consumer) {
|
||||||
|
this.consumers.put(name, composedFunction);
|
||||||
|
}
|
||||||
|
else if (composedFunction instanceof Supplier) {
|
||||||
|
this.suppliers.put(name, composedFunction);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -536,7 +536,7 @@ public class ContextFunctionCatalogAutoConfiguration {
|
|||||||
registrations.add(target);
|
registrations.add(target);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Wrap the functions so they handle reactive inputs and outputs
|
|
||||||
registrations.forEach(registration -> wrap(registration,
|
registrations.forEach(registration -> wrap(registration,
|
||||||
targets.get(registration.getTarget())));
|
targets.get(registration.getTarget())));
|
||||||
}
|
}
|
||||||
@@ -561,23 +561,6 @@ public class ContextFunctionCatalogAutoConfiguration {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// protected class BeanFactoryFunctionInspector implements FunctionInspector {
|
|
||||||
//
|
|
||||||
// private ContextFunctionRegistry processor;
|
|
||||||
//
|
|
||||||
// public BeanFactoryFunctionInspector(ContextFunctionRegistry processor) {
|
|
||||||
// this.processor = processor;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public FunctionRegistration<?> getRegistration(Object function) {
|
|
||||||
// FunctionRegistration<?> registration = this.processor
|
|
||||||
// .getRegistration(function);
|
|
||||||
// return registration;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ConditionalOnClass(Gson.class)
|
@ConditionalOnClass(Gson.class)
|
||||||
@ConditionalOnBean(Gson.class)
|
@ConditionalOnBean(Gson.class)
|
||||||
|
|||||||
@@ -24,10 +24,10 @@ import reactor.core.publisher.Mono;
|
|||||||
/**
|
/**
|
||||||
* Wrapper to mark function {@code Function<Flux<?>, Mono<?>>}.
|
* Wrapper to mark function {@code Function<Flux<?>, Mono<?>>}.
|
||||||
*
|
*
|
||||||
* While it may look similar to {@link FluxedConsumer}
|
* While it may look similar to {@link FluxedConsumer} the fundamental difference is that
|
||||||
* the fundamental difference is that this class represents a function that
|
* this class represents a function that returns {@link Mono} of type {@code <O>}, while
|
||||||
* returns {@link Mono} of type {@code <O>}, while {@link FluxedConsumer} is
|
* {@link FluxedConsumer} is a consumer that has been decorated as
|
||||||
* a consumer that has been decorated as {@code Function<Flux<?>, Mono<Void>>}.
|
* {@code Function<Flux<?>, Mono<Void>>}.
|
||||||
*
|
*
|
||||||
* @param <I> type of {@link Flux} input of the target function
|
* @param <I> type of {@link Flux} input of the target function
|
||||||
* @param <O> type of {@link Mono} output of the target function
|
* @param <O> type of {@link Mono} output of the target function
|
||||||
|
|||||||
Reference in New Issue
Block a user