use of org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter 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());
});
}
use of org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter in project mule by mulesoft.
the class CursorResetInterceptor method before.
@Override
public void before(ExecutionContext<OperationModel> ctx) throws Exception {
Map<Cursor, Long> cursorPositions = new HashMap<>();
ctx.getParameters().forEach((key, value) -> {
if (value instanceof Cursor) {
final Cursor cursor = (Cursor) value;
cursorPositions.put(cursor, cursor.getPosition());
}
});
if (!cursorPositions.isEmpty()) {
((ExecutionContextAdapter<OperationModel>) ctx).setVariable(CURSOR_POSITIONS, cursorPositions);
}
}
use of org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter 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);
}
};
});
}
use of org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter in project mule by mulesoft.
the class VoidReturnDelegateTestCase method returnsMuleEvent.
@Test
public void returnsMuleEvent() throws MuleException {
CoreEvent event = newEvent();
ExecutionContextAdapter operationContext = mock(ExecutionContextAdapter.class);
when(operationContext.getEvent()).thenReturn(event);
Object returnValue = VoidReturnDelegate.INSTANCE.asReturnValue(new Object(), operationContext);
assertThat(event, is(sameInstance(returnValue)));
}
use of org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter in project mule by mulesoft.
the class ConnectionArgumentResolver method resolve.
/**
* Returns the connection previously set on the {@code executionContext} under the key
* {@link ExtensionProperties#CONNECTION_PARAM}
*
* @param executionContext an {@link ExecutionContext}
* @return the connection
* @throws IllegalArgumentException if the connection was not set
* @throws ClassCastException if {@code executionContext} is not an {@link ExecutionContextAdapter}
*/
@Override
public LazyValue<Object> resolve(ExecutionContext executionContext) {
return new LazyValue<>(() -> {
ConnectionHandler connectionHandler = ((ExecutionContextAdapter<ComponentModel>) executionContext).getVariable(CONNECTION_PARAM);
checkArgument(connectionHandler != null, "No connection was provided for the component [" + executionContext.getComponentModel().getName() + "]");
try {
return connectionHandler.getConnection();
} catch (ConnectionException e) {
throw new MuleRuntimeException(I18nMessageFactory.createStaticMessage(String.format("Error was found trying to obtain a connection to execute %s '%s' of extension '%s'", getComponentModelTypeName(executionContext.getComponentModel()), executionContext.getComponentModel().getName(), executionContext.getExtensionModel().getName())), e);
}
});
}
Aggregations