Search in sources :

Example 11 with MuleCoreExtension

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());
    }
}
Also used : DeploymentServiceAware(org.mule.runtime.module.deployment.api.DeploymentServiceAware) ArtifactDeploymentListener(org.mule.runtime.module.deployment.api.ArtifactDeploymentListener) ArtifactClassLoaderManagerAware(org.mule.runtime.container.api.ArtifactClassLoaderManagerAware) Injector(org.mule.runtime.core.api.Injector) RepositoryServiceAware(org.mule.runtime.module.repository.api.RepositoryServiceAware) MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) ToolingServiceAware(org.mule.runtime.module.tooling.api.ToolingServiceAware) DeploymentListener(org.mule.runtime.module.deployment.api.DeploymentListener) ArtifactDeploymentListener(org.mule.runtime.module.deployment.api.ArtifactDeploymentListener) CoreExtensionsAware(org.mule.runtime.container.api.CoreExtensionsAware)

Example 12 with MuleCoreExtension

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));
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) URL(java.net.URL) Test(org.junit.Test)

Example 13 with MuleCoreExtension

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();
}
Also used : InOrder(org.mockito.InOrder) MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 14 with MuleCoreExtension

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);
}
Also used : DeploymentService(org.mule.runtime.module.deployment.api.DeploymentService) MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList)

Example 15 with MuleCoreExtension

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();
}
Also used : InOrder(org.mockito.InOrder) MuleCoreExtension(org.mule.runtime.container.api.MuleCoreExtension) LinkedList(java.util.LinkedList) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

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