Search in sources :

Example 1 with RouterCompletionCallback

use of org.mule.runtime.extension.api.runtime.process.RouterCompletionCallback in project mule by mulesoft.

the class HeisenbergRouters method concurrentRouteExecutor.

public void concurrentRouteExecutor(WhenRoute when, RouterCompletionCallback callback) {
    Consumer<Chain> processor = (chain) -> {
        final Latch latch = new Latch();
        chain.process((result -> latch.release()), (error, result) -> latch.release());
        try {
            latch.await(10000, MILLISECONDS);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    };
    Thread first = new Thread(() -> processor.accept(when.getChain()));
    Thread second = new Thread(() -> processor.accept(when.getChain()));
    first.start();
    second.start();
    try {
        first.join();
        second.join();
    } catch (Exception e) {
        callback.error(e);
    }
    callback.success(Result.builder().output("SUCCESS").build());
}
Also used : Summary(org.mule.runtime.extension.api.annotation.param.display.Summary) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) Attribute(org.mule.test.heisenberg.extension.model.Attribute) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) OtherwiseRoute(org.mule.test.heisenberg.extension.route.OtherwiseRoute) RouterCompletionCallback(org.mule.runtime.extension.api.runtime.process.RouterCompletionCallback) DrugKillingRoute(org.mule.test.heisenberg.extension.route.DrugKillingRoute) AfterCall(org.mule.test.heisenberg.extension.route.AfterCall) Collectors.toMap(java.util.stream.Collectors.toMap) MuleException(org.mule.runtime.api.exception.MuleException) BeforeCall(org.mule.test.heisenberg.extension.route.BeforeCall) Map(java.util.Map) Chain(org.mule.runtime.extension.api.runtime.route.Chain) VoidCompletionCallback(org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback) Optional(org.mule.runtime.extension.api.annotation.param.Optional) Parameter(org.mule.runtime.extension.api.annotation.param.Parameter) Disposable(org.mule.runtime.api.lifecycle.Disposable) Startable(org.mule.runtime.api.lifecycle.Startable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) Result(org.mule.runtime.extension.api.runtime.operation.Result) Consumer(java.util.function.Consumer) Latch(org.mule.runtime.api.util.concurrent.Latch) List(java.util.List) WhenRoute(org.mule.test.heisenberg.extension.route.WhenRoute) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) NullSafe(org.mule.runtime.extension.api.annotation.param.NullSafe) KillingRoute(org.mule.test.heisenberg.extension.route.KillingRoute) NOT_SUPPORTED(org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED) Expression(org.mule.runtime.extension.api.annotation.Expression) Chain(org.mule.runtime.extension.api.runtime.route.Chain) Latch(org.mule.runtime.api.util.concurrent.Latch) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleException(org.mule.runtime.api.exception.MuleException)

Aggregations

List (java.util.List)1 Map (java.util.Map)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1 Consumer (java.util.function.Consumer)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 MuleException (org.mule.runtime.api.exception.MuleException)1 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)1 Disposable (org.mule.runtime.api.lifecycle.Disposable)1 Initialisable (org.mule.runtime.api.lifecycle.Initialisable)1 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)1 Startable (org.mule.runtime.api.lifecycle.Startable)1 Stoppable (org.mule.runtime.api.lifecycle.Stoppable)1 NOT_SUPPORTED (org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED)1 Preconditions.checkArgument (org.mule.runtime.api.util.Preconditions.checkArgument)1 Latch (org.mule.runtime.api.util.concurrent.Latch)1 Expression (org.mule.runtime.extension.api.annotation.Expression)1 NullSafe (org.mule.runtime.extension.api.annotation.param.NullSafe)1 Optional (org.mule.runtime.extension.api.annotation.param.Optional)1 Parameter (org.mule.runtime.extension.api.annotation.param.Parameter)1 Summary (org.mule.runtime.extension.api.annotation.param.display.Summary)1