use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class DefaultStreamingManager method manage.
/**
* {@inheritDoc}
*/
@Override
public void manage(InputStream stream, CoreEvent creatorEvent) {
if (stream instanceof Cursor) {
return;
}
final BaseEventContext ctx = ((BaseEventContext) creatorEvent.getContext()).getRootContext();
ctx.onTerminated((response, throwable) -> closeQuietly(stream));
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class MessageProcessingFlowTraceManager method onMessageProcessorNotificationPreInvoke.
/**
* Callback method for when a message processor is about to be invoked.
* <p/>
* Updates the internal state of the event's {@link ProcessorsTrace} and {@link FlowCallStack} accordingly.
*
* @see DefaultProcessorsTrace#addExecutedProcessors(String)
* @see DefaultFlowCallStack#setCurrentProcessorPath(String)
*
* @param notification the notification that contains the event and the processor that is about to be invoked.
*/
public void onMessageProcessorNotificationPreInvoke(MessageProcessorNotification notification) {
String resolveProcessorRepresentation = resolveProcessorRepresentation(muleContext.getConfiguration().getId(), notification.getComponent().getLocation() != null ? notification.getComponent().getLocation().getLocation() : null, notification.getComponent());
EventContext eventContext = notification.getEventContext();
if (eventContext != null) {
((DefaultProcessorsTrace) ((BaseEventContext) eventContext).getProcessorsTrace()).addExecutedProcessors(resolveProcessorRepresentation);
}
FlowCallStack flowCallStack = ((CoreEvent) notification.getEvent()).getFlowCallStack();
if (flowCallStack != null) {
((DefaultFlowCallStack) flowCallStack).setCurrentProcessorPath(resolveProcessorRepresentation);
}
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class PolicyPointcutParametersManager method createSourcePointcutParameters.
/**
* Creates {@link PolicyPointcutParameters} for a specific source. The created parameters is also stored so it can be used in
* case a matching policy also defines an operation part.
*
* @param source the source component to which policies will be applied
* @param event the event which will execute the source policies
* @return the created {@link PolicyPointcutParameters}
*/
public PolicyPointcutParameters createSourcePointcutParameters(Component source, CoreEvent event) {
ComponentIdentifier sourceIdentifier = source.getLocation().getComponentIdentifier().getIdentifier();
PolicyPointcutParameters sourcePointcutParameters = createPointcutParameters(source, SourcePolicyPointcutParametersFactory.class, sourcePointcutFactories, factory -> factory.supportsSourceIdentifier(sourceIdentifier), factory -> factory.createPolicyPointcutParameters(source, event.getMessage().getAttributes())).orElse(new PolicyPointcutParameters(source));
String correlationId = event.getContext().getCorrelationId();
sourceParametersMap.put(correlationId, sourcePointcutParameters);
((BaseEventContext) event.getContext()).getRootContext().onTerminated((e, t) -> sourceParametersMap.remove(correlationId));
return sourcePointcutParameters;
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class Foreach method splitAndProcess.
private Publisher<CoreEvent> splitAndProcess(CoreEvent request) {
AtomicInteger count = new AtomicInteger();
final AtomicReference<CoreEvent> currentEvent = new AtomicReference<>(request);
// Split into sequence of TypedValue
return fromIterable(() -> splitRequest(request)).onErrorMap(throwable -> new MessagingException(request, throwable, Foreach.this)).transform(p -> batchSize > 1 ? from(p).buffer(batchSize).map(list -> new TypedValue<>(list, fromObject(list))) : p).flatMapSequential(typedValue -> {
EventContext parentContext = currentEvent.get().getContext();
BaseEventContext childContext = newChildContext(currentEvent.get(), ofNullable(getLocation()));
Builder partEventBuilder = builder(childContext, currentEvent.get());
if (typedValue.getValue() instanceof EventBuilderConfigurer) {
// Support EventBuilderConfigurer currently used by Batch Module
EventBuilderConfigurer configurer = (EventBuilderConfigurer) typedValue.getValue();
configurer.configure(partEventBuilder);
childContext.onResponse((e, t) -> {
configurer.eventCompleted();
});
} else if (typedValue.getValue() instanceof Message) {
// If value is a Message then use it directly conserving attributes and properties.
partEventBuilder.message((Message) typedValue.getValue());
} else {
// Otherwise create a new message
partEventBuilder.message(Message.builder().payload(typedValue).build());
}
return Mono.from(just(partEventBuilder.addVariable(counterVariableName, count.incrementAndGet()).build()).transform(nestedChain).doOnNext(completeSuccessIfNeeded(childContext, true)).switchIfEmpty(Mono.from(childContext.getResponsePublisher())).map(result -> builder(parentContext, result).build()).doOnNext(result -> currentEvent.set(CoreEvent.builder(result).build())).doOnError(MessagingException.class, me -> me.setProcessedEvent(builder(parentContext, me.getEvent()).build())).doOnSuccess(result -> {
if (result == null) {
childContext.success();
}
}));
}, // Force sequential execution of the chain for each element
1).switchIfEmpty(defer(() -> {
if (count.get() == 0) {
logger.warn("Split expression returned no results. If this is not expected please check your expression");
return just(request);
} else {
return empty();
}
})).takeLast(1).map(s -> CoreEvent.builder(currentEvent.get()).message(request.getMessage()).build()).errorStrategyStop();
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class AbstractExecutableComponent method execute.
@Override
public final CompletableFuture<Event> execute(Event event) {
CoreEvent internalEvent;
BaseEventContext child = createChildEventContext(event.getContext());
if (event instanceof CoreEvent) {
internalEvent = builder(child, (CoreEvent) event).build();
} else {
internalEvent = CoreEvent.builder(createEventContext(null)).message(event.getMessage()).error(event.getError().orElse(null)).variables(event.getVariables()).build();
}
return from(MessageProcessors.process(internalEvent, getExecutableFunction())).onErrorMap(throwable -> {
MessagingException messagingException = (MessagingException) throwable;
CoreEvent messagingExceptionEvent = messagingException.getEvent();
return new ComponentExecutionException(messagingExceptionEvent.getError().get().getCause(), messagingExceptionEvent);
}).map(r -> builder(event.getContext(), r).build()).cast(Event.class).toFuture();
}
Aggregations