Search in sources :

Example 1 with ParamManager

use of io.vertigo.core.param.ParamManager 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);
    }
}
Also used : ComponentSpaceWritable(io.vertigo.core.component.ComponentSpaceWritable) VSystemException(io.vertigo.lang.VSystemException) DIInjector(io.vertigo.core.component.di.injector.DIInjector) Aspect(io.vertigo.core.component.aop.Aspect) Container(io.vertigo.core.component.Container) DIReactor(io.vertigo.core.component.di.reactor.DIReactor) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ModuleConfig(io.vertigo.app.config.ModuleConfig) List(java.util.List) ProxyMethod(io.vertigo.core.component.proxy.ProxyMethod) ParamManager(io.vertigo.core.param.ParamManager) AspectConfig(io.vertigo.app.config.AspectConfig) Plugin(io.vertigo.core.component.Plugin) Map(java.util.Map) Assertion(io.vertigo.lang.Assertion) Optional(java.util.Optional) Component(io.vertigo.core.component.Component) AopPlugin(io.vertigo.core.component.AopPlugin) Method(java.lang.reflect.Method) ComponentConfig(io.vertigo.app.config.ComponentConfig) ProxyMethodConfig(io.vertigo.app.config.ProxyMethodConfig) ComponentConfig(io.vertigo.app.config.ComponentConfig) Component(io.vertigo.core.component.Component) DIReactor(io.vertigo.core.component.di.reactor.DIReactor) VSystemException(io.vertigo.lang.VSystemException)

Aggregations

AspectConfig (io.vertigo.app.config.AspectConfig)1 ComponentConfig (io.vertigo.app.config.ComponentConfig)1 ModuleConfig (io.vertigo.app.config.ModuleConfig)1 ProxyMethodConfig (io.vertigo.app.config.ProxyMethodConfig)1 AopPlugin (io.vertigo.core.component.AopPlugin)1 Component (io.vertigo.core.component.Component)1 ComponentSpaceWritable (io.vertigo.core.component.ComponentSpaceWritable)1 Container (io.vertigo.core.component.Container)1 Plugin (io.vertigo.core.component.Plugin)1 Aspect (io.vertigo.core.component.aop.Aspect)1 DIInjector (io.vertigo.core.component.di.injector.DIInjector)1 DIReactor (io.vertigo.core.component.di.reactor.DIReactor)1 ProxyMethod (io.vertigo.core.component.proxy.ProxyMethod)1 ParamManager (io.vertigo.core.param.ParamManager)1 Assertion (io.vertigo.lang.Assertion)1 VSystemException (io.vertigo.lang.VSystemException)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1