Search in sources :

Example 1 with ResolverSet

use of org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet in project mule by mulesoft.

the class DefaultImplicitConfigurationProviderFactory method createImplicitConfigurationProvider.

/**
 * {@inheritDoc}
 */
@Override
public ConfigurationProvider createImplicitConfigurationProvider(ExtensionModel extensionModel, ConfigurationModel implicitConfigurationModel, CoreEvent event, ReflectionCache reflectionCache, MuleContext muleContext) {
    if (implicitConfigurationModel == null || !canBeUsedImplicitly(implicitConfigurationModel)) {
        throw new IllegalStateException("Could not find a config for extension '" + extensionModel.getName() + "' and none can be created automatically. Please define one");
    }
    final String providerName = getImplicitConfigurationProviderName(extensionModel, implicitConfigurationModel);
    Callable<ResolverSet> resolverSetCallable = () -> buildImplicitResolverSet(implicitConfigurationModel, reflectionCache, muleContext);
    ClassLoader pluginClassloader = getClassLoader(extensionModel);
    final ResolverSet resolverSet = withContextClassLoader(pluginClassloader, resolverSetCallable);
    try {
        ImplicitConnectionProviderValueResolver implicitConnectionProviderValueResolver = new ImplicitConnectionProviderValueResolver(implicitConfigurationModel.getName(), extensionModel, implicitConfigurationModel, reflectionCache, muleContext);
        ConfigurationInstance configurationInstance = withContextClassLoader(pluginClassloader, () -> new ConfigurationInstanceFactory(extensionModel, implicitConfigurationModel, resolverSet, reflectionCache, muleContext).createConfiguration(providerName, event, implicitConnectionProviderValueResolver));
        if (resolverSet.isDynamic() || needsDynamicConnectionProvider(extensionModel, implicitConfigurationModel, implicitConnectionProviderValueResolver)) {
            return new DynamicConfigurationProvider(providerName, extensionModel, implicitConfigurationModel, resolverSet, implicitConnectionProviderValueResolver, ImmutableExpirationPolicy.getDefault(new LocalTimeSupplier()), reflectionCache, muleContext);
        }
        return new ConfigurationProviderToolingAdapter(providerName, extensionModel, implicitConfigurationModel, configurationInstance, reflectionCache, muleContext);
    } catch (Exception e) {
        throw new MuleRuntimeException(createStaticMessage(format("Could not create an implicit configuration '%s' for the extension '%s'", implicitConfigurationModel.getName(), extensionModel.getName())), e);
    }
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) ImplicitObjectUtils.buildImplicitResolverSet(org.mule.runtime.module.extension.internal.loader.utils.ImplicitObjectUtils.buildImplicitResolverSet) ImplicitConnectionProviderValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ImplicitConnectionProviderValueResolver) LocalTimeSupplier(org.mule.runtime.core.internal.time.LocalTimeSupplier) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Example 2 with ResolverSet

use of org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet in project mule by mulesoft.

the class DefaultImplicitConnectionProviderFactory method createImplicitConnectionProvider.

/**
 * {@inheritDoc}
 */
@Override
public <T> Pair<ConnectionProvider<T>, ResolverSetResult> createImplicitConnectionProvider(String configName, CoreEvent event) {
    ResolverSet resolverSet = resolverSetProvider.get();
    ConnectionProviderObjectBuilder<T> builder = new DefaultConnectionProviderObjectBuilder<>(connectionProviderModel, resolverSet, extensionModel, muleContext);
    builder.setOwnerConfigName(configName);
    try {
        return builder.build(from(event));
    } catch (MuleException e) {
        throw new MuleRuntimeException(e);
    }
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) ImplicitObjectUtils.buildImplicitResolverSet(org.mule.runtime.module.extension.internal.loader.utils.ImplicitObjectUtils.buildImplicitResolverSet) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException)

Example 3 with ResolverSet

use of org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet in project mule by mulesoft.

the class ComponentMessageProcessorBuilder method getArgumentsResolverSet.

protected ResolverSet getArgumentsResolverSet() throws ConfigurationException {
    final ResolverSet parametersResolverSet = ParametersResolver.fromValues(parameters, muleContext, lazyModeEnabled, reflectionCache).getParametersAsResolverSet(operationModel, muleContext);
    final ResolverSet childsResolverSet = ParametersResolver.fromValues(parameters, muleContext, lazyModeEnabled, reflectionCache).getNestedComponentsAsResolverSet(operationModel);
    return parametersResolverSet.merge(childsResolverSet);
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet)

Example 4 with ResolverSet

use of org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet in project mule by mulesoft.

the class DynamicConfigurationProviderTestCase method resolveProviderParamsDifferentInstance.

@Test
public void resolveProviderParamsDifferentInstance() throws Exception {
    HeisenbergExtension config = (HeisenbergExtension) provider.get(event).getValue();
    mockConfigurationInstance(configurationModel, MODULE_CLASS.newInstance());
    ResolverSet providerResolverSet = mock(ResolverSet.class);
    when(connectionProviderResolver.getResolverSet()).thenReturn(of(providerResolverSet));
    when(connectionProviderResolver.getObjectBuilder()).thenReturn(empty());
    when(providerResolverSet.resolve(from(event))).thenReturn(mock(ResolverSetResult.class));
    assertThat(provider.get(event).getValue(), is(not(sameInstance(config))));
    verify(resolverSet, times(2)).resolve(from(event));
    verify(providerResolverSet, times(1)).resolve(from(event));
    verify(connectionProviderResolver, times(2)).resolve(from(event));
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) ResolverSetResult(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSetResult) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with ResolverSet

use of org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet in project mule by mulesoft.

the class DynamicConfigurationProviderTestCase method resolveCachedWithProviderParams.

@Test
public void resolveCachedWithProviderParams() throws Exception {
    ResolverSet providerResolverSet = mock(ResolverSet.class);
    when(connectionProviderResolver.getResolverSet()).thenReturn(of(providerResolverSet));
    when(connectionProviderResolver.getObjectBuilder()).thenReturn(empty());
    when(providerResolverSet.resolve(from(event))).thenReturn(resolverSetResult);
    final int count = 10;
    HeisenbergExtension config = (HeisenbergExtension) provider.get(event).getValue();
    for (int i = 1; i < count; i++) {
        assertThat(provider.get(event).getValue(), is(sameInstance(config)));
    }
    verify(providerResolverSet, times(count)).resolve(from(event));
    verify(resolverSet, times(count)).resolve(from(event));
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) HeisenbergExtension(org.mule.test.heisenberg.extension.HeisenbergExtension) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

ResolverSet (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet)11 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)4 Test (org.junit.Test)2 MuleContext (org.mule.runtime.core.api.MuleContext)2 ConfigurationException (org.mule.runtime.core.api.config.ConfigurationException)2 ClassUtils.withContextClassLoader (org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)2 ImplicitObjectUtils.buildImplicitResolverSet (org.mule.runtime.module.extension.internal.loader.utils.ImplicitObjectUtils.buildImplicitResolverSet)2 ConnectionProviderResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ConnectionProviderResolver)2 ImplicitConnectionProviderValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ImplicitConnectionProviderValueResolver)2 SmallTest (org.mule.tck.size.SmallTest)2 HeisenbergExtension (org.mule.test.heisenberg.extension.HeisenbergExtension)2 String.format (java.lang.String.format)1 Thread.currentThread (java.lang.Thread.currentThread)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1 Optional.ofNullable (java.util.Optional.ofNullable)1 MetadataType (org.mule.metadata.api.model.MetadataType)1 MuleException (org.mule.runtime.api.exception.MuleException)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)1