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);
}
}
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;
}
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);
}
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);
}
Aggregations