Search in sources :

Example 36 with Processor

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

the class AbstractPipeline method doInitialise.

@Override
protected void doInitialise() throws MuleException {
    super.doInitialise();
    pipeline = createPipeline();
    if (source != null) {
        source.setListener(new Processor() {

            @Override
            public CoreEvent process(CoreEvent event) throws MuleException {
                return processToApply(event, this);
            }

            @Override
            public Publisher<CoreEvent> apply(Publisher<CoreEvent> publisher) {
                return from(publisher).transform(dispatchToFlow());
            }
        });
    }
    initialiseIfNeeded(source, muleContext);
    initialiseIfNeeded(pipeline, muleContext);
}
Also used : ReactiveProcessor(org.mule.runtime.core.api.processor.ReactiveProcessor) Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Publisher(org.reactivestreams.Publisher) MuleException(org.mule.runtime.api.exception.MuleException)

Example 37 with Processor

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

the class DefaultPolicyManager method createSourcePolicyInstance.

@Override
public SourcePolicy createSourcePolicyInstance(Component source, CoreEvent sourceEvent, Processor flowExecutionProcessor, MessageSourceResponseParametersProcessor messageSourceResponseParametersProcessor) {
    PolicyPointcutParameters sourcePointcutParameters = policyPointcutParametersManager.createSourcePointcutParameters(source, sourceEvent);
    List<Policy> parameterizedPolicies = policyProvider.findSourceParameterizedPolicies(sourcePointcutParameters);
    if (parameterizedPolicies.isEmpty()) {
        return event -> from(process(event, flowExecutionProcessor)).defaultIfEmpty(CoreEvent.builder(sourceEvent).message(of(null)).build()).<Either<SourcePolicyFailureResult, SourcePolicySuccessResult>>map(flowExecutionResult -> right(new SourcePolicySuccessResult(flowExecutionResult, () -> messageSourceResponseParametersProcessor.getSuccessfulExecutionResponseParametersFunction().apply(flowExecutionResult), messageSourceResponseParametersProcessor))).onErrorResume(Exception.class, e -> {
            MessagingException messagingException = e instanceof MessagingException ? (MessagingException) e : new MessagingException(event, e, (Component) flowExecutionProcessor);
            return just(Either.left(new SourcePolicyFailureResult(messagingException, () -> messageSourceResponseParametersProcessor.getFailedExecutionResponseParametersFunction().apply(messagingException.getEvent()))));
        });
    }
    return new CompositeSourcePolicy(parameterizedPolicies, lookupSourceParametersTransformer(source.getLocation().getComponentIdentifier().getIdentifier()), sourcePolicyProcessorFactory, flowExecutionProcessor, messageSourceResponseParametersProcessor);
}
Also used : Policy(org.mule.runtime.core.api.policy.Policy) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Processor(org.mule.runtime.core.api.processor.Processor) StreamingManager(org.mule.runtime.core.api.streaming.StreamingManager) Inject(javax.inject.Inject) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleContext(org.mule.runtime.core.api.MuleContext) MessageProcessors.process(org.mule.runtime.core.privileged.processor.MessageProcessors.process) Component(org.mule.runtime.api.component.Component) Map(java.util.Map) Mono.from(reactor.core.publisher.Mono.from) Mono.just(reactor.core.publisher.Mono.just) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) SourcePolicyPointcutParametersFactory(org.mule.runtime.policy.api.SourcePolicyPointcutParametersFactory) PolicyStateHandler(org.mule.runtime.core.api.policy.PolicyStateHandler) SourcePolicyParametersTransformer(org.mule.runtime.core.api.policy.SourcePolicyParametersTransformer) Collections.emptyList(java.util.Collections.emptyList) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Message.of(org.mule.runtime.api.message.Message.of) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) OperationPolicyParametersTransformer(org.mule.runtime.core.api.policy.OperationPolicyParametersTransformer) Either.right(org.mule.runtime.core.api.functional.Either.right) Either(org.mule.runtime.core.api.functional.Either) PolicyProvider(org.mule.runtime.core.api.policy.PolicyProvider) List(java.util.List) Policy(org.mule.runtime.core.api.policy.Policy) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters) Optional(java.util.Optional) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) MuleRegistry(org.mule.runtime.core.internal.registry.MuleRegistry) OperationPolicyPointcutParametersFactory(org.mule.runtime.policy.api.OperationPolicyPointcutParametersFactory) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Component(org.mule.runtime.api.component.Component) PolicyPointcutParameters(org.mule.runtime.policy.api.PolicyPointcutParameters)

