use of org.mule.runtime.core.api.context.DefaultMuleContextFactory in project mule by mulesoft.
the class QueueManagerLifecycleOrderTestCase method before.
@Before
public void before() throws InitialisationException, ConfigurationException {
Map<String, Object> objects = new HashMap<>();
objects.put(OBJECT_QUEUE_MANAGER, rtqm);
objects.put(OBJECT_SECURITY_MANAGER, new DefaultMuleSecurityManager());
objects.put(PROCESSOR_INTERCEPTOR_MANAGER_REGISTRY_KEY, mock(ProcessorInterceptorManager.class));
muleContext = new DefaultMuleContextFactory().createMuleContext(testServicesConfigurationBuilder, new SimpleConfigurationBuilder(objects));
testServicesConfigurationBuilder.configure(muleContext);
}
use of org.mule.runtime.core.api.context.DefaultMuleContextFactory in project mule by mulesoft.
the class DomainContextBuilder method build.
public MuleContext build() throws Exception {
List<ConfigurationBuilder> builders = new ArrayList<>(3);
ConfigurationBuilder cfgBuilder = getDomainBuilder(domainConfig);
builders.add(cfgBuilder);
addBuilders(builders);
DefaultMuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
MuleContext domainContext = muleContextFactory.createMuleContext(builders, muleContextBuilder);
domainContext.start();
return domainContext;
}
use of org.mule.runtime.core.api.context.DefaultMuleContextFactory in project mule by mulesoft.
the class AbstractBenchmark method createMuleContextWithServices.
protected MuleContext createMuleContextWithServices() throws MuleException {
MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
List<ConfigurationBuilder> builderList = new ArrayList<>();
builderList.add(new BasicRuntimeServicesConfigurationBuilder());
builderList.add(new DefaultsConfigurationBuilder());
return muleContextFactory.createMuleContext(builderList.toArray(new ConfigurationBuilder[] {}));
}
use of org.mule.runtime.core.api.context.DefaultMuleContextFactory in project mule by mulesoft.
the class AbstractMuleContextTestCase method createMuleContext.
protected MuleContext createMuleContext() throws Exception {
// Should we set up the manager for every method?
MuleContext context;
if (isDisposeContextPerClass() && muleContext != null) {
context = muleContext;
} else {
final ClassLoader executionClassLoader = getExecutionClassLoader();
final ClassLoader originalContextClassLoader = currentThread().getContextClassLoader();
try {
currentThread().setContextClassLoader(executionClassLoader);
MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
List<ConfigurationBuilder> builders = new ArrayList<>();
builders.add(new SimpleConfigurationBuilder(getStartUpRegistryObjects()));
addBuilders(builders);
builders.add(getBuilder());
MuleContextBuilder contextBuilder = MuleContextBuilder.builder(APP);
DefaultMuleConfiguration muleConfiguration = new DefaultMuleConfiguration();
String workingDirectory = this.workingDirectory.getRoot().getAbsolutePath();
LOGGER.info("Using working directory for test: " + workingDirectory);
muleConfiguration.setWorkingDirectory(workingDirectory);
muleConfiguration.setId(this.getClass().getSimpleName() + "#" + name.getMethodName());
contextBuilder.setMuleConfiguration(muleConfiguration);
contextBuilder.setExecutionClassLoader(executionClassLoader);
contextBuilder.setObjectSerializer(getObjectSerializer());
contextBuilder.setDeploymentProperties(getDeploymentProperties());
configureMuleContext(contextBuilder);
context = muleContextFactory.createMuleContext(builders, contextBuilder);
recordSchedulersOnInit(context);
if (!isGracefulShutdown()) {
// Even though graceful shutdown is disabled allow small amount of time to avoid rejection errors when stream emits
// complete signal
((DefaultMuleConfiguration) context.getConfiguration()).setShutdownTimeout(NON_GRACEFUL_SHUTDOWN_TIMEOUT);
}
} finally {
currentThread().setContextClassLoader(originalContextClassLoader);
}
}
return context;
}
use of org.mule.runtime.core.api.context.DefaultMuleContextFactory in project mule by mulesoft.
the class ArtifactContextBuilder method build.
/**
* @return the {@code MuleContext} created with the provided configuration
* @throws ConfigurationException when there's a problem creating the {@code MuleContext}
* @throws InitialisationException when a certain configuration component failed during initialisation phase
*/
public ArtifactContext build() throws InitialisationException, ConfigurationException {
checkState(executionClassLoader != null, EXECUTION_CLASSLOADER_WAS_NOT_SET);
checkState(classLoaderRepository != null, CLASS_LOADER_REPOSITORY_WAS_NOT_SET);
checkState(POLICY.equals(artifactType) || APP.equals(artifactType) || parentArtifact == null, ONLY_APPLICATIONS_OR_POLICIES_ARE_ALLOWED_TO_HAVE_A_PARENT_ARTIFACT);
try {
return withContextClassLoader(executionClassLoader, () -> {
List<ConfigurationBuilder> builders = new LinkedList<>();
builders.addAll(additionalBuilders);
builders.add(new ArtifactBootstrapServiceDiscovererConfigurationBuilder(artifactPlugins));
if (extensionManagerFactory == null) {
if (parentArtifact == null) {
extensionManagerFactory = new ArtifactExtensionManagerFactory(artifactPlugins, extensionModelLoaderRepository, new DefaultExtensionManagerFactory());
} else {
extensionManagerFactory = new CompositeArtifactExtensionManagerFactory(parentArtifact, extensionModelLoaderRepository, artifactPlugins, new DefaultExtensionManagerFactory());
}
}
builders.add(new ArtifactExtensionManagerConfigurationBuilder(artifactPlugins, extensionManagerFactory));
builders.add(createConfigurationBuilderFromApplicationProperties());
// TODO MULE-14289 (elrodro83) pass this object to the builder instead of looking it up here
ArtifactConfigurationProcessor artifactConfigurationProcessor = ArtifactConfigurationProcessor.discover();
AtomicReference<ArtifactContext> artifactContext = new AtomicReference<>();
builders.add(new ConfigurationBuilder() {
@Override
public void configure(MuleContext muleContext) throws ConfigurationException {
if (serviceRepository != null) {
serviceConfigurators.add(new ContainerServicesMuleContextConfigurator(serviceRepository));
}
if (classLoaderRepository != null) {
serviceConfigurators.add(customizationService -> customizationService.registerCustomServiceImpl(OBJECT_CLASSLOADER_REPOSITORY, classLoaderRepository));
}
if (policyProvider != null) {
serviceConfigurators.add(customizationService -> customizationService.registerCustomServiceImpl(OBJECT_POLICY_PROVIDER, policyProvider));
}
ArtifactContextConfiguration.ArtifactContextConfigurationBuilder artifactContextConfigurationBuilder = ArtifactContextConfiguration.builder().setMuleContext(muleContext).setConfigResources(configurationFiles).setArtifactDeclaration(artifactDeclaration).setArtifactProperties(merge(artifactProperties, muleContext.getDeploymentProperties())).setArtifactType(artifactType).setEnableLazyInitialization(enableLazyInit).setDisableXmlValidations(disableXmlValidations).setServiceConfigurators(serviceConfigurators);
if (parentArtifact != null) {
artifactContextConfigurationBuilder.setParentContext(parentArtifact.getRegistry().lookupByType(MuleContext.class).get());
}
artifactContext.set(artifactConfigurationProcessor.createArtifactContext(artifactContextConfigurationBuilder.build()));
((DefaultMuleConfiguration) muleContext.getConfiguration()).setDataFolderName(dataFolderName);
}
@Override
public void addServiceConfigurator(ServiceConfigurator serviceConfigurator) {
// Nothing to do
}
});
DefaultMuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
if (muleContextListener != null) {
muleContextFactory.addListener(muleContextListener);
}
if (APP.equals(artifactType)) {
muleContextBuilder = new ApplicationMuleContextBuilder(artifactName, artifactProperties, defaultEncoding);
} else if (POLICY.equals(artifactType)) {
muleContextBuilder = new PolicyMuleContextBuilder(artifactName, artifactProperties, defaultEncoding);
} else {
muleContextBuilder = new DomainMuleContextBuilder(artifactName);
}
muleContextBuilder.setExecutionClassLoader(this.executionClassLoader);
ArtifactObjectSerializer objectSerializer = new ArtifactObjectSerializer(classLoaderRepository);
muleContextBuilder.setObjectSerializer(objectSerializer);
muleContextBuilder.setDeploymentProperties(properties);
if (parentArtifact != null) {
builders.add(new ConnectionManagerConfigurationBuilder(parentArtifact));
muleContextBuilder.setErrorTypeRepository(createCompositeErrorTypeRepository(parentArtifact.getRegistry().lookupByType(MuleContext.class).get().getErrorTypeRepository()));
} else {
builders.add(new ConnectionManagerConfigurationBuilder());
}
try {
muleContextFactory.createMuleContext(builders, muleContextBuilder);
return artifactContext.get();
} catch (InitialisationException e) {
throw new ConfigurationException(e);
}
});
} catch (MuleRuntimeException e) {
// We need this exception to be thrown as they are since the are possible causes of connectivity errors
if (e.getCause() instanceof InitialisationException) {
throw (InitialisationException) e.getCause();
}
if (e.getCause() instanceof ConfigurationException) {
throw (ConfigurationException) e.getCause();
}
throw e;
}
}
Aggregations