Search in sources :

Example 1 with MuleRegistryHelper

use of org.mule.runtime.core.internal.registry.MuleRegistryHelper in project mule by mulesoft.

the class DefaultMuleContextTestCase method getStreamCloserService.

@Test
public void getStreamCloserService() throws Exception {
    createMuleContext();
    StreamCloserService serviceFromRegistry = ((MuleContextWithRegistries) context).getRegistry().lookupObject(OBJECT_MULE_STREAM_CLOSER_SERVICE);
    MuleRegistryHelper registry = spy((MuleRegistryHelper) ((MuleContextWithRegistries) context).getRegistry());
    ((DefaultMuleContext) context).setMuleRegistry(registry);
    StreamCloserService streamCloserService = context.getStreamCloserService();
    assertThat(streamCloserService, not(nullValue()));
    assertThat(streamCloserService, is(sameInstance(serviceFromRegistry)));
    // test that subsequent invocations consistently returns the same object
    assertThat(context.getStreamCloserService(), is(sameInstance(streamCloserService)));
    // verify we're not fetching from registry many times
    verify(registry, times(1)).lookupObject(OBJECT_MULE_STREAM_CLOSER_SERVICE);
}
Also used : MuleRegistryHelper(org.mule.runtime.core.internal.registry.MuleRegistryHelper) StreamCloserService(org.mule.runtime.core.api.util.StreamCloserService) Test(org.junit.Test)

Example 2 with MuleRegistryHelper

use of org.mule.runtime.core.internal.registry.MuleRegistryHelper in project mule by mulesoft.

the class DefaultMuleContextTestCase method cachesDataTypeConversionResolver.

@Test
public void cachesDataTypeConversionResolver() throws Exception {
    createMuleContext();
    disposeIfNeeded(((MuleContextWithRegistries) context).getRegistry(), LOGGER);
    final MuleRegistryHelper muleRegistry = mock(MuleRegistryHelper.class);
    ((DefaultMuleContext) context).setMuleRegistry(muleRegistry);
    DataTypeConversionResolver dataTypeConverterResolver1 = context.getDataTypeConverterResolver();
    DataTypeConversionResolver dataTypeConverterResolver2 = context.getDataTypeConverterResolver();
    assertThat(dataTypeConverterResolver1, instanceOf(DynamicDataTypeConversionResolver.class));
    assertThat(dataTypeConverterResolver2, sameInstance(dataTypeConverterResolver1));
    verify(muleRegistry).lookupObject(OBJECT_CONVERTER_RESOLVER);
}
Also used : DynamicDataTypeConversionResolver(org.mule.runtime.core.internal.transformer.DynamicDataTypeConversionResolver) MuleRegistryHelper(org.mule.runtime.core.internal.registry.MuleRegistryHelper) DynamicDataTypeConversionResolver(org.mule.runtime.core.internal.transformer.DynamicDataTypeConversionResolver) DataTypeConversionResolver(org.mule.runtime.core.api.transformer.DataTypeConversionResolver) Test(org.junit.Test)

Example 3 with MuleRegistryHelper

use of org.mule.runtime.core.internal.registry.MuleRegistryHelper in project mule by mulesoft.

the class DefaultMuleContextBuilder method buildMuleContext.

/**
 * {@inheritDoc}
 */
@Override
public MuleContext buildMuleContext() {
    logger.debug("Building new DefaultMuleContext instance with MuleContextBuilder: " + this);
    DefaultMuleContext muleContext = createDefaultMuleContext();
    muleContext.setMuleConfiguration(injectMuleContextIfRequired(getMuleConfiguration(), muleContext));
    muleContext.setNotificationManager(injectMuleContextIfRequired(getNotificationManager(), muleContext));
    muleContext.setLifecycleManager(injectMuleContextIfRequired(getLifecycleManager(), muleContext));
    muleContext.setArtifactType(artifactType);
    DefaultRegistryBroker registryBroker = new DefaultRegistryBroker(muleContext, muleContext.getLifecycleInterceptor());
    muleContext.setRegistryBroker(registryBroker);
    MuleRegistryHelper muleRegistry = new MuleRegistryHelper(registryBroker, muleContext);
    muleContext.setMuleRegistry(muleRegistry);
    muleContext.setInjector(new RegistryDelegatingInjector(muleRegistry));
    muleContext.setExceptionListener(createExceptionListener(muleContext));
    muleContext.setExecutionClassLoader(getExecutionClassLoader());
    muleContext.setBootstrapServiceDiscoverer(injectMuleContextIfRequired(createBootstrapDiscoverer(), muleContext));
    muleContext.setDeploymentProperties(getDeploymentProperties());
    muleContext.setListeners(listeners);
    getObjectSerializer(muleContext);
    if (errorTypeRepository == null) {
        errorTypeRepository = createDefaultErrorTypeRepository();
    }
    muleContext.setErrorTypeRepository(errorTypeRepository);
    muleContext.setErrorTypeLocator(createDefaultErrorTypeLocator(errorTypeRepository));
    return muleContext;
}
Also used : MuleRegistryHelper(org.mule.runtime.core.internal.registry.MuleRegistryHelper) DefaultRegistryBroker(org.mule.runtime.core.internal.registry.DefaultRegistryBroker) RegistryDelegatingInjector(org.mule.runtime.core.internal.registry.RegistryDelegatingInjector)

