use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.
the class DefaultMuleCoreExtensionManagerServer method initializeCoreExtensions.
private void initializeCoreExtensions() throws MuleException {
LOGGER.info("Initializing core extensions");
Injector simpleRegistry = createContainerInjector();
for (MuleCoreExtension extension : orderedCoreExtensions) {
if (extension instanceof DeploymentServiceAware) {
((DeploymentServiceAware) extension).setDeploymentService(deploymentService);
}
if (extension instanceof RepositoryServiceAware) {
((RepositoryServiceAware) extension).setRepositoryService(repositoryService);
}
if (extension instanceof ToolingServiceAware) {
((ToolingServiceAware) extension).setToolingService(toolingService);
}
if (extension instanceof ArtifactDeploymentListener) {
deploymentService.addDeploymentListener(createDeploymentListenerAdapter((ArtifactDeploymentListener) extension, APP));
deploymentService.addDomainDeploymentListener(createDeploymentListenerAdapter((ArtifactDeploymentListener) extension, DOMAIN));
}
if (extension instanceof DeploymentListener) {
deploymentService.addDeploymentListener((DeploymentListener) extension);
}
if (extension instanceof CoreExtensionsAware) {
((CoreExtensionsAware) extension).setCoreExtensions(orderedCoreExtensions);
}
if (extension instanceof ArtifactClassLoaderManagerAware) {
((ArtifactClassLoaderManagerAware) extension).setArtifactClassLoaderManager(artifactClassLoaderManager);
}
simpleRegistry.inject(extension);
extension.initialise();
initializedCoreExtensions.add(extension);
LOGGER.info("Core extension '{}' initialized", extension.toString());
}
}
use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.
the class ClasspathMuleCoreExtensionDiscovererTestCase method setsContainerClassLoaderOnDiscoveredExtensions.
@Test
public void setsContainerClassLoaderOnDiscoveredExtensions() throws Exception {
final ArtifactClassLoader artifactClassLoader = mock(ArtifactClassLoader.class);
final ClassLoader classLoader = mock(ClassLoader.class);
final URL resource = getClass().getClassLoader().getResource("test-core-extension.properties");
when(classLoader.getResources(CORE_EXTENSION_RESOURCE_NAME)).thenReturn(new EnumerationAdapter<URL>(Collections.singleton(resource)));
when(artifactClassLoader.getClassLoader()).thenReturn(classLoader);
final ClasspathMuleCoreExtensionDiscoverer discoverer = new ClasspathMuleCoreExtensionDiscoverer(artifactClassLoader);
// Uses context classloader to force discovering of the test properties
final List<MuleCoreExtension> discover = withContextClassLoader(artifactClassLoader.getClassLoader(), () -> {
try {
return discoverer.discover();
} catch (DefaultMuleException e) {
throw new IllegalStateException(e);
}
});
assertThat(discover.size(), equalTo(1));
assertThat(discover.get(0), instanceOf(TestCoreExtension.class));
assertThat(((TestCoreExtension) discover.get(0)).containerClassLoader, is(artifactClassLoader));
}
use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.
the class DefaultMuleCoreExtensionManagerTestCase method startsCoreExtensionsInOrder.
@Test
public void startsCoreExtensionsInOrder() throws Exception {
List<MuleCoreExtension> extensions = new LinkedList<>();
MuleCoreExtension extension1 = mock(MuleCoreExtension.class);
MuleCoreExtension extension2 = mock(MuleCoreExtension.class);
extensions.add(extension1);
extensions.add(extension2);
when(coreExtensionDiscoverer.discover()).thenReturn(extensions);
List<MuleCoreExtension> orderedExtensions = new LinkedList<>();
orderedExtensions.add(extension2);
orderedExtensions.add(extension1);
when(coreExtensionDependencyResolver.resolveDependencies(extensions)).thenReturn(orderedExtensions);
coreExtensionManager.initialise();
coreExtensionManager.start();
InOrder ordered = inOrder(extension1, extension2);
ordered.verify(extension2).start();
ordered.verify(extension1).start();
}
use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.
the class DefaultMuleCoreExtensionManagerTestCase method assertArtifactDeploymentListener.
private void assertArtifactDeploymentListener(ArtifactDeploymentListener extension) throws Exception {
List<MuleCoreExtension> extensions = new LinkedList<>();
extensions.add((MuleCoreExtension) extension);
when(coreExtensionDiscoverer.discover()).thenReturn(extensions);
when(coreExtensionDependencyResolver.resolveDependencies(extensions)).thenReturn(extensions);
DeploymentService deploymentService = mock(DeploymentService.class);
TestMuleCoreExtensionManager testCoreExtensionManager = new TestMuleCoreExtensionManager(coreExtensionDiscoverer, coreExtensionDependencyResolver);
testCoreExtensionManager.setDeploymentService(deploymentService);
testCoreExtensionManager.initialise();
verify(deploymentService).addDomainDeploymentListener(testCoreExtensionManager.domainDeploymentListener);
verify(deploymentService).addDeploymentListener(testCoreExtensionManager.applicationDeploymentListener);
}
use of org.mule.runtime.container.api.MuleCoreExtension in project mule by mulesoft.
the class DefaultMuleCoreExtensionManagerTestCase method stopsCoreExtensionsInOrder.
@Test
public void stopsCoreExtensionsInOrder() throws Exception {
List<MuleCoreExtension> extensions = new LinkedList<>();
MuleCoreExtension extension1 = mock(MuleCoreExtension.class);
MuleCoreExtension extension2 = mock(MuleCoreExtension.class);
extensions.add(extension1);
extensions.add(extension2);
when(coreExtensionDiscoverer.discover()).thenReturn(extensions);
List<MuleCoreExtension> orderedExtensions = new LinkedList<>();
orderedExtensions.add(extension1);
orderedExtensions.add(extension2);
when(coreExtensionDependencyResolver.resolveDependencies(extensions)).thenReturn(orderedExtensions);
coreExtensionManager.initialise();
coreExtensionManager.start();
coreExtensionManager.stop();
InOrder ordered = inOrder(extension1, extension2);
ordered.verify(extension2).stop();
ordered.verify(extension1).stop();
}
Aggregations