Class Reactor

java.lang.Object
com.couchbase.client.core.Reactor

public class Reactor extends Object
This class provides utility methods when working with reactor.
Since:
2.0.0
  • Field Details

    • DEFAULT_EMIT_BUSY_DURATION

      public static final Duration DEFAULT_EMIT_BUSY_DURATION
  • Method Details

    • wrap

      public static <T> Mono<T> wrap(Request<?> request, CompletableFuture<T> response, boolean propagateCancellation)
      Wraps a Request and returns it in a Mono.
      Parameters:
      request - the request to wrap.
      response - the full response to wrap, might not be the same as in the request.
      propagateCancellation - if a cancelled/unsubscribed mono should also cancel the request.
      Returns:
      the mono that wraps the request.
    • wrap

      @Internal public static <T> Mono<T> wrap(CompletableFuture<T> response, Runnable cancellationTask)
      Converts the given future into a mono. Runs the given cancellation task when the mono is cancelled.
    • toMono

      public static <T> Mono<T> toMono(Supplier<CompletableFuture<T>> input)
      Helper method to wrap an async call into a reactive one and translate exceptions appropriately.
      Parameters:
      input - a supplier that will be called on every subscription.
      Returns:
      a mono that invokes the given supplier on each subscription.
    • toFlux

      public static <T, C extends Iterable<T>> Flux<T> toFlux(Supplier<CompletableFuture<C>> input)
      Helper method to wrap an async call into a reactive one and translate exceptions appropriately.
      Parameters:
      input - a supplier that will be called on every subscription.
      Returns:
      a flux that invokes the given supplier on each subscription.
    • emitFailureHandler

      public static Sinks.EmitFailureHandler emitFailureHandler()
      Constructs a new EmitFailureHandler with the default busy wait duration.
      Returns:
      a new emit failure handler, busy looping for DEFAULT_EMIT_BUSY_DURATION.
    • emitFailureHandler

      public static Sinks.EmitFailureHandler emitFailureHandler(Duration duration)
      Constructs a new EmitFailureHandler with a custom busy wait duration.
      Parameters:
      duration - the duration to busy loop until failure.
      Returns:
      a new emit failure handler, busy looping for the given duration.
    • shieldFromCancellation

      public static <T> Flux<T> shieldFromCancellation(Flux<T> flux)
      Returns a new Flux that wraps the given Flux and receives events from it. If the returned Flux is cancelled, the cancellation is not propagated to the inner Flux.

      Useful for cooperative cancellation schemes, where an external flag (typically an AtomicBoolean) is set whenever the inner Flux should stop emitting events. The external flag is typically set by a Flux.doOnCancel(java.lang.Runnable) callback on the returned Flux.

      This allows the inner Flux to do non-trivial cleanup work before it terminates.