Java Code Examples for reactor.core.publisher.Mono#transformDeferred()

The following examples show how to use reactor.core.publisher.Mono#transformDeferred() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * handle the Spring web flux (Flux /Mono) return types AOP based into reactor circuit-breaker
 * See {@link io.github.resilience4j.reactor.circuitbreaker.operator.CircuitBreakerOperator} for
 * details.
 *
 * @param proceedingJoinPoint Spring AOP proceedingJoinPoint
 * @param circuitBreaker      the configured circuitBreaker
 * @param methodName          the method name
 * @return the result object
 * @throws Throwable exception in case of faulty flow
 */
@Override
public Object handle(ProceedingJoinPoint proceedingJoinPoint, CircuitBreaker circuitBreaker,
    String methodName) throws Throwable {
    Object returnValue = proceedingJoinPoint.proceed();
    if (Flux.class.isAssignableFrom(returnValue.getClass())) {
        Flux<?> fluxReturnValue = (Flux<?>) returnValue;
        return fluxReturnValue.transformDeferred(
            io.github.resilience4j.reactor.circuitbreaker.operator.CircuitBreakerOperator
                .of(circuitBreaker));
    } else if (Mono.class.isAssignableFrom(returnValue.getClass())) {
        Mono<?> monoReturnValue = (Mono<?>) returnValue;
        return monoReturnValue.transformDeferred(CircuitBreakerOperator.of(circuitBreaker));
    } else {
        logger.error("Unsupported type for Reactor circuit breaker {}",
            returnValue.getClass().getTypeName());
        throw new IllegalArgumentException(
            "Not Supported type for the circuit breaker in Reactor:" + returnValue.getClass()
                .getName());

    }
}
 
Example 2
/**
 * handle the Spring web flux (Flux /Mono) return types AOP based into reactor bulk head See
 * {@link Bulkhead} for details.
 *
 * @param proceedingJoinPoint Spring AOP proceedingJoinPoint
 * @param bulkhead            the configured bulkhead
 * @param methodName          the method name
 * @return the result object
 * @throws Throwable exception in case of faulty flow
 */
@Override
public Object handle(ProceedingJoinPoint proceedingJoinPoint, Bulkhead bulkhead,
    String methodName) throws Throwable {
    Object returnValue = proceedingJoinPoint.proceed();
    if (Flux.class.isAssignableFrom(returnValue.getClass())) {
        Flux<?> fluxReturnValue = (Flux<?>) returnValue;
        return fluxReturnValue.transformDeferred(BulkheadOperator.of(bulkhead));
    } else if (Mono.class.isAssignableFrom(returnValue.getClass())) {
        Mono<?> monoReturnValue = (Mono<?>) returnValue;
        return monoReturnValue.transformDeferred(BulkheadOperator.of(bulkhead));
    } else {
        logger.error("Unsupported type for Reactor BulkHead {}",
            returnValue.getClass().getTypeName());
        throw new IllegalArgumentException(
            "Not Supported type for the BulkHead in Reactor :" + returnValue.getClass()
                .getName());

    }
}
 
Example 3
/**
 * handle the Spring web flux (Flux /Mono) return types AOP based into reactor retry See {@link
 * io.github.resilience4j.retry.Retry} for details.
 *
 * @param proceedingJoinPoint Spring AOP proceedingJoinPoint
 * @param retry               the configured retry
 * @param methodName          the method name
 * @return the result object
 * @throws Throwable exception in case of faulty flow
 */
@Override
public Object handle(ProceedingJoinPoint proceedingJoinPoint,
    io.github.resilience4j.retry.Retry retry, String methodName) throws Throwable {
    Object returnValue = proceedingJoinPoint.proceed();
    if (Flux.class.isAssignableFrom(returnValue.getClass())) {
        Flux<?> fluxReturnValue = (Flux<?>) returnValue;
        return fluxReturnValue.transformDeferred(RetryOperator.of(retry));
    } else if (Mono.class.isAssignableFrom(returnValue.getClass())) {
        Mono<?> monoReturnValue = (Mono<?>) returnValue;
        return monoReturnValue.transformDeferred(RetryOperator.of(retry));
    } else {
        logger.error("Unsupported type for Reactor retry {}",
            returnValue.getClass().getTypeName());
        throw new IllegalArgumentException(
            "Not Supported type for the retry in Reactor :" + returnValue.getClass().getName());

    }
}
 
Example 4
/**
 * handle the Spring web flux (Flux /Mono) return types AOP based into reactor rate limiter See
 * {@link RateLimiter} for details.
 *
 * @param proceedingJoinPoint Spring AOP proceedingJoinPoint
 * @param rateLimiter         the configured rateLimiter
 * @param methodName          the method name
 * @return the result object
 * @throws Throwable exception in case of faulty flow
 */
@Override
public Object handle(ProceedingJoinPoint proceedingJoinPoint, RateLimiter rateLimiter,
    String methodName) throws Throwable {
    Object returnValue = proceedingJoinPoint.proceed();
    if (Flux.class.isAssignableFrom(returnValue.getClass())) {
        Flux<?> fluxReturnValue = (Flux<?>) returnValue;
        return fluxReturnValue.transformDeferred(RateLimiterOperator.of(rateLimiter));
    } else if (Mono.class.isAssignableFrom(returnValue.getClass())) {
        Mono<?> monoReturnValue = (Mono<?>) returnValue;
        return monoReturnValue.transformDeferred(RateLimiterOperator.of(rateLimiter));
    } else {
        logger.error("Unsupported type for Reactor rateLimiter {}",
            returnValue.getClass().getTypeName());
        throw new IllegalArgumentException(
            "Not Supported type for the rateLimiter in Reactor :" + returnValue.getClass()
                .getName());

    }
}
 
Example 5
/**
 * handle the Spring web flux (Flux /Mono) return types AOP based into reactor time limiter
 * See {@link TimeLimiter} for details.
 *
 * @param proceedingJoinPoint Spring AOP proceedingJoinPoint
 * @param timeLimiter         the configured rateLimiter
 * @param methodName          the method name
 * @return the result object
 * @throws Throwable exception in case of faulty flow
 */
@Override
public Object handle(ProceedingJoinPoint proceedingJoinPoint,
    TimeLimiter timeLimiter, String methodName) throws Throwable {
    Object returnValue = proceedingJoinPoint.proceed();
    if (Flux.class.isAssignableFrom(returnValue.getClass())) {
        Flux<?> fluxReturnValue = (Flux<?>) returnValue;
        return fluxReturnValue.transformDeferred(TimeLimiterOperator.of(timeLimiter));
    } else if (Mono.class.isAssignableFrom(returnValue.getClass())) {
        Mono<?> monoReturnValue = (Mono<?>) returnValue;
        return monoReturnValue.transformDeferred(TimeLimiterOperator.of(timeLimiter));
    } else {
        throw new IllegalReturnTypeException(returnValue.getClass(), methodName,
            "Reactor expects Mono/Flux.");
    }
}