Interface Valve<T>

  • Type Parameters:
    T - a type of items produced by Valve API
    All Superinterfaces:
    Pausable
    All Known Implementing Classes:
    InputStreamValve, Tank

    public interface Valve<T>
    extends Pausable
    Represents a reactive source of data which can be paused and resumed.
    • 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 and Pausable representing a faucet of this Valve.
        onError - a callback of errors or null
        onComplete - a callback for completion event or null
        Throws:
        NullPointerException - if onData parameter is null
        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 and Pausable representing a faucet of this Valve.
        Throws:
        NullPointerException - if onData parameter is null
        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 or null
        onComplete - a callback for completion event or null
        Throws:
        NullPointerException - if onData parameter is null
        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 - if onData parameter is null
        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 or null
        Throws:
        NullPointerException - if onData parameter is null
        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 a Valve consisting of the results of applying the given function to the elements of this Valve.
        Type Parameters:
        K - the element type of the new Valve
        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 new Valve instance which combines all results into a single Valve.

        If provided mapFunction returns null then this result is skipped.

        Type Parameters:
        K - the element type of the new Valve
        Parameters:
        mapFunction - maps an element into new Valve instance.
        Returns:
        the new Valve
      • filter

        default Valve<T> filter​(Predicate<T> predicate)
        Returns a Valve consisting of the elements of this Valve that match the given 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 a Valve consisting of the elements of this Valve, additionally performing the provided action on each element as elements are consumed from the resulting Valve.
        Parameters:
        action - an action to perform on the elements as they are consumed from the Valve
        Returns:
        the new Valve
      • collect

        default <A,​R> CompletionStage<R> collect​(Collector<? super T,​A,​R> collector)
        Returns a CompletionStage which will be completed when this Valve is completed and result is a collected value.

        Result completes exceptionally if this Valve completes exceptionally.

        Type Parameters:
        A - the intermediate accumulation type of the Collector
        R - the type of the result
        Parameters:
        collector - a collector to use
        Returns:
        a completion stage of collected result
      • executeOn

        default Valve<T> executeOn​(ExecutorService executorService)
        Returns new Valve which defer all handlers to provided ExecutorService. Each data chunk will be still called sequentially.
        Parameters:
        executorService - an executor service to use
        Returns:
        a new Valve instance
        Throws:
        NullPointerException - if executorService parameter is null.
      • toIterator

        default ValveIterator<T> toIterator()
        Transforms this Valve into ValveIterator representation. It transforms reactive approach to the blocking polling Iterator API.
        Returns:
        an iterator instance
        Throws:
        IllegalStateException - if this instance has already registered handlers