Package io.smallrye.reactive.converters
Interface ReactiveTypeConverter<T>
-
- Type Parameters:
T- the converted type.
public interface ReactiveTypeConverter<T>Converts a specific reactive types from and toCompletionStageandPublisher. In addition to conversion operations, this class provides characteristics on the converted type:- whether or not the converted type
<T>may emit at most one item - whether or not the converted type
<T>may emit multiple items - whether or not the converted type
<T>may emitnullvalues - ...
Implementations must be tested against the TCK by extending the test case from the
io.smallrye.reactive.converters.tckpackages.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleanemitAtMostOneItem()booleanemitItems()<X> TfromCompletionStage(CompletionStage<X> cs)Transforms an instance ofCompletionStageto an instance ofT.<X> TfromFlowPublisher(Flow.Publisher<X> publisher)Transforms an instance ofTto aFlow.Publisher.<X> TfromPublisher(org.reactivestreams.Publisher<X> publisher)Transforms an instance ofTto aPublisher.default booleanrequireAtLeastOneItem()booleansupportNullValue()<X> CompletionStage<X>toCompletionStage(T instance)Transforms an instance ofTto aCompletionStagecompleted with a potential value.<X> Flow.Publisher<X>toFlowPublisher(T instance)Transforms an instance ofTto aFlow.Publisher.<X> org.reactivestreams.Publisher<X>toRSPublisher(T instance)Transforms an instance ofTto aPublisher.Class<T>type()
-
-
-
Method Detail
-
toCompletionStage
<X> CompletionStage<X> toCompletionStage(T instance)
Transforms an instance ofTto aCompletionStagecompleted with a potential value. Each converter instances can use specific rules, however the following set of rules are mandatory:- The returned
CompletionStagemust never benull. - The returned
CompletionStagecompletes with the first emitted value. This value may benullfor empty stream or instance ofTemittingnullas first value. - If the passed
instanceemits several values, only the first one is considered, others are discarded. - If the passed
instancefails before emitting a value, the returnedCompletionStagecompletes with this failure. - If the passed
instancedoes not emit any value and does not fail or complete, the returnedCompletionStagedoes not complete. - If the passed
instancecompletes before
emitting a value, theCompletionStageis completed with anullvalue. - If the passed
instanceemitsnullas first value (if supported), theCompletionStageis completed withnull. As a consequence, there are no differences between aninstanceemittingnullas first value or completing without emitting a value. If theinstancedoes not support emittingnullvalues, the returnedCompletionStagemust be completed with a failure.
- Type Parameters:
X- the type used to complete the returnedCompletionStage. It is generally the type of data emitted by the passedinstance.- Parameters:
instance- the instance to convert to aCompletionStage. Must not benull.- Returns:
- a
non-nullCompletionStage.
- The returned
-
toRSPublisher
<X> org.reactivestreams.Publisher<X> toRSPublisher(T instance)
Transforms an instance ofTto aPublisher. Each converter instances can use specific rules, however the following set of rules are mandatory:- The returned
Publishermust never benull. - All values emitted by the
instanceare emitted by the returnedPublisher. - If the
instanceemits a failure,Publisherpropagates the same failure and terminates. - If the
instancecompletes,Publisheralso completes. - If the passed
instancedoes not emit any value and does not fail or complete, the returnedPublisherdoes not send any signals or values. - If the passed
instancecompletes before
emitting a value, thePublisheralso completes empty. - If the passed
instanceemitsnull, thePublishermust send a failure (NullPointerException. - If the
instancesupport back-pressure, the resultingPublishermust enforce back-pressure. When theinstancedoes not support back-pressure, thePublisherconsumes the data without back-pressure using an unbounded-buffer. In other words, this operation is a pass-through for back-pressure and its behavior is determined by the back-pressure behavior of the passedinstance.
- Type Parameters:
X- the type emitted by the returnedPublisher. It is generally the type of data emitted by the passedinstance.- Parameters:
instance- the instance to convert to aPublisher. Must not benull.- Returns:
- a
non-nullPublisher.
- The returned
-
toFlowPublisher
<X> Flow.Publisher<X> toFlowPublisher(T instance)
Transforms an instance ofTto aFlow.Publisher. Each converter instances can use specific rules, however the following set of rules are mandatory:- The returned
Flow.Publishermust never benull. - All values emitted by the
instanceare emitted by the returnedFlow.Publisher. - If the
instanceemits a failure,Flow.Publisherpropagates the same failure and terminates. - If the
instancecompletes,Flow.Publisheralso completes. - If the passed
instancedoes not emit any value and does not fail or complete, the returnedPublisherdoes not send any signals or values. - If the passed
instancecompletes before
emitting a value, theFlow.Publisheralso completes empty. - If the passed
instanceemitsnull, theFlow.Publishermust send a failure (NullPointerException. - If the
instancesupport back-pressure, the resultingFlow.Publishermust enforce back-pressure. When theinstancedoes not support back-pressure, theFlow.Publisherconsumes the data without back-pressure using an unbounded-buffer. In other words, this operation is a pass-through for back-pressure and its behavior is determined by the back-pressure behavior of the passedinstance.
- Type Parameters:
X- the type emitted by the returnedFlow.Publisher. It is generally the type of data emitted by the passedinstance.- Parameters:
instance- the instance to convert to aFlow.Publisher. Must not benull.- Returns:
- a
non-nullFlow.Publisher.
- The returned
-
fromCompletionStage
<X> T fromCompletionStage(CompletionStage<X> cs)
Transforms an instance ofCompletionStageto an instance ofT. The value emitted byTdepends on the completion of the passedCompletionStage. Each converter instances can use specific rules, however the following set of rules are mandatory:- The returned
Tmust never benull. - If the passed
CompletionStagenever completes, no values are emitted by the returnedT. - If the passed
CompletionStageredeems anullvalue, and ifTsupportnullvalues,nullis emitted by the returned instance ofT. - If the passed
CompletionStageredeems anullvalue, and ifTdoes not supportnullvalues, a failure is emitted by the returned instance ofT. - If the passed
CompletionStageredeems anon-nullvalue, the value is emitted by the returned instance ofT. - If the passed
CompletionStageis completed with a failure, the same failure is emitted by the returned instance ofT. - If the passed
CompletionStageis cancelled before having completed, theCancellationExceptionmust be emitted by the returned instance.
Implementations must not expect the
CompletionStageto be instances ofCompletableFuture.Implementations may decide to adapt the emitted result when receiving container object such as
Optional.- Type Parameters:
X- the type of result provided by theCompletionStage- Parameters:
cs- the instance ofCompletionStage, must not benull- Returns:
- the instance of T, generally emitting instances of
X.
- The returned
-
fromPublisher
<X> T fromPublisher(org.reactivestreams.Publisher<X> publisher)
Transforms an instance ofTto aPublisher. Each converter instances can use specific rules, however the following set of rules are mandatory:- The returned
Publishermust never benull. - If the instance of
Temits a single value, the returnedPublisheremits the same value and completes. - If the instance of
Tdoes not emits value, sends the completion signal, the returnedPublishercompletes. - If the instance of
Temits a failure, the returnedPublisheremits a failure. - If the instance of
Temits anullvalue, the returnedPublisheremits anNullPointerExceptionasnullis not a valid value. - If the instance of
Tdoes neither emits a value nor a signal, the returnedPublisherdoes not emits values or signals. - This operation is a pass-through for back-pressure and its behavior is determined by the back-pressure behavior of the returned instance.
- Type Parameters:
X- the type of data emitted by the passedPublisher.- Parameters:
publisher- thePublisherto convert. Must not benull.- Returns:
- a
non-nullinstance ofT.
- The returned
-
fromFlowPublisher
<X> T fromFlowPublisher(Flow.Publisher<X> publisher)
Transforms an instance ofTto aFlow.Publisher. Each converter instances can use specific rules, however the following set of rules are mandatory:- The returned
Flow.Publishermust never benull. - If the instance of
Temits a single value, the returnedFlow.Publisheremits the same value and completes. - If the instance of
Tdoes not emits value, sends the completion signal, the returnedFlow.Publishercompletes. - If the instance of
Temits a failure, the returnedFlow.Publisheremits a failure. - If the instance of
Temits anullvalue, the returnedFlow.Publisheremits anNullPointerExceptionasnullis not a valid value. - If the instance of
Tdoes neither emits a value nor a signal, the returnedPublisherdoes not emits values or signals. - This operation is a pass-through for back-pressure and its behavior is determined by the back-pressure behavior of the returned instance.
- Type Parameters:
X- the type of data emitted by the passedFlow.Publisher.- Parameters:
publisher- theFlow.Publisherto convert. Must not benull.- Returns:
- a
non-nullinstance ofT.
- The returned
-
type
Class<T> type()
- Returns:
- the conversion type. Must not be
null. Notice that sub-classes of the returned class are also managed by the same converter.
-
emitItems
boolean emitItems()
- Returns:
trueif the typeTmay emit items,falseotherwise.
-
emitAtMostOneItem
boolean emitAtMostOneItem()
- Returns:
trueif the typeTmay emit items at most one item,falseotherwise. Returningfalseto this method means that the converted type only signals about completion or error. Returningtruemeans thatemitItems()must also returntrue.
-
supportNullValue
boolean supportNullValue()
- Returns:
trueif the typeTcan emit or receivenullas item.
-
requireAtLeastOneItem
default boolean requireAtLeastOneItem()
- Returns:
trueif the typeTrequire at least one item. Converting from a type not emitting a value item would fail.
-
-