Class Adaptation

java.lang.Object
org.apache.juneau.rest.server.reactive.Adaptation

public final class Adaptation extends Object
The result of a ReactiveStreamsAdapter.adapt(...) call: either a single-value CompletionStage or a multi-value Flow.Publisher.

Exactly one of the two shapes is present. Single-value adaptations (e.g. Reactor Mono, RxJava Single / Maybe) collapse onto the existing CompletableFuture async response path. Streaming adaptations (e.g. Reactor Flux, RxJava Flowable / Observable, a Reactive-Streams Publisher) are subscribed to and rendered as a buffered list, an SSE stream, or an NDJSON stream depending on the negotiated response media type.

Since:
10.0.0
See Also:
  • Method Details

    • single

      public static Adaptation single(CompletionStage<?> value)
      Creates a single-value adaptation backed by a CompletionStage.
      Parameters:
      value - The completion stage. Must not be null.
      Returns:
      A new adaptation.
    • stream

      public static Adaptation stream(Flow.Publisher<?> value)
      Creates a streaming adaptation backed by a Flow.Publisher.
      Parameters:
      value - The publisher. Must not be null.
      Returns:
      A new adaptation.
    • isStream

      public boolean isStream()
      Returns whether this adaptation is a multi-value stream (vs. a single value).
      Returns:
      true if this is a Flow.Publisher adaptation.
    • single

      public CompletionStage<?> single()
      Returns the single-value completion stage, or null if this is a streaming adaptation.
      Returns:
      The completion stage, or null.
    • stream

      public Flow.Publisher<?> stream()
      Returns the streaming publisher, or null if this is a single-value adaptation.
      Returns:
      The publisher, or null.