Interface ReactiveStreamsAdapter
- All Known Implementing Classes:
ReactiveStreamsPublisherAdapter,ReactorReactiveAdapter,RxJavaReactiveAdapter
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 TypeMethodDescriptionConverts the supplied reactive value to a JDK-nativeAdaptation.booleanReturns whether this adapter recognizes the supplied return value.
-
Method Details
-
canAdapt
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@RestOphandler return value. Nevernull.- Returns:
trueifadapt(Object)can convert this value.
-
adapt
Converts the supplied reactive value to a JDK-nativeAdaptation.Only called when
canAdapt(Object)returnedtruefor the same value.- Parameters:
value- The reactive value to adapt. Nevernull.- Returns:
- The adapted single-value or streaming shape. Never
null.
-