Search in sources :

Example 1 with BootstrapService

use of org.mule.runtime.core.api.config.bootstrap.BootstrapService in project mule by mulesoft.

the class AbstractRegistryBootstrap method initialise.

/**
 * TODO Optimize me! MULE-9343
 *
 * {@inheritDoc}
 */
@Override
public void initialise() throws InitialisationException {
    List<BootstrapService> bootstrapServices;
    try {
        bootstrapServices = muleContext.getRegistryBootstrapServiceDiscoverer().discover();
    } catch (Exception e) {
        throw new InitialisationException(e, this);
    }
    // Merge and process properties
    int objectCounter = 1;
    List<TransformerBootstrapProperty> transformers = new LinkedList<>();
    List<ObjectBootstrapProperty> namedObjects = new LinkedList<>();
    List<ObjectBootstrapProperty> unnamedObjects = new LinkedList<>();
    List<TransactionFactoryBootstrapProperty> singleTransactionFactories = new LinkedList<>();
    for (BootstrapService bootstrapService : bootstrapServices) {
        Properties bootstrapProperties = bootstrapService.getProperties();
        for (Map.Entry entry : bootstrapProperties.entrySet()) {
            final String propertyKey = (String) entry.getKey();
            final String propertyValue = (String) entry.getValue();
            if (propertyKey.contains(OBJECT_KEY)) {
                String newKey = propertyKey.substring(0, propertyKey.lastIndexOf(".")) + objectCounter++;
                unnamedObjects.add(createObjectBootstrapProperty(bootstrapService, newKey, propertyValue));
            } else if (propertyKey.contains(TRANSFORMER_KEY)) {
                transformers.add(createTransformerBootstrapProperty(bootstrapService, propertyValue));
            } else if (propertyKey.contains(SINGLE_TX)) {
                if (!propertyKey.contains(TRANSACTION_RESOURCE_SUFFIX)) {
                    singleTransactionFactories.add(createTransactionFactoryBootstrapProperty(bootstrapService, bootstrapProperties, propertyKey, propertyValue));
                }
            } else {
                namedObjects.add(createObjectBootstrapProperty(bootstrapService, propertyKey, propertyValue));
            }
        }
    }
    try {
        registerUnnamedObjects(unnamedObjects);
        registerTransformers();
        registerTransformers(transformers);
        registerObjects(namedObjects);
        registerTransactionFactories(singleTransactionFactories, muleContext);
    } catch (Exception e1) {
        throw new InitialisationException(e1, this);
    }
}
Also used : InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) ArtifactType.createFromString(org.mule.runtime.core.api.config.bootstrap.ArtifactType.createFromString) Properties(java.util.Properties) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LinkedList(java.util.LinkedList) HashMap(java.util.HashMap) Map(java.util.Map) BootstrapService(org.mule.runtime.core.api.config.bootstrap.BootstrapService)

Example 2 with BootstrapService

use of org.mule.runtime.core.api.config.bootstrap.BootstrapService in project mule by mulesoft.

the class TestBootstrapServiceDiscovererConfigurationBuilder method getArtifactBootstrapService.

private List<BootstrapService> getArtifactBootstrapService(Object artifactClassLoader) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException, IOException {
    // Uses reflection to access the class loader as classes were loaded from different class loaders so they cannot be casted
    ClassLoader classLoader = (ClassLoader) artifactClassLoader.getClass().getMethod("getClassLoader").invoke(artifactClassLoader);
    final Enumeration<URL> resources = (Enumeration<URL>) classLoader.getClass().getMethod("findResources", String.class).invoke(classLoader, BOOTSTRAP_PROPERTIES);
    final List<BootstrapService> bootstrapServices = new ArrayList<>();
    if (resources.hasMoreElements()) {
        while (resources.hasMoreElements()) {
            final URL localResource = resources.nextElement();
            final Properties properties = PropertiesUtils.loadProperties(localResource);
            final PropertiesBootstrapService propertiesBootstrapService = new PropertiesBootstrapService(classLoader, properties);
            bootstrapServices.add(propertiesBootstrapService);
        }
    }
    return bootstrapServices;
}
Also used : PropertiesBootstrapService(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService) Enumeration(java.util.Enumeration) ArrayList(java.util.ArrayList) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) Properties(java.util.Properties) URL(java.net.URL) BootstrapService(org.mule.runtime.core.api.config.bootstrap.BootstrapService) PropertiesBootstrapService(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService)

