Search in sources :

Example 1 with TestTransactionalConnection

use of org.mule.test.transactional.connection.TestTransactionalConnection in project mule by mulesoft.

the class TransactionalSource method onStart.

@Override
public void onStart(SourceCallback<TestTransactionalConnection, Object> sourceCallback) throws MuleException {
    connectExecutor = newFixedThreadPool(1);
    connectExecutor.execute(() -> {
        SourceCallbackContext ctx = sourceCallback.createContext();
        try {
            TestTransactionalConnection connection = connectionProvider.connect();
            boolean isXa = false;
            if (connection instanceof XATransactionalConnection) {
                isXa = true;
                xaResource = (DummyXaResource) ((XATransactionalConnection) connection).getXAResource();
            }
            ctx.addVariable(IS_XA, isXa);
            ctx.bindConnection(connection);
            sourceCallback.handle(Result.<TestTransactionalConnection, Object>builder().output(connection).build(), ctx);
        } catch (ConnectionException e) {
            sourceCallback.onConnectionException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : SourceCallbackContext(org.mule.runtime.extension.api.runtime.source.SourceCallbackContext) TestTransactionalConnection(org.mule.test.transactional.connection.TestTransactionalConnection) XATransactionalConnection(org.mule.runtime.extension.api.connectivity.XATransactionalConnection) ConnectionException(org.mule.runtime.api.connection.ConnectionException) ConnectionException(org.mule.runtime.api.connection.ConnectionException) TransactionException(org.mule.runtime.api.tx.TransactionException) MuleException(org.mule.runtime.api.exception.MuleException)

Aggregations

ConnectionException (org.mule.runtime.api.connection.ConnectionException)1 MuleException (org.mule.runtime.api.exception.MuleException)1 TransactionException (org.mule.runtime.api.tx.TransactionException)1 XATransactionalConnection (org.mule.runtime.extension.api.connectivity.XATransactionalConnection)1 SourceCallbackContext (org.mule.runtime.extension.api.runtime.source.SourceCallbackContext)1 TestTransactionalConnection (org.mule.test.transactional.connection.TestTransactionalConnection)1