io.hyperfoil.core.builders.ServiceLoadedBuilderProvider Maven / Gradle / Ivy
package io.hyperfoil.core.builders;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import io.hyperfoil.api.config.BenchmarkDefinitionException;
import io.hyperfoil.api.config.BuilderBase;
import io.hyperfoil.api.config.IncludeBuilders;
import io.hyperfoil.api.config.InitFromParam;
import io.hyperfoil.api.config.Locator;
import io.hyperfoil.api.config.Name;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
public class ServiceLoadedBuilderProvider {
private static final Logger log = LoggerFactory.getLogger(ServiceLoadedBuilderProvider.class);
private static final Map, Map>> BUILDERS = new HashMap<>();
private final Class builderClazz;
private final Locator locator;
private final Consumer consumer;
public static synchronized Map> builders(Class> clazz) {
Map> builders = BUILDERS.get(clazz);
if (builders != null) {
return builders;
}
builders = new HashMap<>();
Set> included = new HashSet<>();
ArrayDeque> deque = new ArrayDeque<>();
deque.add(new BuilderInfo<>(clazz, Function.identity()));
included.add(clazz);
while (!deque.isEmpty()) {
BuilderInfo