use of org.mule.runtime.api.util.LazyValue in project mule by mulesoft.
the class ComponentMessageProcessor method createComponentExecutor.
private ComponentExecutor<T> createComponentExecutor() {
Map<String, Object> params = new HashMap<>();
LazyValue<Optional<ConfigurationInstance>> staticConfiguration = new LazyValue<>(this::getStaticConfiguration);
LazyValue<ValueResolvingContext> resolvingContext = new LazyValue<>(() -> {
CoreEvent initialiserEvent = null;
try {
initialiserEvent = getInitialiserEvent();
return from(initialiserEvent, staticConfiguration.get());
} finally {
if (initialiserEvent != null) {
((BaseEventContext) initialiserEvent.getContext()).success();
}
}
});
componentModel.getParameterGroupModels().stream().forEach(group -> {
if (group.getName().equals(DEFAULT_GROUP_NAME)) {
group.getParameterModels().stream().filter(p -> p.getModelProperty(FieldOperationParameterModelProperty.class).isPresent()).forEach(p -> {
ValueResolver<?> resolver = resolverSet.getResolvers().get(p.getName());
if (resolver != null) {
try {
params.put(getMemberName(p), resolveValue(resolver, resolvingContext.get()));
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
});
} else {
ParameterGroupDescriptor groupDescriptor = group.getModelProperty(ParameterGroupModelProperty.class).map(g -> g.getDescriptor()).orElse(null);
if (groupDescriptor == null) {
return;
}
List<ParameterModel> fieldParameters = getGroupsOfFieldParameters(group);
if (fieldParameters.isEmpty()) {
return;
}
ObjectBuilder groupBuilder = createFieldParameterGroupBuilder(groupDescriptor, fieldParameters);
try {
params.put(((Field) groupDescriptor.getContainer()).getName(), groupBuilder.build(resolvingContext.get()));
} catch (MuleException e) {
throw new MuleRuntimeException(e);
}
}
});
return getOperationExecutorFactory(componentModel).createExecutor(componentModel, params);
}
use of org.mule.runtime.api.util.LazyValue in project mule by mulesoft.
the class ConnectionArgumentResolver method resolve.
/**
* Returns the connection previously set on the {@code executionContext} under the key
* {@link ExtensionProperties#CONNECTION_PARAM}
*
* @param executionContext an {@link ExecutionContext}
* @return the connection
* @throws IllegalArgumentException if the connection was not set
* @throws ClassCastException if {@code executionContext} is not an {@link ExecutionContextAdapter}
*/
@Override
public LazyValue<Object> resolve(ExecutionContext executionContext) {
return new LazyValue<>(() -> {
ConnectionHandler connectionHandler = ((ExecutionContextAdapter<ComponentModel>) executionContext).getVariable(CONNECTION_PARAM);
checkArgument(connectionHandler != null, "No connection was provided for the component [" + executionContext.getComponentModel().getName() + "]");
try {
return connectionHandler.getConnection();
} catch (ConnectionException e) {
throw new MuleRuntimeException(I18nMessageFactory.createStaticMessage(String.format("Error was found trying to obtain a connection to execute %s '%s' of extension '%s'", getComponentModelTypeName(executionContext.getComponentModel()), executionContext.getComponentModel().getName(), executionContext.getExtensionModel().getName())), e);
}
});
}
Aggregations