Package io.helidon.common.reactive.valve
Interface Valve<T>
-
- Type Parameters:
T
- a type of items produced byValve
API
- 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 aCompletionStage
which will be completed when thisValve
is completed and result is a collected value.default Valve<T>
executeOn(ExecutorService executorService)
Returns newValve
which defer all handlers to providedExecutorService
.default Valve<T>
filter(Predicate<T> predicate)
default <K> Valve<K>
flatMap(Function<T,Valve<K>> mapFunction)
Returns newValve
instance which combines all results into a single Valve.default void
handle(BiConsumer<T,Pausable> onData)
Register data handlers (callbacks).default void
handle(BiConsumer<T,Pausable> onData, Consumer<Throwable> onError)
Register data handlers (callbacks).void
handle(BiConsumer<T,Pausable> onData, Consumer<Throwable> onError, Runnable onComplete)
Register data handlers (callbacks).default void
handle(Consumer<T> onData)
Register data handlers (callbacks).default void
handle(Consumer<T> onData, Consumer<Throwable> onError)
Register data handlers (callbacks).default void
handle(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 thisValve
intoValveIterator
representation.default Flow.Publisher<T>
toPublisher()
Transforms thisValve
intoFlow.Publisher
representation.
-
-
-
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 andPausable
representing a faucet of thisValve
.onError
- a callback of errors ornull
onComplete
- a callback for completion event ornull
- Throws:
NullPointerException
- ifonData
parameter isnull
IllegalStateException
- 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 andPausable
representing a faucet of thisValve
.- Throws:
NullPointerException
- ifonData
parameter isnull
IllegalStateException
- 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 andPausable
representing a faucet of thisValve
.onError
- a callback of errors ornull
- Throws:
NullPointerException
- ifonData
parameter isnull
IllegalStateException
- 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 ornull
onComplete
- a callback for completion event ornull
- Throws:
NullPointerException
- ifonData
parameter isnull
IllegalStateException
- 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
- ifonData
parameter isnull
IllegalStateException
- 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
- ifonData
parameter isnull
IllegalStateException
- 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 aValve
consisting 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 newValve
instance which combines all results into a single Valve.If provided
mapFunction
returnsnull
then 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 aValve
consisting 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 aCompletionStage
which will be completed when thisValve
is completed and result is a collected value.Result completes exceptionally if this
Valve
completes exceptionally.- Type Parameters:
A
- the intermediate accumulation type of theCollector
R
- 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 thisValve
intoFlow.Publisher
representation. ResultingPublisher
accepts only singleFlow.Subscriber
.- Returns:
- a
Publisher
representation
-
executeOn
default Valve<T> executeOn(ExecutorService executorService)
Returns newValve
which defer all handlers to providedExecutorService
. Each data chunk will be still called sequentially.- Parameters:
executorService
- an executor service to use- Returns:
- a new
Valve
instance - Throws:
NullPointerException
- ifexecutorService
parameter isnull
.
-
toIterator
default ValveIterator<T> toIterator()
Transforms thisValve
intoValveIterator
representation. It transforms reactive approach to the blocking pollingIterator
API.- Returns:
- an iterator instance
- Throws:
IllegalStateException
- if this instance has already registered handlers
-
-