Package io.helidon.common.reactive.valve
Interface Valve<T>
-
- Type Parameters:
T- a type of items produced byValveAPI
- All Superinterfaces:
Pausable
- All Known Implementing Classes:
InputStreamValve,Tank
public interface Valve<T> extends Pausable
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <A,R>
CompletionStage<R>collect(Collector<? super T,A,R> collector)Returns aCompletionStagewhich will be completed when thisValveis completed and result is a collected value.default Valve<T>executeOn(ExecutorService executorService)Returns newValvewhich defer all handlers to providedExecutorService.default Valve<T>filter(Predicate<T> predicate)default <K> Valve<K>flatMap(Function<T,Valve<K>> mapFunction)Returns newValveinstance which combines all results into a single Valve.default voidhandle(BiConsumer<T,Pausable> onData)Register data handlers (callbacks).default voidhandle(BiConsumer<T,Pausable> onData, Consumer<Throwable> onError)Register data handlers (callbacks).voidhandle(BiConsumer<T,Pausable> onData, Consumer<Throwable> onError, Runnable onComplete)Register data handlers (callbacks).default voidhandle(Consumer<T> onData)Register data handlers (callbacks).default voidhandle(Consumer<T> onData, Consumer<Throwable> onError)Register data handlers (callbacks).default voidhandle(Consumer<T> onData, Consumer<Throwable> onError, Runnable onComplete)Register data handlers (callbacks).default <K> Valve<K>map(Function<T,K> mapper)default Valve<T>peek(Consumer<T> action)default ValveIterator<T>toIterator()Transforms thisValveintoValveIteratorrepresentation.default Flow.Publisher<T>toPublisher()Transforms thisValveintoFlow.Publisherrepresentation.
-
-
-
Method Detail
-
handle
void handle(BiConsumer<T,Pausable> onData, Consumer<Throwable> onError, Runnable onComplete)
Register data handlers (callbacks).- Parameters:
onData- a callback for data chunks andPausablerepresenting a faucet of thisValve.onError- a callback of errors ornullonComplete- a callback for completion event ornull- Throws:
NullPointerException- ifonDataparameter isnullIllegalStateException- if cannot register new callback. For example if instance accepts only a single handler.
-
handle
default void handle(BiConsumer<T,Pausable> onData)
Register data handlers (callbacks).- Parameters:
onData- a callback for data chunks andPausablerepresenting a faucet of thisValve.- Throws:
NullPointerException- ifonDataparameter isnullIllegalStateException- if cannot register new callback. For example if instance accepts only a single handler.
-
handle
default void handle(BiConsumer<T,Pausable> onData, Consumer<Throwable> onError)
Register data handlers (callbacks).- Parameters:
onData- a callback for data chunks andPausablerepresenting a faucet of thisValve.onError- a callback of errors ornull- Throws:
NullPointerException- ifonDataparameter isnullIllegalStateException- if cannot register new callback. For example if instance accepts only a single handler.
-
handle
default void handle(Consumer<T> onData, Consumer<Throwable> onError, Runnable onComplete)
Register data handlers (callbacks).- Parameters:
onData- a callback for data chunks.onError- a callback of errors ornullonComplete- a callback for completion event ornull- Throws:
NullPointerException- ifonDataparameter isnullIllegalStateException- if cannot register new callback. For example if instance accepts only a single handler.
-
handle
default void handle(Consumer<T> onData)
Register data handlers (callbacks).- Parameters:
onData- a callback for data chunks.- Throws:
NullPointerException- ifonDataparameter isnullIllegalStateException- if cannot register new callback. For example if instance accepts only a single handler.
-
handle
default void handle(Consumer<T> onData, Consumer<Throwable> onError)
Register data handlers (callbacks).- Parameters:
onData- a callback for data chunks.onError- a callback of errors ornull- Throws:
NullPointerException- ifonDataparameter isnullIllegalStateException- if cannot register new callback. For example if instance accepts only a single handler.
-
map
default <K> Valve<K> map(Function<T,K> mapper)
Returns aValveconsisting of the results of applying the given function to the elements of thisValve.- Type Parameters:
K- the element type of the newValve- Parameters:
mapper- a stateless function to apply to each element- Returns:
- the new
Valve
-
flatMap
default <K> Valve<K> flatMap(Function<T,Valve<K>> mapFunction)
Returns newValveinstance which combines all results into a single Valve.If provided
mapFunctionreturnsnullthen this result is skipped.
-
filter
default Valve<T> filter(Predicate<T> predicate)
- Parameters:
predicate- a stateless predicate to apply to each element to determine if it should be included- Returns:
- the new
Valve
-
peek
default Valve<T> peek(Consumer<T> action)
Returns aValveconsisting of the elements of thisValve, additionally performing the provided action on each element as elements are consumed from the resultingValve.- Parameters:
action- an action to perform on the elements as they are consumed from theValve- Returns:
- the new
Valve
-
collect
default <A,R> CompletionStage<R> collect(Collector<? super T,A,R> collector)
Returns aCompletionStagewhich will be completed when thisValveis completed and result is a collected value.Result completes exceptionally if this
Valvecompletes exceptionally.- Type Parameters:
A- the intermediate accumulation type of theCollectorR- the type of the result- Parameters:
collector- a collector to use- Returns:
- a completion stage of collected result
-
toPublisher
default Flow.Publisher<T> toPublisher()
Transforms thisValveintoFlow.Publisherrepresentation. ResultingPublisheraccepts only singleFlow.Subscriber.- Returns:
- a
Publisherrepresentation
-
executeOn
default Valve<T> executeOn(ExecutorService executorService)
Returns newValvewhich defer all handlers to providedExecutorService. Each data chunk will be still called sequentially.- Parameters:
executorService- an executor service to use- Returns:
- a new
Valveinstance - Throws:
NullPointerException- ifexecutorServiceparameter isnull.
-
toIterator
default ValveIterator<T> toIterator()
Transforms thisValveintoValveIteratorrepresentation. It transforms reactive approach to the blocking pollingIteratorAPI.- Returns:
- an iterator instance
- Throws:
IllegalStateException- if this instance has already registered handlers
-
-