Search in sources :

Example 1 with LazyValue

use of org.mule.runtime.api.util.LazyValue in project mule by mulesoft.

the class ReflectiveMethodComponentExecutor method getMethodArgumentResolver.

private LazyValue<ArgumentResolverDelegate> getMethodArgumentResolver(List<ParameterGroupModel> groups, Method method) {
    return new LazyValue<>(() -> {
        try {
            MethodArgumentResolverDelegate resolver = new MethodArgumentResolverDelegate(groups, method);
            initialiseIfNeeded(resolver, muleContext);
            return resolver;
        } catch (Exception e) {
            throw new MuleRuntimeException(createStaticMessage("Could not initialize argument resolver resolver"), e);
        }
    });
}
Also used : LazyValue(org.mule.runtime.api.util.LazyValue) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException)

Example 2 with LazyValue

use of org.mule.runtime.api.util.LazyValue in project mule by mulesoft.

the class BackPressureContextArgumentResolver method resolve.

@Override
public LazyValue<BackPressureContext> resolve(ExecutionContext executionContext) {
    return new LazyValue<>(() -> {
        ExecutionContextAdapter ctx = (ExecutionContextAdapter) executionContext;
        BackPressureAction action = (BackPressureAction) ctx.getVariable(BACK_PRESSURE_ACTION_CONTEXT_PARAM);
        if (action == null) {
            action = FAIL;
        }
        return new ImmutableBackPressureContext(ctx.getEvent(), action, callbackContextResolver.resolve(ctx).get());
    });
}
Also used : LazyValue(org.mule.runtime.api.util.LazyValue) BackPressureAction(org.mule.runtime.extension.api.runtime.source.BackPressureAction) ImmutableBackPressureContext(org.mule.runtime.module.extension.internal.runtime.source.ImmutableBackPressureContext) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter)

Example 3 with LazyValue

use of org.mule.runtime.api.util.LazyValue in project mule by mulesoft.

the class VoidCallbackArgumentResolver method resolve.

@Override
public LazyValue<VoidCompletionCallback> resolve(ExecutionContext executionContext) {
    return new LazyValue<>(() -> {
        ExecutionContextAdapter adapter = (ExecutionContextAdapter) executionContext;
        CompletionCallback completionCallback = (CompletionCallback) adapter.getVariable(COMPLETION_CALLBACK_CONTEXT_PARAM);
        final CoreEvent event = adapter.getEvent();
        return new VoidCompletionCallback() {

            @Override
            public void success() {
                completionCallback.success(EventedResult.from(event));
            }

            @Override
            public void error(Throwable e) {
                completionCallback.error(e);
            }
        };
    });
}
Also used : LazyValue(org.mule.runtime.api.util.LazyValue) CompletionCallback(org.mule.runtime.extension.api.runtime.process.CompletionCallback) VoidCompletionCallback(org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) VoidCompletionCallback(org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter)

Example 4 with LazyValue

use of org.mule.runtime.api.util.LazyValue in project mule by mulesoft.

the class SourceResultArgumentResolver method resolve.

@Override
public LazyValue<SourceResult> resolve(ExecutionContext executionContext) {
    return new LazyValue<>(() -> {
        Error error = errorArgumentResolver.resolve(executionContext).get();
        SourceCallbackContext callbackContext = callbackContextArgumentResolver.resolve(executionContext).get();
        if (error == null) {
            return success(callbackContext);
        } else {
            String errorIdentifier = error.getErrorType().getIdentifier();
            return isErrorGeneratingErrorResponse(errorIdentifier) ? invocationError(error, callbackContext) : responseError(error, callbackContext);
        }
    });
}
Also used : LazyValue(org.mule.runtime.api.util.LazyValue) SourceCallbackContext(org.mule.runtime.extension.api.runtime.source.SourceCallbackContext) SourceResult.responseError(org.mule.runtime.extension.api.runtime.source.SourceResult.responseError) SourceResult.invocationError(org.mule.runtime.extension.api.runtime.source.SourceResult.invocationError) Error(org.mule.runtime.api.message.Error)

Example 5 with LazyValue

use of org.mule.runtime.api.util.LazyValue in project mule by mulesoft.

the class CommonBeanDefinitionCreator method createBeanDefinitionBuilderFromObjectFactory.

