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);
}
}
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);
}
}
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);
}
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));
}
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));
}
Aggregations