add support for function composition
This commit is contained in:
@@ -22,6 +22,7 @@ import java.util.function.Function;
|
|||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
import org.springframework.cloud.function.registry.FunctionCatalog;
|
import org.springframework.cloud.function.registry.FunctionCatalog;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
@@ -49,9 +50,18 @@ public class InMemoryFunctionCatalog implements FunctionCatalog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
public <T, R> Function<T, R> lookupFunction(String name) {
|
public <T, R> Function<T, R> lookupFunction(String name) {
|
||||||
return (Function<T, R>) functions.get(name);
|
if (name.indexOf(',') == -1) {
|
||||||
|
return (Function<T, R>) functions.get(name);
|
||||||
|
}
|
||||||
|
String[] tokens = StringUtils.tokenizeToStringArray(name, ",");
|
||||||
|
Function function = null;
|
||||||
|
for (String token : tokens) {
|
||||||
|
Function next = lookupFunction(token);
|
||||||
|
function = (function == null) ? next : function.andThen(next);
|
||||||
|
}
|
||||||
|
return function;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -138,6 +138,11 @@ public class StreamConfiguration {
|
|||||||
if (!StringUtils.hasText(functionName)) {
|
if (!StringUtils.hasText(functionName)) {
|
||||||
return ConditionOutcome.noMatch("no function name available");
|
return ConditionOutcome.noMatch("no function name available");
|
||||||
}
|
}
|
||||||
|
if (functionName.indexOf(',') != -1) {
|
||||||
|
// for now we will just check the first, but later may support:
|
||||||
|
// supplier[,function]+ or [function,]+consumer
|
||||||
|
functionName = functionName.substring(0, functionName.indexOf(','));
|
||||||
|
}
|
||||||
Class<?> beanType = context.getBeanFactory().getType(functionName);
|
Class<?> beanType = context.getBeanFactory().getType(functionName);
|
||||||
if (type.isAssignableFrom(beanType)) {
|
if (type.isAssignableFrom(beanType)) {
|
||||||
return ConditionOutcome.match(String.format("bean '%s' is a %s", functionName, type));
|
return ConditionOutcome.match(String.format("bean '%s' is a %s", functionName, type));
|
||||||
|
|||||||
Reference in New Issue
Block a user