Polishing in GroupsMetadata

See gh-33992
This commit is contained in:
rstoyanchev
2025-03-31 10:23:31 +01:00
parent 85bc6350ce
commit 87fa9a5acb
2 changed files with 13 additions and 6 deletions

View File

@@ -142,10 +142,9 @@ public abstract class AbstractHttpServiceRegistrar implements
mergeGroups(proxyRegistryBeanDef);
this.groupsMetadata.forEachRegistration(group -> group.httpServiceTypeNames().forEach(type -> {
this.groupsMetadata.forEachRegistration((groupName, types) -> types.forEach(type -> {
GenericBeanDefinition proxyBeanDef = new GenericBeanDefinition();
proxyBeanDef.setBeanClassName(type);
String groupName = group.name();
String beanName = (groupName + "#" + type);
proxyBeanDef.setInstanceSupplier(() -> getProxyInstance(proxyRegistryBeanName, groupName, type));
if (!beanRegistry.containsBeanDefinition(beanName)) {

View File

@@ -21,7 +21,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import org.springframework.util.Assert;
@@ -54,16 +54,24 @@ final class GroupsMetadata {
* Merge all registrations from the given {@link GroupsMetadata} into this one.
*/
public void mergeWith(GroupsMetadata other) {
other.forEachRegistration(registration ->
other.groupMap.values().forEach(registration ->
getOrCreateGroup(registration.name(), registration.clientType())
.httpServiceTypeNames()
.addAll(registration.httpServiceTypeNames()));
}
public void forEachRegistration(Consumer<Registration> consumer) {
this.groupMap.values().forEach(consumer);
/**
* Callback to apply to all registrations with access to the group name and
* its HTTP service type names.
*/
public void forEachRegistration(BiConsumer<String, Set<String>> consumer) {
this.groupMap.values().forEach(registration ->
consumer.accept(registration.name(), registration.httpServiceTypeNames()));
}
/**
* Create the {@link HttpServiceGroup}s for all registrations.
*/
public Collection<HttpServiceGroup> groups() {
return this.groupMap.values().stream().map(DefaultRegistration::toHttpServiceGroup).toList();
}