Example 38 with Processor

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

the class EventCorrelator method handleGroupExpiry.

protected void handleGroupExpiry(EventGroup group) throws MuleException {
    try {
        removeEventGroup(group);
    } catch (ObjectStoreException e) {
        throw new DefaultMuleException(e);
    }
    if (isFailOnTimeout()) {
        CoreEvent messageCollectionEvent = group.getMessageCollectionEvent();
        notificationFirer.dispatch(new RoutingNotification(messageCollectionEvent.getMessage(), null, CORRELATION_TIMEOUT));
        try {
            group.clear();
        } catch (ObjectStoreException e) {
            logger.warn("Failed to clear group with id " + group.getGroupId() + " since underlying ObjectStore threw Exception:" + e.getMessage());
        }
        throw new CorrelationTimeoutException(correlationTimedOut(group.getGroupId()));
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug(MessageFormat.format("Aggregator expired, but ''failOnTimeOut'' is false. Forwarding {0} events out of {1} " + "total for group ID: {2}", group.size(), group.expectedSize().map(v -> v.toString()).orElse(NOT_SET), group.getGroupId()));
        }
        try {
            if (!(group.getCreated() + DAYS.toMillis(1) < currentTimeMillis())) {
                CoreEvent newEvent = CoreEvent.builder(callback.aggregateEvents(group)).build();
                group.clear();
                if (!correlatorStore.contains((String) group.getGroupId(), getExpiredAndDispatchedPartitionKey())) {
                    // returned?
                    if (timeoutMessageProcessor != null) {
                        processToApply(newEvent, timeoutMessageProcessor, false, empty());
                    } else {
                        throw new MessagingException(createStaticMessage(MessageFormat.format("Group {0} timed out, but no timeout message processor was " + "configured.", group.getGroupId())), newEvent);
                    }
                    correlatorStore.store((String) group.getGroupId(), group.getCreated(), getExpiredAndDispatchedPartitionKey());
                } else {
                    logger.warn(MessageFormat.format("Discarding group {0}", group.getGroupId()));
                }
            }
        } catch (MessagingException me) {
            throw me;
        } catch (Exception e) {
            throw new MessagingException(group.getMessageCollectionEvent(), e);
        }
    }
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) NOT_SET(org.mule.runtime.core.api.message.GroupCorrelation.NOT_SET) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) System.currentTimeMillis(java.lang.System.currentTimeMillis) DeserializationPostInitialisable(org.mule.runtime.core.privileged.store.DeserializationPostInitialisable) LoggerFactory(org.slf4j.LoggerFactory) MINUTES(java.util.concurrent.TimeUnit.MINUTES) PartitionableObjectStore(org.mule.runtime.api.store.PartitionableObjectStore) Expirable(org.mule.runtime.core.privileged.util.monitor.Expirable) Processor(org.mule.runtime.core.api.processor.Processor) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) MuleContext(org.mule.runtime.core.api.MuleContext) MuleException(org.mule.runtime.api.exception.MuleException) Scheduler(org.mule.runtime.api.scheduler.Scheduler) DAYS(java.util.concurrent.TimeUnit.DAYS) CORRELATION_TIMEOUT(org.mule.runtime.api.notification.RoutingNotification.CORRELATION_TIMEOUT) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) Mono.empty(reactor.core.publisher.Mono.empty) ExpiryMonitor(org.mule.runtime.core.privileged.util.monitor.ExpiryMonitor) RoutingNotification(org.mule.runtime.api.notification.RoutingNotification) Disposable(org.mule.runtime.api.lifecycle.Disposable) Startable(org.mule.runtime.api.lifecycle.Startable) MISSED_AGGREGATION_GROUP_EVENT(org.mule.runtime.api.notification.RoutingNotification.MISSED_AGGREGATION_GROUP_EVENT) Logger(org.slf4j.Logger) MessageProcessors.processToApply(org.mule.runtime.core.privileged.processor.MessageProcessors.processToApply) ObjectStore(org.mule.runtime.api.store.ObjectStore) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) StringMessageUtils.truncate(org.mule.runtime.core.api.util.StringMessageUtils.truncate) StringMessageUtils(org.mule.runtime.core.api.util.StringMessageUtils) String.format(java.lang.String.format) EventGroup(org.mule.runtime.core.internal.routing.EventGroup) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) List(java.util.List) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) CoreMessages.objectIsNull(org.mule.runtime.core.api.config.i18n.CoreMessages.objectIsNull) CoreMessages.correlationTimedOut(org.mule.runtime.core.api.config.i18n.CoreMessages.correlationTimedOut) FlowConstruct(org.mule.runtime.core.api.construct.FlowConstruct) NotificationDispatcher(org.mule.runtime.api.notification.NotificationDispatcher) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RoutingNotification(org.mule.runtime.api.notification.RoutingNotification) ObjectStoreException(org.mule.runtime.api.store.ObjectStoreException) ObjectDoesNotExistException(org.mule.runtime.api.store.ObjectDoesNotExistException) MuleException(org.mule.runtime.api.exception.MuleException) MessagingException(org.mule.runtime.core.internal.exception.MessagingException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException) ObjectAlreadyExistsException(org.mule.runtime.api.store.ObjectAlreadyExistsException)