Example 4 with MuleRegistryHelper

use of org.mule.runtime.core.internal.registry.MuleRegistryHelper in project mule by mulesoft.

the class SimpleRegistryBootstrap method registerTransformers.

@Override
protected void registerTransformers() throws MuleException {
    MuleRegistryHelper registry = (MuleRegistryHelper) ((MuleContextWithRegistries) muleContext).getRegistry();
    Map<String, Converter> converters = registry.lookupByType(Converter.class);
    for (Converter converter : converters.values()) {
        registry.notifyTransformerResolvers(converter, TransformerResolver.RegistryAction.ADDED);
    }
}
Also used : MuleRegistryHelper(org.mule.runtime.core.internal.registry.MuleRegistryHelper) Converter(org.mule.runtime.core.api.transformer.Converter)

Example 5 with MuleRegistryHelper

use of org.mule.runtime.core.internal.registry.MuleRegistryHelper in project mule by mulesoft.

the class ExtensionPluginMetadataGenerator method createExtensionManager.

/**
 * Creates a {@link ExtensionManager} needed for generating the metadata for an extension. It would be later discarded due to
 * the manager would have references to classes loaded with the launcher class loader instead of the hierarchical class loaders
 * created as result of the classification process.
 *
 * @return an {@link ExtensionManager} that would be used to register the extensions.
 */
private ExtensionManager createExtensionManager() {
    DefaultExtensionManager extensionManager = new DefaultExtensionManager();
    extensionManager.setMuleContext(new DefaultMuleContext() {

        private ErrorTypeRepository errorTypeRepository = createDefaultErrorTypeRepository();

        private ErrorTypeLocator errorTypeLocator = createDefaultErrorTypeLocator(errorTypeRepository);

        @Override
        public MuleRegistry getRegistry() {
            return new MuleRegistryHelper(new DefaultRegistryBroker(this, new MuleLifecycleInterceptor()), this);
        }

        @Override
        public ErrorTypeLocator getErrorTypeLocator() {
            return errorTypeLocator;
        }

        @Override
        public ErrorTypeRepository getErrorTypeRepository() {
            return errorTypeRepository;
        }
    });
    try {
        extensionManager.initialise();
    } catch (InitialisationException e) {
        throw new RuntimeException("Error while initialising the extension manager", e);
    }
    return extensionManager;
}
Also used : ErrorTypeRepository(org.mule.runtime.api.exception.ErrorTypeRepository) ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository(org.mule.runtime.core.internal.exception.ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository) MuleRegistryHelper(org.mule.runtime.core.internal.registry.MuleRegistryHelper) DefaultMuleContext(org.mule.runtime.core.internal.context.DefaultMuleContext) DefaultRegistryBroker(org.mule.runtime.core.internal.registry.DefaultRegistryBroker) ErrorTypeLocatorFactory.createDefaultErrorTypeLocator(org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator) ErrorTypeLocator(org.mule.runtime.core.privileged.exception.ErrorTypeLocator) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleLifecycleInterceptor(org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor) DefaultExtensionManager(org.mule.runtime.module.extension.internal.manager.DefaultExtensionManager)

Aggregations

MuleRegistryHelper (org.mule.runtime.core.internal.registry.MuleRegistryHelper)6 Test (org.junit.Test)2 DefaultRegistryBroker (org.mule.runtime.core.internal.registry.DefaultRegistryBroker)2 ErrorTypeRepository (org.mule.runtime.api.exception.ErrorTypeRepository)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 ComponentLocatorCreatePostProcessor (org.mule.runtime.config.internal.processor.ComponentLocatorCreatePostProcessor)1 DiscardedOptionalBeanPostProcessor (org.mule.runtime.config.internal.processor.DiscardedOptionalBeanPostProcessor)1 LifecycleStatePostProcessor (org.mule.runtime.config.internal.processor.LifecycleStatePostProcessor)1 PostRegistrationActionsPostProcessor (org.mule.runtime.config.internal.processor.PostRegistrationActionsPostProcessor)1 Converter (org.mule.runtime.core.api.transformer.Converter)1 DataTypeConversionResolver (org.mule.runtime.core.api.transformer.DataTypeConversionResolver)1 StreamCloserService (org.mule.runtime.core.api.util.StreamCloserService)1 DefaultMuleContext (org.mule.runtime.core.internal.context.DefaultMuleContext)1 ErrorTypeLocatorFactory.createDefaultErrorTypeLocator (org.mule.runtime.core.internal.exception.ErrorTypeLocatorFactory.createDefaultErrorTypeLocator)1 ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository (org.mule.runtime.core.internal.exception.ErrorTypeRepositoryFactory.createDefaultErrorTypeRepository)1 MuleLifecycleInterceptor (org.mule.runtime.core.internal.lifecycle.MuleLifecycleInterceptor)1 MuleRegistry (org.mule.runtime.core.internal.registry.MuleRegistry)1 RegistryDelegatingInjector (org.mule.runtime.core.internal.registry.RegistryDelegatingInjector)1 DynamicDataTypeConversionResolver (org.mule.runtime.core.internal.transformer.DynamicDataTypeConversionResolver)1 ErrorTypeLocator (org.mule.runtime.core.privileged.exception.ErrorTypeLocator)1