Interface ReactiveStreamsAdapter

All Known Implementing Classes:
ReactiveStreamsPublisherAdapter, ReactorReactiveAdapter, RxJavaReactiveAdapter

public interface ReactiveStreamsAdapter
SPI that bridges a third-party reactive return type to one of the two JDK-native shapes that the ReactiveResponseProcessor understands: a CompletionStage (single value) or a Flow.Publisher (a stream of values).
Why this exists

The opt-in juneau-rest-server-reactive module handles Flow.Publisher (and, via the existing AsyncResponseProcessor, CompletionStage) using only JDK APIs — no external dependency. Libraries such as Project Reactor (Mono / Flux), RxJava 3 (Single / Maybe / Flowable / Observable), and the Reactive-Streams org.reactivestreams.Publisher are NOT on the core classpath. The opt-in juneau-rest-server-reactive-reactor module ships ReactiveStreamsAdapter implementations that convert those types into the JDK-native shapes, so the streaming / buffering / SSE / NDJSON plumbing is implemented exactly once in the core.

Registration

Adapters are discovered via the JDK ServiceLoader mechanism. A bridge module (or a consumer who wants a custom adapter) ships a META-INF/services/ReactiveStreamsAdapter file listing the implementation class names. The ReactiveResponseProcessor loads the providers once (lazily, at first use) and skips any provider whose backing library is absent from the runtime classpath (a NoClassDefFoundError / ServiceConfigurationError on instantiation is swallowed). This means a single juneau-rest-server-reactive-reactor jar can declare Reactor, RxJava, and Reactive-Streams adapters while the consumer pulls only the provided-scope libraries they actually want.

Since:
10.0.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    adapt(Object value)
    Converts the supplied reactive value to a JDK-native Adaptation.
    boolean
    Returns whether this adapter recognizes the supplied return value.
  • Method Details

    • canAdapt

      boolean canAdapt(Object value)
      Returns whether this adapter recognizes the supplied return value.

      Implementations must return false (rather than throw) for values they do not handle, and must be cheap to call — this is invoked on the response hot path for every non-null handler return value once at least one adapter is registered.

      Parameters:
      value - The @RestOp handler return value. Never null.
      Returns:
      true if adapt(Object) can convert this value.
    • adapt

      Converts the supplied reactive value to a JDK-native Adaptation.

      Only called when canAdapt(Object) returned true for the same value.

      Parameters:
      value - The reactive value to adapt. Never null.
      Returns:
      The adapted single-value or streaming shape. Never null.