private BeanDefinitionBuilder createBeanDefinitionBuilderFromObjectFactory(final SpringComponentModel componentModel, final ComponentBuildingDefinition componentBuildingDefinition) {
    ObjectTypeVisitor objectTypeVisitor = new ObjectTypeVisitor(componentModel);
    componentBuildingDefinition.getTypeDefinition().visit(objectTypeVisitor);
    Class<?> objectFactoryType = componentBuildingDefinition.getObjectFactoryType();
    Optional<Consumer<Object>> instanceCustomizationFunctionOptional;
    Map<String, Object> customProperties = getTransformerCustomProperties(componentModel);
    if (customProperties.isEmpty()) {
        instanceCustomizationFunctionOptional = empty();
    } else {
        instanceCustomizationFunctionOptional = of(object -> injectSpringProperties(customProperties, object));
    }
    return rootBeanDefinition(objectFactoryClassRepository.getObjectFactoryClass(componentBuildingDefinition, objectFactoryType, objectTypeVisitor.getType(), new LazyValue<>(() -> componentModel.getBeanDefinition().isLazyInit()), instanceCustomizationFunctionOptional));
}
Also used : BeanDefinitionPostProcessor(org.mule.runtime.config.privileged.dsl.BeanDefinitionPostProcessor) Optional.of(java.util.Optional.of) CursorStreamProvider(org.mule.runtime.api.streaming.bytes.CursorStreamProvider) SecurityFilter(org.mule.runtime.core.api.security.SecurityFilter) MuleApplicationClassLoader.resolveContextArtifactPluginClassLoaders(org.mule.runtime.deployment.model.internal.application.MuleApplicationClassLoader.resolveContextArtifactPluginClassLoaders) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) ROOT_MACRO_EXPANDED_FLOW_CONTAINER_NAME(org.mule.runtime.config.internal.dsl.model.extension.xml.MacroExpansionModuleModel.ROOT_MACRO_EXPANDED_FLOW_CONTAINER_NAME) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) MULE_PROPERTY_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.MULE_PROPERTY_IDENTIFIER) Collectors.toMap(java.util.stream.Collectors.toMap) SecurityFilterMessageProcessor(org.mule.runtime.core.privileged.processor.SecurityFilterMessageProcessor) Map(java.util.Map) CUSTOM_TRANSFORMER_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.CUSTOM_TRANSFORMER_IDENTIFIER) Pair(org.mule.runtime.api.util.Pair) ANNOTATIONS_ELEMENT_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.ANNOTATIONS_ELEMENT_IDENTIFIER) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) SPRING_PROTOTYPE_OBJECT(org.mule.runtime.config.internal.dsl.spring.BeanDefinitionFactory.SPRING_PROTOTYPE_OBJECT) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ProcessingStrategy(org.mule.runtime.core.api.processor.strategy.ProcessingStrategy) XmlCustomAttributeHandler(org.mule.runtime.config.internal.dsl.processor.xml.XmlCustomAttributeHandler) ComponentBuildingDefinition(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition) List(java.util.List) Optional(java.util.Optional) BeanUtils.copyProperty(org.apache.commons.beanutils.BeanUtils.copyProperty) QName(javax.xml.namespace.QName) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Optional.empty(java.util.Optional.empty) XmlCustomAttributeHandler.from(org.mule.runtime.config.internal.dsl.processor.xml.XmlCustomAttributeHandler.from) DefaultMessageProcessorChainBuilder(org.mule.runtime.core.privileged.processor.chain.DefaultMessageProcessorChainBuilder) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionBuilder.genericBeanDefinition(org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition) HashMap(java.util.HashMap) ANNOTATIONS_PROPERTY_NAME(org.mule.runtime.api.component.Component.ANNOTATIONS_PROPERTY_NAME) XmlMetadataAnnotations(org.mule.runtime.config.internal.parsers.XmlMetadataAnnotations) ArrayList(java.util.ArrayList) Component(org.mule.runtime.api.component.Component) Node(org.w3c.dom.Node) ServiceConfigurationError(java.util.ServiceConfigurationError) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ModuleOperationMessageProcessorChainFactoryBean(org.mule.runtime.config.internal.factories.ModuleOperationMessageProcessorChainFactoryBean) Collections.emptyMap(java.util.Collections.emptyMap) MULE_PROPERTIES_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.MULE_PROPERTIES_IDENTIFIER) PropertyComponentUtils.getPropertyValueFromPropertyComponent(org.mule.runtime.config.internal.dsl.spring.PropertyComponentUtils.getPropertyValueFromPropertyComponent) LocationExecutionContextProvider.addMetadataAnnotationsFromXml(org.mule.runtime.core.privileged.execution.LocationExecutionContextProvider.addMetadataAnnotationsFromXml) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor) AbstractComponent(org.mule.runtime.api.component.AbstractComponent) Consumer(java.util.function.Consumer) LazyValue(org.mule.runtime.api.util.LazyValue) Element(org.w3c.dom.Element) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) BeanDefinitionBuilder.rootBeanDefinition(org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) LazyValue(org.mule.runtime.api.util.LazyValue) Consumer(java.util.function.Consumer) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor)

Aggregations

LazyValue (org.mule.runtime.api.util.LazyValue)7 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)4 ExecutionContextAdapter (org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter)4 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Optional.empty (java.util.Optional.empty)2 Optional.of (java.util.Optional.of)2 MuleException (org.mule.runtime.api.exception.MuleException)2 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 String.format (java.lang.String.format)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Collections.emptyMap (java.util.Collections.emptyMap)1 ServiceConfigurationError (java.util.ServiceConfigurationError)1 Set (java.util.Set)1 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1