Search in sources :

Example 1 with ConfigurationDependencyResolver

use of org.mule.runtime.config.internal.dsl.model.ConfigurationDependencyResolver in project mule by mulesoft.

the class LazyMuleArtifactContext method createComponents.

private List<String> createComponents(Optional<Predicate> predicateOptional, Optional<Location> locationOptional, Optional<ComponentModelInitializerAdapter> parentComponentModelInitializerAdapter) {
    checkState(predicateOptional.isPresent() != locationOptional.isPresent(), "predicate or location has to be passed");
    List<String> alreadyCreatedApplicationComponents = new ArrayList<>();
    alreadyCreatedApplicationComponents.addAll(trackingPostProcessor.getBeansTracked());
    reverse(alreadyCreatedApplicationComponents);
    trackingPostProcessor.startTracking();
    Reference<List<String>> createdComponents = new Reference<>();
    withContextClassLoader(muleContext.getExecutionClassLoader(), () -> {
        applicationModel.executeOnEveryMuleComponentTree(componentModel -> componentModel.setEnabled(false));
        ConfigurationDependencyResolver dependencyResolver = new ConfigurationDependencyResolver(this.applicationModel, componentBuildingDefinitionRegistry);
        MinimalApplicationModelGenerator minimalApplicationModelGenerator = new MinimalApplicationModelGenerator(dependencyResolver);
        Reference<ApplicationModel> minimalApplicationModel = new Reference<>();
        predicateOptional.ifPresent(predicate -> minimalApplicationModel.set(minimalApplicationModelGenerator.getMinimalModel(predicate)));
        locationOptional.ifPresent(location -> minimalApplicationModel.set(minimalApplicationModelGenerator.getMinimalModel(location)));
        // First unregister any already initialized/started component
        unregisterBeans(alreadyCreatedApplicationComponents);
        objectProviders.clear();
        if (parentComponentModelInitializerAdapter.isPresent()) {
            List<String> missingComponentNames = dependencyResolver.getMissingDependencies().stream().filter(dependencyNode -> dependencyNode.isTopLevel()).map(dependencyNode -> dependencyNode.getComponentName()).collect(toList());
            parentComponentModelInitializerAdapter.get().initializeComponents(componentModel -> {
                if (componentModel.getNameAttribute() != null) {
                    return missingComponentNames.contains(componentModel.getNameAttribute());
                }
                return false;
            });
        } else {
            dependencyResolver.getMissingDependencies().stream().forEach(globalElementName -> {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(String.format("Ignoring dependency %s because it does not exists", globalElementName));
                }
            });
        }
        List<String> applicationComponents = createApplicationComponents((DefaultListableBeanFactory) this.getBeanFactory(), minimalApplicationModel.get(), false);
        createdComponents.set(applicationComponents);
        super.prepareObjectProviders();
        // This is required to force the execution of postProcessAfterInitialization() for each created component
        applicationComponents.forEach(component -> getRegistry().lookupByName(component).get());
    });
    trackingPostProcessor.stopTracking();
    List<String> createdComponentNames = createdComponents.get();
    trackingPostProcessor.intersection(createdComponentNames);
    return createdComponentNames;
}
Also used : Optional.empty(java.util.Optional.empty) Optional.of(java.util.Optional.of) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ConfigurationProperties(org.mule.runtime.api.component.ConfigurationProperties) Location(org.mule.runtime.api.component.location.Location) NON_LAZY_VALUE_PROVIDER_SERVICE(org.mule.runtime.config.internal.LazyValueProviderService.NON_LAZY_VALUE_PROVIDER_SERVICE) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) ArrayList(java.util.ArrayList) ValueProviderService(org.mule.runtime.api.value.ValueProviderService) MuleContext(org.mule.runtime.core.api.MuleContext) NON_LAZY_CONNECTIVITY_TESTING_SERVICE(org.mule.runtime.config.internal.LazyConnectivityTestingService.NON_LAZY_CONNECTIVITY_TESTING_SERVICE) MuleException(org.mule.runtime.api.exception.MuleException) ArtifactDeclaration(org.mule.runtime.app.declaration.api.ArtifactDeclaration) Map(java.util.Map) Location.builderFromStringRepresentation(org.mule.runtime.api.component.location.Location.builderFromStringRepresentation) Preconditions.checkState(org.mule.runtime.api.util.Preconditions.checkState) LegacyRegistryUtils.unregisterObject(org.mule.runtime.core.privileged.registry.LegacyRegistryUtils.unregisterObject) ConfigurationDependencyResolver(org.mule.runtime.config.internal.dsl.model.ConfigurationDependencyResolver) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) MinimalApplicationModelGenerator(org.mule.runtime.config.internal.dsl.model.MinimalApplicationModelGenerator) MetadataService(org.mule.runtime.api.metadata.MetadataService) VALUE_PROVIDER_SERVICE_KEY(org.mule.runtime.api.value.ValueProviderService.VALUE_PROVIDER_SERVICE_KEY) Collections.reverse(java.util.Collections.reverse) Startable(org.mule.runtime.api.lifecycle.Startable) Logger(org.slf4j.Logger) DefaultConnectivityTestingService(org.mule.runtime.core.internal.connectivity.DefaultConnectivityTestingService) Predicate(java.util.function.Predicate) ConfigResource(org.mule.runtime.core.api.config.ConfigResource) ApplicationModel(org.mule.runtime.config.internal.model.ApplicationModel) BeansException(org.springframework.beans.BeansException) MuleDeploymentProperties(org.mule.runtime.core.api.config.MuleDeploymentProperties) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) String.format(java.lang.String.format) ConnectivityTestingService(org.mule.runtime.api.connectivity.ConnectivityTestingService) MuleValueProviderService(org.mule.runtime.core.internal.value.MuleValueProviderService) Collectors.toList(java.util.stream.Collectors.toList) ArtifactType(org.mule.runtime.core.api.config.bootstrap.ArtifactType) List(java.util.List) METADATA_SERVICE_KEY(org.mule.runtime.api.metadata.MetadataService.METADATA_SERVICE_KEY) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) Reference(org.mule.runtime.api.util.Reference) MuleMetadataService(org.mule.runtime.core.internal.metadata.MuleMetadataService) NON_LAZY_METADATA_SERVICE(org.mule.runtime.config.internal.LazyMetadataService.NON_LAZY_METADATA_SERVICE) Optional(java.util.Optional) CONNECTIVITY_TESTING_SERVICE_KEY(org.mule.runtime.api.connectivity.ConnectivityTestingService.CONNECTIVITY_TESTING_SERVICE_KEY) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Reference(org.mule.runtime.api.util.Reference) ArrayList(java.util.ArrayList) ApplicationModel(org.mule.runtime.config.internal.model.ApplicationModel) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ConfigurationDependencyResolver(org.mule.runtime.config.internal.dsl.model.ConfigurationDependencyResolver) MinimalApplicationModelGenerator(org.mule.runtime.config.internal.dsl.model.MinimalApplicationModelGenerator)

Aggregations

String.format (java.lang.String.format)1 ArrayList (java.util.ArrayList)1 Collections.reverse (java.util.Collections.reverse)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 Optional.of (java.util.Optional.of)1 Predicate (java.util.function.Predicate)1 Collectors.toList (java.util.stream.Collectors.toList)1 ConfigurationProperties (org.mule.runtime.api.component.ConfigurationProperties)1 Location (org.mule.runtime.api.component.location.Location)1 Location.builderFromStringRepresentation (org.mule.runtime.api.component.location.Location.builderFromStringRepresentation)1 ConnectivityTestingService (org.mule.runtime.api.connectivity.ConnectivityTestingService)1 CONNECTIVITY_TESTING_SERVICE_KEY (org.mule.runtime.api.connectivity.ConnectivityTestingService.CONNECTIVITY_TESTING_SERVICE_KEY)1 MuleException (org.mule.runtime.api.exception.MuleException)1 Initialisable (org.mule.runtime.api.lifecycle.Initialisable)1 Startable (org.mule.runtime.api.lifecycle.Startable)1 MetadataService (org.mule.runtime.api.metadata.MetadataService)1