Example 3 with BootstrapService

use of org.mule.runtime.core.api.config.bootstrap.BootstrapService in project mule by mulesoft.

the class ArtifactBootstrapServiceDiscovererConfigurationBuilder method doConfigure.

@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
    final PropertiesBootstrapServiceDiscoverer propertiesBootstrapServiceDiscoverer = new PropertiesBootstrapServiceDiscoverer(this.getClass().getClassLoader());
    List<BootstrapService> bootstrapServices = new LinkedList<>();
    bootstrapServices.addAll(propertiesBootstrapServiceDiscoverer.discover());
    for (ArtifactPlugin artifactPlugin : artifactPlugins) {
        final Enumeration<URL> resources = artifactPlugin.getArtifactClassLoader().findResources(BOOTSTRAP_PROPERTIES);
        while (resources.hasMoreElements()) {
            final URL localResource = resources.nextElement();
            final Properties properties = PropertiesUtils.loadProperties(localResource);
            final BootstrapService pluginBootstrapService = new PropertiesBootstrapService(artifactPlugin.getArtifactClassLoader().getClassLoader(), properties);
            bootstrapServices.add(pluginBootstrapService);
        }
    }
    muleContext.setBootstrapServiceDiscoverer(() -> bootstrapServices);
}
Also used : PropertiesBootstrapServiceDiscoverer(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapServiceDiscoverer) PropertiesBootstrapService(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService) Properties(java.util.Properties) LinkedList(java.util.LinkedList) URL(java.net.URL) BootstrapService(org.mule.runtime.core.api.config.bootstrap.BootstrapService) PropertiesBootstrapService(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService) ArtifactPlugin(org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)

Example 4 with BootstrapService

use of org.mule.runtime.core.api.config.bootstrap.BootstrapService in project mule by mulesoft.

the class TestBootstrapServiceDiscovererConfigurationBuilder method doConfigure.

@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
    final PropertiesBootstrapServiceDiscoverer propertiesBootstrapServiceDiscoverer = new PropertiesBootstrapServiceDiscoverer(containerClassLoader);
    List<BootstrapService> bootstrapServices = new LinkedList<>();
    bootstrapServices.addAll(propertiesBootstrapServiceDiscoverer.discover());
    // Uses Object instead of ArtifactClassLoader because that class was originally loaded from a different class loader
    for (Object pluginClassLoader : pluginClassLoaders) {
        List<BootstrapService> pluginBootstrapServices = getArtifactBootstrapService(pluginClassLoader);
        bootstrapServices.addAll(pluginBootstrapServices);
    }
    List<BootstrapService> appBootstrapServices = getArtifactBootstrapService(executionClassLoader);
    bootstrapServices.addAll(appBootstrapServices);
    muleContext.setBootstrapServiceDiscoverer(() -> bootstrapServices);
}
Also used : PropertiesBootstrapServiceDiscoverer(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapServiceDiscoverer) LinkedList(java.util.LinkedList) BootstrapService(org.mule.runtime.core.api.config.bootstrap.BootstrapService) PropertiesBootstrapService(org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService)

Aggregations

BootstrapService (org.mule.runtime.core.api.config.bootstrap.BootstrapService)4 LinkedList (java.util.LinkedList)3 Properties (java.util.Properties)3 PropertiesBootstrapService (org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapService)3 URL (java.net.URL)2 PropertiesBootstrapServiceDiscoverer (org.mule.runtime.core.api.config.bootstrap.PropertiesBootstrapServiceDiscoverer)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 MuleException (org.mule.runtime.api.exception.MuleException)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 ArtifactType.createFromString (org.mule.runtime.core.api.config.bootstrap.ArtifactType.createFromString)1 ArtifactPlugin (org.mule.runtime.deployment.model.api.plugin.ArtifactPlugin)1 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)1