use of org.mule.runtime.core.api.registry.SpiServiceRegistry in project mule by mulesoft.
the class ExtensionModelDiscoverer method discoverRuntimeExtensionModels.
/**
* Discover the extension models provided by the runtime.
*
* @return {@link Set} of the runtime provided {@link ExtensionModel}s.
*/
public Set<ExtensionModel> discoverRuntimeExtensionModels() {
final Set<ExtensionModel> extensionModels = new HashSet<>();
Collection<RuntimeExtensionModelProvider> runtimeExtensionModelProviders = new SpiServiceRegistry().lookupProviders(RuntimeExtensionModelProvider.class, Thread.currentThread().getContextClassLoader());
for (RuntimeExtensionModelProvider runtimeExtensionModelProvider : runtimeExtensionModelProviders) {
extensionModels.add(runtimeExtensionModelProvider.createExtensionModel());
}
return extensionModels;
}
use of org.mule.runtime.core.api.registry.SpiServiceRegistry in project mule by mulesoft.
the class MuleExtensionModelLoaderManager method start.
/**
* Will look through SPI every class that implements the {@code providerClass} and if there are repeated IDs, it will
* collect them all to throw an exception with the detailed message.
* <p/>
* The exception, if thrown, will have the following message:
* <pre>
* There are several loaders that return the same ID when looking up providers for 'org.mule.runtime.module.artifact.ExtensionModelLoader'. Full error list:
* ID [some-id] is being returned by the following classes [org.foo.FooLoader, org.bar.BarLoader]
* ID [another-id] is being returned by the following classes [org.foo2.FooLoader2, org.bar2.BarLoader2]
* </pre>
*
* @throws IllegalStateException if there are loaders with repeated IDs.
*/
@Override
public void start() throws MuleException {
final Class<ExtensionModelLoader> providerClass = ExtensionModelLoader.class;
final SpiServiceRegistry spiServiceRegistry = new SpiServiceRegistry();
final ClassLoader classLoader = containerClassLoader.getClassLoader();
final Collection<ExtensionModelLoader> extensionModelLoaders = spiServiceRegistry.lookupProviders(providerClass, classLoader);
final StringBuilder sb = new StringBuilder();
extensionModelLoaders.stream().collect(groupingBy(ExtensionModelLoader::getId)).entrySet().stream().filter(entry -> entry.getValue().size() > 1).forEach(entry -> {
// At this point we are sure there are at least 2 classes that return the same ID, we will append it to the builder
final String classes = entry.getValue().stream().map(extensionModelLoader -> extensionModelLoader.getClass().getName()).collect(Collectors.joining(", "));
sb.append(lineSeparator()).append("ID [").append(entry.getKey()).append("] is being returned by the following classes [").append(classes).append("]");
});
if (isNotBlank(sb.toString())) {
throw new MuleRuntimeException(createStaticMessage(format("There are several loaders that return the same identifier when looking up providers for '%s'. Full error list: %s", providerClass.getName(), sb.toString())));
}
extensionModelLoaders.stream().forEach(extensionModelLoader -> this.extensionModelLoaders.put(extensionModelLoader.getId(), extensionModelLoader));
if (logger.isDebugEnabled()) {
logger.debug("ExtensionModelLoader registered identifiers: {}", printExtensionModelLoaderIDs());
}
}
use of org.mule.runtime.core.api.registry.SpiServiceRegistry in project mule by mulesoft.
the class CraftedExtensionModelLoaderTestCase method spiDiscoverable.
@Test
public void spiDiscoverable() throws Exception {
ServiceRegistry registry = new SpiServiceRegistry();
Optional<ExtensionModelLoader> craftedLoader = registry.lookupProviders(ExtensionModelLoader.class, classLoader).stream().filter(p -> p instanceof CraftedExtensionModelLoader).findAny();
assertThat(craftedLoader.isPresent(), is(true));
}
use of org.mule.runtime.core.api.registry.SpiServiceRegistry in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method loadArtifactConfig.
private ConfigLine loadArtifactConfig(String name, InputStream resource) {
checkArgument(resource != null, "The given application was not found as resource");
Document document = noValidationDocumentLoader().loadDocument(context.getExtensions(), name, resource);
return new XmlApplicationParser(new XmlApplicationServiceRegistry(new SpiServiceRegistry(), context), resolveContextArtifactPluginClassLoaders()).parse(document.getDocumentElement()).orElseThrow(() -> new MuleRuntimeException(createStaticMessage("Could not load load a Configuration from the given resource")));
}
use of org.mule.runtime.core.api.registry.SpiServiceRegistry in project mule by mulesoft.
the class BasicRuntimeServicesConfigurationBuilder method doConfigure.
@Override
protected void doConfigure(MuleContext muleContext) throws Exception {
new SpiServiceRegistry().lookupProviders(Service.class, BasicRuntimeServicesConfigurationBuilder.class.getClassLoader()).forEach(service -> {
try {
startIfNeeded(service);
registerObject(muleContext, service.getName(), service);
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
});
DefaultExpressionLanguageFactoryService weaveExpressionExecutor = new WeaveDefaultExpressionLanguageFactoryService();
registerObject(muleContext, weaveExpressionExecutor.getName(), weaveExpressionExecutor);
}
Aggregations