Search in sources :

Example 1 with SmallRyeThreadContext

use of io.smallrye.context.SmallRyeThreadContext in project smallrye-mutiny by smallrye.

the class BaseContextPropagationInterceptor method decorate.

@Override
public <T> BinaryOperator<T> decorate(BinaryOperator<T> operator) {
    SmallRyeThreadContext context = getThreadContext();
    if (context.isContextualized(operator) || context.isEmpty()) {
        return operator;
    }
    BiFunction<T, T, T> function = context.contextualFunction(operator);
    return new ContextualizedBinaryOperator<>(function);
}
Also used : SmallRyeThreadContext(io.smallrye.context.SmallRyeThreadContext)

Example 2 with SmallRyeThreadContext

use of io.smallrye.context.SmallRyeThreadContext in project smallrye-mutiny by smallrye.

the class BaseContextPropagationInterceptor method decorate.

@Override
public BooleanSupplier decorate(BooleanSupplier supplier) {
    SmallRyeThreadContext context = getThreadContext();
    if (context.isContextualized(supplier) || context.isEmpty()) {
        return supplier;
    }
    Supplier<Boolean> contextualized = context.contextualSupplier(supplier::getAsBoolean);
    return new ContextualizedBooleanSupplier(contextualized);
}
Also used : SmallRyeThreadContext(io.smallrye.context.SmallRyeThreadContext)

Example 3 with SmallRyeThreadContext

use of io.smallrye.context.SmallRyeThreadContext in project smallrye-mutiny by smallrye.

the class BaseContextPropagationInterceptor method decorate.

@SuppressWarnings("unchecked")
@Override
public <I1, I2, I3, I4, I5, I6, I7, O> Functions.Function7<I1, I2, I3, I4, I5, I6, I7, O> decorate(Functions.Function7<I1, I2, I3, I4, I5, I6, I7, O> function) {
    SmallRyeThreadContext context = getThreadContext();
    if (context.isContextualized(function) || context.isEmpty()) {
        return function;
    }
    Function<Object[], O> fun = context.contextualFunction(args -> function.apply((I1) args[0], (I2) args[1], (I3) args[2], (I4) args[3], (I5) args[4], (I6) args[5], (I7) args[6]));
    return new ContextualizedFunction7<>(fun);
}
Also used : SmallRyeThreadContext(io.smallrye.context.SmallRyeThreadContext)

Example 4 with SmallRyeThreadContext

use of io.smallrye.context.SmallRyeThreadContext in project smallrye-mutiny by smallrye.

the class BaseContextPropagationInterceptor method decorate.

@Override
public LongConsumer decorate(LongConsumer consumer) {
    SmallRyeThreadContext context = getThreadContext();
    if (context.isContextualized(consumer) || context.isEmpty()) {
        return consumer;
    }
    Consumer<Long> cons = context.contextualConsumer(consumer::accept);
    return new ContextualizedLongConsumer(cons);
}
Also used : SmallRyeThreadContext(io.smallrye.context.SmallRyeThreadContext)

Example 5 with SmallRyeThreadContext

use of io.smallrye.context.SmallRyeThreadContext in project smallrye-mutiny by smallrye.

the class BaseContextPropagationInterceptor method decorate.

@SuppressWarnings("unchecked")
@Override
public <I1, I2, I3, O> Functions.Function3<I1, I2, I3, O> decorate(Functions.Function3<I1, I2, I3, O> function) {
    SmallRyeThreadContext context = getThreadContext();
    if (context.isContextualized(function) || context.isEmpty()) {
        return function;
    }
    Function<Object[], O> fun = context.contextualFunction(args -> function.apply((I1) args[0], (I2) args[1], (I3) args[2]));
    return new ContextualizedFunction3<>(fun);
}
Also used : SmallRyeThreadContext(io.smallrye.context.SmallRyeThreadContext)

Aggregations

SmallRyeThreadContext (io.smallrye.context.SmallRyeThreadContext)13 CleanAutoCloseable (io.smallrye.context.CleanAutoCloseable)2 Uni (io.smallrye.mutiny.Uni)2 Infrastructure (io.smallrye.mutiny.infrastructure.Infrastructure)2 Duration (java.time.Duration)2 java.util.concurrent (java.util.concurrent)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ThreadContext (org.eclipse.microprofile.context.ThreadContext)2 org.junit.jupiter.api (org.junit.jupiter.api)2 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)2 Multi (io.smallrye.mutiny.Multi)1 AssertSubscriber (io.smallrye.mutiny.helpers.test.AssertSubscriber)1 Cancellable (io.smallrye.mutiny.subscription.Cancellable)1 UniEmitter (io.smallrye.mutiny.subscription.UniEmitter)1 ChronoUnit (java.time.temporal.ChronoUnit)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Consumer (java.util.function.Consumer)1 Awaitility.await (org.awaitility.Awaitility.await)1