use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class CursorManager method manage.
/**
* Becomes aware of the given {@code provider} and returns a replacement provider which is managed by the runtime, allowing for
* automatic resource handling
*
* @param provider the provider to be tracked
* @param creatorEvent the event that created the provider
* @return a {@link CursorContext}
*/
public CursorProvider manage(CursorProvider provider, CoreEvent creatorEvent) {
final BaseEventContext ownerContext = ((BaseEventContext) creatorEvent.getContext()).getRootContext();
registerEventContext(ownerContext);
registry.getUnchecked(ownerContext.getId()).addProvider(provider);
final CursorContext context = new CursorContext(provider, ownerContext);
if (provider instanceof CursorStreamProvider) {
return new ManagedCursorStreamProvider(context, this);
} else if (provider instanceof CursorIteratorProvider) {
return new ManagedCursorIteratorProvider(context, this);
}
throw new MuleRuntimeException(createStaticMessage("Unknown cursor provider type: " + context.getClass().getName()));
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class IdempotentRedeliveryPolicy method process.
@Override
public CoreEvent process(CoreEvent event) throws MuleException {
Optional<Exception> exceptionSeen = empty();
String messageId = null;
try {
messageId = getIdForEvent(event);
} catch (ExpressionRuntimeException e) {
logger.warn("The message cannot be processed because the digest could not be generated. Either make the payload serializable or use an expression.");
return null;
} catch (Exception ex) {
exceptionSeen = of(ex);
}
Lock lock = lockFactory.createLock(idrId + "-" + messageId);
lock.lock();
try {
RedeliveryCounter counter = findCounter(messageId);
if (exceptionSeen.isPresent()) {
throw new MessageRedeliveredException(messageId, counter.counter.get(), maxRedeliveryCount, exceptionSeen.get());
} else if (counter != null && counter.counter.get() > maxRedeliveryCount) {
throw new MessageRedeliveredException(messageId, counter.errors, counter.counter.get(), maxRedeliveryCount);
}
try {
CoreEvent returnEvent = processNext(CoreEvent.builder(DefaultEventContext.child((BaseEventContext) event.getContext(), empty()), event).build());
counter = findCounter(messageId);
if (counter != null) {
resetCounter(messageId);
}
return returnEvent;
} catch (Exception ex) {
if (ex instanceof MessagingException) {
incrementCounter(messageId, (MessagingException) ex);
throw ex;
} else {
MessagingException me = createMessagingException(event, ex, this);
incrementCounter(messageId, me);
throw ex;
}
}
} finally {
lock.unlock();
}
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class TopLevelParameterObjectFactory method doGetObject.
@Override
public Object doGetObject() throws Exception {
return withContextClassLoader(classLoader, () -> {
// TODO MULE-10919 - This logic is similar to that of the resolverset object builder and should
// be generalized
DefaultObjectBuilder builder = this.builder.get();
resolveParameters(objectType, builder);
resolveParameterGroups(objectType, builder);
injectFields();
ValueResolver<Object> resolver = new ObjectBuilderValueResolver<>(builder, muleContext);
if (resolver.isDynamic()) {
return resolver;
}
CoreEvent initialiserEvent = null;
try {
initialiserEvent = getInitialiserEvent(muleContext);
staticProduct = resolver.resolve(from(initialiserEvent));
muleContext.getInjector().inject(staticProduct);
return staticProduct;
} finally {
if (initialiserEvent != null) {
((BaseEventContext) initialiserEvent.getContext()).success();
}
}
}, Exception.class, exception -> {
throw exception;
});
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class DefaultEventContextTestCase method componentData.
@Test
@Description("Verify that a location produces connector and source data.")
public void componentData() throws Exception {
TypedComponentIdentifier typedComponentIdentifier = TypedComponentIdentifier.builder().type(SOURCE).identifier(buildFromStringRepresentation("http:listener")).build();
ComponentLocation location = mock(ComponentLocation.class);
when(location.getComponentIdentifier()).thenReturn(typedComponentIdentifier);
when(location.getParts()).thenReturn(asList(new DefaultLocationPart("flow", empty(), empty(), empty())));
BaseEventContext context = contextWithComponentLocation.apply(location);
assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getNamespace(), is("http"));
assertThat(context.getOriginatingLocation().getComponentIdentifier().getIdentifier().getName(), is("listener"));
}
use of org.mule.runtime.core.privileged.event.BaseEventContext in project mule by mulesoft.
the class DefaultEventContextTestCase method multipleBranches.
@Test
@Description("Parent EventContext only completes once response publisher completes with a value and all child contexts are complete, even if one branch of the tree completes.")
public void multipleBranches() throws Exception {
BaseEventContext parent = context.get();
BaseEventContext child1 = child(parent, empty());
BaseEventContext child2 = child(parent, empty());
BaseEventContext grandchild1 = child(child1, empty());
BaseEventContext grandchild2 = child(child1, empty());
BaseEventContext grandchild3 = child(child2, empty());
BaseEventContext grandchild4 = child(child2, empty());
grandchild1.success();
grandchild2.success();
assertThat(grandchild1.isTerminated(), is(true));
assertThat(grandchild2.isTerminated(), is(true));
assertThat(child1.isTerminated(), is(false));
assertThat(parent.isTerminated(), is(false));
child1.success();
assertThat(child1.isTerminated(), is(true));
assertThat(parent.isTerminated(), is(false));
grandchild3.success();
grandchild4.success();
child2.success();
assertThat(grandchild3.isTerminated(), is(true));
assertThat(grandchild4.isTerminated(), is(true));
assertThat(child2.isTerminated(), is(true));
assertThat(parent.isTerminated(), is(false));
parent.success();
assertThat(parent.isTerminated(), is(true));
}
Aggregations