use of io.vertigo.core.component.di.reactor.DIReactor in project vertigo by KleeGroup.
the class ComponentLoader method registerComponents.
/**
* registers all the components defined by their configs.
* @param paramManagerOpt the optional manager of params
* @param moduleName the name of the module
* @param componentConfigs the configs of the components
*/
public void registerComponents(final Optional<ParamManager> paramManagerOpt, final String moduleName, final List<ComponentConfig> componentConfigs) {
Assertion.checkNotNull(componentSpace);
Assertion.checkNotNull(paramManagerOpt);
Assertion.checkNotNull(moduleName);
Assertion.checkNotNull(componentConfigs);
// ---- Proxies----
componentConfigs.stream().filter(ComponentConfig::isProxy).forEach(componentConfig -> {
final Component component = createProxyWithOptions(/*paramManagerOpt,*/
componentConfig);
componentSpace.registerComponent(componentConfig.getId(), component);
});
// ---- No proxy----
final DIReactor reactor = new DIReactor();
// 0; On ajoute la liste des ids qui sont déjà résolus.
for (final String id : componentSpace.keySet()) {
reactor.addParent(id);
}
// Map des composants définis par leur id
final Map<String, ComponentConfig> componentConfigById = componentConfigs.stream().filter(componentConfig -> !componentConfig.isProxy()).peek(componentConfig -> reactor.addComponent(componentConfig.getId(), componentConfig.getImplClass(), componentConfig.getParams().keySet())).collect(Collectors.toMap(ComponentConfig::getId, Function.identity()));
// Comment trouver des plugins orphenlins ?
final List<String> ids = reactor.proceed();
// On a récupéré la liste ordonnée des ids.
// On positionne un proxy pour compter les plugins non utilisés
final ComponentUnusedKeysContainer componentProxyContainer = new ComponentUnusedKeysContainer(componentSpace);
for (final String id : ids) {
if (componentConfigById.containsKey(id)) {
// Si il s'agit d'un composant (y compris plugin)
final ComponentConfig componentConfig = componentConfigById.get(id);
// 2.a On crée le composant avec AOP et autres options (elastic)
final Component component = createComponentWithOptions(paramManagerOpt, componentProxyContainer, componentConfig);
// 2.b. On enregistre le composant
componentSpace.registerComponent(componentConfig.getId(), component);
}
}
// --Search for unuseds plugins
final List<String> unusedPluginIds = componentConfigs.stream().filter(componentConfig -> !componentConfig.isProxy()).filter(componentConfig -> Plugin.class.isAssignableFrom(componentConfig.getImplClass())).map(ComponentConfig::getId).filter(pluginId -> !componentProxyContainer.getUsedKeys().contains(pluginId)).collect(Collectors.toList());
if (!unusedPluginIds.isEmpty()) {
throw new VSystemException("plugins '{0}' in module'{1}' are not used by injection", unusedPluginIds, moduleName);
}
}
Aggregations