Search in sources :

Example 1 with ExecutionContextAdapter

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());
    });
}
Also used : LazyValue(org.mule.runtime.api.util.LazyValue) BackPressureAction(org.mule.runtime.extension.api.runtime.source.BackPressureAction) ImmutableBackPressureContext(org.mule.runtime.module.extension.internal.runtime.source.ImmutableBackPressureContext) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter)

Example 2 with ExecutionContextAdapter

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);
    }
}
Also used : HashMap(java.util.HashMap) Cursor(org.mule.runtime.api.streaming.Cursor) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter)

Example 3 with ExecutionContextAdapter

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);
            }
        };
    });
}
Also used : LazyValue(org.mule.runtime.api.util.LazyValue) CompletionCallback(org.mule.runtime.extension.api.runtime.process.CompletionCallback) VoidCompletionCallback(org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) VoidCompletionCallback(org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter)

Example 4 with ExecutionContextAdapter

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)));
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with ExecutionContextAdapter

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);
        }
    });
}
Also used : LazyValue(org.mule.runtime.api.util.LazyValue) ConnectionHandler(org.mule.runtime.api.connection.ConnectionHandler) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ExecutionContextAdapter(org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter) ConnectionException(org.mule.runtime.api.connection.ConnectionException)

Aggregations

ExecutionContextAdapter (org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter)6 LazyValue (org.mule.runtime.api.util.LazyValue)3 Test (org.junit.Test)2 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)2 HashMap (java.util.HashMap)1 TransactionManager (javax.transaction.TransactionManager)1 ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 ConnectionHandler (org.mule.runtime.api.connection.ConnectionHandler)1 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 Cursor (org.mule.runtime.api.streaming.Cursor)1 TransactionConfig (org.mule.runtime.core.api.transaction.TransactionConfig)1 XaTransaction (org.mule.runtime.core.privileged.transaction.XaTransaction)1 XATransactionalConnection (org.mule.runtime.extension.api.connectivity.XATransactionalConnection)1 ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)1 CompletionCallback (org.mule.runtime.extension.api.runtime.process.CompletionCallback)1 VoidCompletionCallback (org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback)1 BackPressureAction (org.mule.runtime.extension.api.runtime.source.BackPressureAction)1 ImmutableBackPressureContext (org.mule.runtime.module.extension.internal.runtime.source.ImmutableBackPressureContext)1 XAExtensionTransactionalResource (org.mule.runtime.module.extension.internal.runtime.transaction.XAExtensionTransactionalResource)1