ContextFunctionCatalogAutoConfiguration improvements

Removed FunctionEntry as it was no longer referenced by anything
This commit is contained in:
Oleg Zhurakousky
2018-07-12 16:29:47 +02:00
parent 20f02c94c2
commit e1a7e16c18
2 changed files with 13 additions and 78 deletions

View File

@@ -1,44 +0,0 @@
/*
* Copyright 2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.function.context;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.annotation.AliasFor;
/**
* A {@link Qualifier} annotation that specifies how to locate a function in the
* {@link FunctionCatalog} (instead of using the bean name).
*
* @author Dave Syer
*/
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER, ElementType.TYPE,
ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@Qualifier
public @interface FunctionEntry {
@AliasFor(annotation=Qualifier.class)
String value() default "";
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2018 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.
@@ -36,6 +36,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
import javax.annotation.PreDestroy;
@@ -382,40 +383,18 @@ public class ContextFunctionCatalogAutoConfiguration {
registrations.add(registration);
targets.put(registration.getTarget(), key);
}
// Add consumers that were not already registered
for (String key : consumers.keySet()) {
if (!targets.containsKey(consumers.get(key))) {
FunctionRegistration<Object> target = new FunctionRegistration<Object>(
consumers.get(key)).names(getAliases(key));
targets.put(target.getTarget(), key);
registrations.add(target);
}
}
// Add suppliers that were not already registered
for (String key : suppliers.keySet()) {
if (!targets.containsKey(suppliers.get(key))) {
FunctionRegistration<Object> target = new FunctionRegistration<Object>(
suppliers.get(key)).names(getAliases(key));
targets.put(target.getTarget(), key);
registrations.add(target);
}
}
// Add functions that were not already registered
for (String key : functions.keySet()) {
if (!targets.containsKey(functions.get(key))) {
FunctionRegistration<Object> target = new FunctionRegistration<Object>(
functions.get(key)).names(getAliases(key));
targets.put(target.getTarget(), key);
registrations.add(target);
}
}
Stream.concat(consumers.entrySet().stream(), Stream.concat(suppliers.entrySet().stream(), functions.entrySet().stream()))
.forEach(entry -> {
if (!targets.containsKey(entry.getValue())) {
FunctionRegistration<Object> target = new FunctionRegistration<Object>(
entry.getValue()).names(getAliases(entry.getKey()));
targets.put(target.getTarget(), entry.getKey());
registrations.add(target);
}
});
// Wrap the functions so they handle reactive inputs and outputs
for (FunctionRegistration<?> registration : registrations) {
@SuppressWarnings("unchecked")
FunctionRegistration<Object> target = (FunctionRegistration<Object>) registration;
String key = targets.get(target.getTarget());
wrap(target, key);
}
registrations.forEach(registration -> wrap(registration, targets.get(registration.getTarget())));
return registrations;
}