Search in sources :

Example 1 with ReactiveProcessor

use of org.mule.runtime.core.api.processor.ReactiveProcessor in project mule by mulesoft.

the class AbstractMessageProcessorChain method apply.

@Override
public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
    List<BiFunction<Processor, ReactiveProcessor, ReactiveProcessor>> interceptors = resolveInterceptors();
    Flux<CoreEvent> stream = from(publisher);
    for (Processor processor : getProcessorsToExecute()) {
        // Perform assembly for processor chain by transforming the existing publisher with a publisher function for each processor
        // along with the interceptors that decorate it.
        stream = stream.transform(applyInterceptors(interceptors, processor)).subscriberContext(context -> context.put(REACTOR_ON_OPERATOR_ERROR_LOCAL, getLocalOperatorErrorHook(processor))).errorStrategyContinue(getContinueStrategyErrorHandler(processor));
    }
    return stream.subscriberContext(ctx -> {
        ClassLoader tccl = currentThread().getContextClassLoader();
        if (tccl == null || tccl.getParent() == null || appClClass == null || !appClClass.isAssignableFrom(tccl.getClass())) {
            return ctx;
        } else {
            return ctx.put(TCCL_ORIGINAL_REACTOR_CTX_KEY, tccl).put(TCCL_REACTOR_CTX_KEY, tccl.getParent());
        }
    });
}
Also used : InterceptedReactiveProcessor(org.mule.runtime.core.internal.processor.chain.InterceptedReactiveProcessor) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) Processor(org.mule.runtime.core.api.processor.Processor) BiFunction(java.util.function.BiFunction) CoreEvent(org.mule.runtime.core.api.event.CoreEvent)

Example 2 with ReactiveProcessor

use of org.mule.runtime.core.api.processor.ReactiveProcessor in project mule by mulesoft.

the class ReactiveAroundInterceptorAdapter method doAround.

private CompletableFuture<InternalEvent> doAround(InternalEvent event, ProcessorInterceptor interceptor, Processor component, Map<String, String> dslParameters, ReactiveProcessor next) {
    final InternalEvent eventWithResolvedParams = addResolvedParameters(event, component, dslParameters);
    DefaultInterceptionEvent interceptionEvent = new DefaultInterceptionEvent(eventWithResolvedParams);
    final ReactiveInterceptionAction reactiveInterceptionAction = new ReactiveInterceptionAction(interceptionEvent, next, component, ((PrivilegedMuleContext) getMuleContext()).getErrorTypeLocator());
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Calling around() for '{}' in processor '{}'...", interceptor, ((Component) component).getLocation().getLocation());
    }
    try {
        return withContextClassLoader(interceptor.getClass().getClassLoader(), () -> interceptor.around(((Component) component).getLocation(), getResolvedParams(eventWithResolvedParams), interceptionEvent, reactiveInterceptionAction)).exceptionally(t -> {
            if (t instanceof MessagingException) {
                throw new CompletionException(t);
            } else {
                throw new CompletionException(createMessagingException(eventWithResolvedParams, t instanceof CompletionException ? t.getCause() : t, ((Component) component)));
            }
        }).thenApply(interceptedEvent -> interceptedEvent != null ? ((DefaultInterceptionEvent) interceptedEvent).resolve() : null);
    } catch (Exception e) {
        throw propagate(createMessagingException(interceptionEvent.resolve(), e, (Component) component));
    }
}
Also used : ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) Logger(org.slf4j.Logger) Exceptions.propagate(reactor.core.Exceptions.propagate) Flux.from(reactor.core.publisher.Flux.from) LoggerFactory(org.slf4j.LoggerFactory) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) InterceptionAction(org.mule.runtime.api.interception.InterceptionAction) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) CompletableFuture(java.util.concurrent.CompletableFuture) CompletionException(java.util.concurrent.CompletionException) Processor(org.mule.runtime.core.api.processor.Processor) ProcessorInterceptorFactory(org.mule.runtime.api.interception.ProcessorInterceptorFactory) Mono.fromFuture(reactor.core.publisher.Mono.fromFuture) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) InterceptionEvent(org.mule.runtime.api.interception.InterceptionEvent) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) PrivilegedMuleContext(org.mule.runtime.core.privileged.PrivilegedMuleContext) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent) DefaultInterceptionEvent(org.mule.runtime.core.internal.interception.DefaultInterceptionEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) CompletionException(java.util.concurrent.CompletionException) Component(org.mule.runtime.api.component.Component) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) CompletionException(java.util.concurrent.CompletionException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) InternalEvent(org.mule.runtime.core.internal.message.InternalEvent)

Example 3 with ReactiveProcessor

use of org.mule.runtime.core.api.processor.ReactiveProcessor in project mule by mulesoft.

the class ReactiveInterceptorAdapter method apply.

// TODO MULE-13449 Loggers in this method must be INFO
@Override
public ReactiveProcessor apply(Processor component, ReactiveProcessor next) {
    if (!isInterceptable(component)) {
        return next;
    }
    final ComponentLocation componentLocation = ((Component) component).getLocation();
    if (!interceptorFactory.intercept(componentLocation)) {
        return next;
    }
    final ProcessorInterceptor interceptor = interceptorFactory.get();
    Map<String, String> dslParameters = (Map<String, String>) ((Component) component).getAnnotation(ANNOTATION_PARAMETERS);
    ReactiveProcessor interceptedProcessor = doApply(component, next, componentLocation, interceptor, dslParameters);
    LOGGER.debug("Interceptor '{}' for processor '{}' configured.", interceptor, componentLocation.getLocation());
    return interceptedProcessor;
}
Also used : ComponentLocation(org.mule.runtime.api.component.location.ComponentLocation) ProcessorInterceptor(org.mule.runtime.api.interception.ProcessorInterceptor) ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) Component(org.mule.runtime.api.component.Component) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) LazyMap(org.apache.commons.collections.map.LazyMap)

Aggregations

ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)3 Map (java.util.Map)2 Component (org.mule.runtime.api.component.Component)2 ComponentLocation (org.mule.runtime.api.component.location.ComponentLocation)2 ProcessorInterceptor (org.mule.runtime.api.interception.ProcessorInterceptor)2 Processor (org.mule.runtime.core.api.processor.Processor)2 HashMap (java.util.HashMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletionException (java.util.concurrent.CompletionException)1 BiFunction (java.util.function.BiFunction)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 LazyMap (org.apache.commons.collections.map.LazyMap)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 InterceptionAction (org.mule.runtime.api.interception.InterceptionAction)1 InterceptionEvent (org.mule.runtime.api.interception.InterceptionEvent)1 ProcessorInterceptorFactory (org.mule.runtime.api.interception.ProcessorInterceptorFactory)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 ClassUtils.withContextClassLoader (org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)1 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)1 DefaultInterceptionEvent (org.mule.runtime.core.internal.interception.DefaultInterceptionEvent)1