Search in sources :

Example 21 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class ClasspathMuleCoreExtensionDiscoverer method discover.

@Override
public List<MuleCoreExtension> discover() throws MuleException {
    List<MuleCoreExtension> result = new LinkedList<>();
    Enumeration<?> e = ClassUtils.getResources(CORE_EXTENSION_RESOURCE_NAME, getClass().getClassLoader());
    List<Properties> extensions = new LinkedList<Properties>();
    // load ALL of the extension files first
    while (e.hasMoreElements()) {
        try {
            URL url = (URL) e.nextElement();
            if (logger.isDebugEnabled()) {
                logger.debug("Reading extension file: " + url.toString());
            }
            extensions.add(loadProperties(url.openStream()));
        } catch (Exception ex) {
            throw new DefaultMuleException("Error loading Mule core extensions", ex);
        }
    }
    for (Properties extProps : extensions) {
        for (Map.Entry entry : extProps.entrySet()) {
            String extName = (String) entry.getKey();
            String extClass = (String) entry.getValue();
            try {
                MuleCoreExtension extension = (MuleCoreExtension) ClassUtils.instantiateClass(extClass);
                extension.setContainerClassLoader(containerClassLoader);
                result.add(extension);
            } catch (Throwable t) {
                throw new DefaultMuleException(format("Error starting Mule core extension '%s'. Extension class is %s", extName, extClass), t);
            }
        }
    }
    return result;
}
Also used : Properties(java.util.Properties) PropertiesUtils.loadProperties(org.mule.runtime.core.api.util.PropertiesUtils.loadProperties) LinkedList(java.util.LinkedList) URL(java.net.URL) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleException(org.mule.runtime.api.exception.MuleException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) Map(java.util.Map)

Example 22 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class DefaultMuleCoreExtensionManagerServer method dispose.

@Override
public void dispose() {
    LOGGER.info("Disposing core extensions");
    for (MuleCoreExtension extension : coreExtensions) {
        if (initializedCoreExtensions.contains(extension)) {
            try {
                extension.dispose();
                LOGGER.info("Core extension '{}' disposed", extension.toString());
            } catch (Exception ex) {
                LOGGER.error("Error disposing core extension " + extension.getName(), ex);
            }
        }
    }
    initializedCoreExtensions.clear();
}
Also used : MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 23 with MuleCoreExtension

use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.

the class DefaultMuleCoreExtensionManagerServer method stop.

@Override
public void stop() throws MuleException {
    if (orderedCoreExtensions == null) {
        return;
    }
    LOGGER.info("Stopping core extensions");
    for (int i = orderedCoreExtensions.size() - 1; i >= 0; i--) {
        MuleCoreExtension extension = orderedCoreExtensions.get(i);
        if (startedCoreExtensions.contains(extension)) {
            try {
                extension.stop();
                LOGGER.info("Core extension '{}' stopped", extension.toString());
            } catch (Throwable e) {
                LOGGER.warn("Error stopping core extension: " + extension.getName(), e);
            }
        }
    }
    startedCoreExtensions.clear();
}
Also used : MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension)

Aggregations

MuleCoreExtension (org.mule.runtime.container.api.MuleCoreExtension)23 LinkedList (java.util.LinkedList)17 Test (org.junit.Test)15 SmallTest (org.mule.tck.size.SmallTest)14 InOrder (org.mockito.InOrder)5 MuleException (org.mule.runtime.api.exception.MuleException)4 URL (java.net.URL)2 ExpectedException (org.junit.rules.ExpectedException)2 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)2 Map (java.util.Map)1 Properties (java.util.Properties)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 ServiceRepository (org.mule.runtime.api.service.ServiceRepository)1 ArtifactClassLoaderManagerAware (org.mule.runtime.container.api.ArtifactClassLoaderManagerAware)1 CoreExtensionsAware (org.mule.runtime.container.api.CoreExtensionsAware)1 Injector (org.mule.runtime.core.api.Injector)1 ClassUtils.withContextClassLoader (org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)1 PropertiesUtils.loadProperties (org.mule.runtime.core.api.util.PropertiesUtils.loadProperties)1 ArtifactClassLoader (org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader)1 ArtifactDeploymentListener (org.mule.runtime.module.deployment.api.ArtifactDeploymentListener)1