Example 39 with Processor

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

the class FirstSuccessfulRoutingStrategy method route.

@Override
public CoreEvent route(CoreEvent event, List<Processor> messageProcessors) throws MuleException {
    CoreEvent returnEvent = null;
    boolean failed = true;
    Exception failExceptionCause = null;
    validateMessageIsNotConsumable(event.getMessage());
    for (Processor mp : messageProcessors) {
        try {
            returnEvent = processToApplyWithChildContext(event, mp);
            if (returnEvent == null) {
                failed = false;
            } else if (returnEvent.getMessage() == null) {
                failed = true;
            } else {
                failed = returnEvent.getError().isPresent();
            }
        } catch (Exception ex) {
            failed = true;
            failExceptionCause = ex;
        }
        if (!failed) {
            break;
        }
    }
    if (failed) {
        if (failExceptionCause != null) {
            throw new RoutingFailedException(createStaticMessage("All processors failed during 'first-successful' routing strategy"), failExceptionCause);
        } else {
            throw new RoutingFailedException(createStaticMessage("All processors failed during 'first-successful' routing strategy"));
        }
    }
    return returnEvent != null ? builder(event.getContext(), returnEvent).build() : null;
}
Also used : Processor(org.mule.runtime.core.api.processor.Processor) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) DispatchException(org.mule.runtime.core.privileged.connector.DispatchException) RoutingException(org.mule.runtime.core.privileged.routing.RoutingException)

Example 40 with Processor

use of org.mule.runtime.core.api.processor.Processor 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)

Aggregations

Processor (org.mule.runtime.core.api.processor.Processor)58 Test (org.junit.Test)31 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)24 MuleException (org.mule.runtime.api.exception.MuleException)15 ReactiveProcessor (org.mule.runtime.core.api.processor.ReactiveProcessor)14 Component (org.mule.runtime.api.component.Component)12 ArrayList (java.util.ArrayList)11 InternalProcessor (org.mule.runtime.core.privileged.processor.InternalProcessor)11 Publisher (org.reactivestreams.Publisher)11 Message (org.mule.runtime.api.message.Message)10 MessagingException (org.mule.runtime.core.internal.exception.MessagingException)10 Map (java.util.Map)9 Arrays.asList (java.util.Arrays.asList)8 Flow (org.mule.runtime.core.api.construct.Flow)8 Inject (javax.inject.Inject)7 Assert.assertThat (org.junit.Assert.assertThat)7 Mockito.mock (org.mockito.Mockito.mock)7 Mockito.when (org.mockito.Mockito.when)7 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)7 Disposable (org.mule.runtime.api.lifecycle.Disposable)7