Class Valves


  • public class Valves
    extends Object
    An utility class for Valve interface.
    • Method Detail

      • from

        @SafeVarargs
        public static <T> Valve<T> from​(T... t)
        Creates a Valve instance from provided array.

        If t array parameter is null then returns an empty Valve.

        Type Parameters:
        T - a type of the array items
        Parameters:
        t - an array to provide as a Valve
        Returns:
        the new instance
      • from

        public static <T> Valve<T> from​(Iterable<T> iterable)
        Creates a Valve instance from the provided Iterable.

        If iterable parameter is null then returns an empty Valve.

        Type Parameters:
        T - a type of iterable items
        Parameters:
        iterable - an iterable to provide as a Valve
        Returns:
        the new instance
      • from

        public static Valve<ByteBuffer> from​(InputStream stream,
                                             int bufferCapacity)
        Creates a ByteBuffer based Valve instance from the provided InputStream. Each byte buffer will have the provided capacity.

        Each byte buffer uses a newly allocated memory and as such no pooling is performed.

        Parameters:
        stream - the input stream to create the Valve from
        bufferCapacity - the capacity of each buffer of bytes
        Returns:
        the new instance
      • from

        public static Valve<ByteBuffer> from​(InputStream stream,
                                             int bufferCapacity,
                                             ExecutorService executorService)
        Creates a ByteBuffer based Valve instance from the provided InputStream. Each byte buffer will have the provided capacity.

        Each byte buffer uses a newly allocated memory and as such no pooling is performed.

        Parameters:
        stream - the input stream to create the Valve from
        bufferCapacity - the capacity of each buffer of bytes
        executorService - the executor service to use for an execution of the InputStream.read() (and its overloads) operations that are blocking by its nature.
        Returns:
        the new instance
      • from

        public static <T> Valve<T> from​(Flow.Publisher<T> publisher)
        Creates a Valve instance from provided Flow.Publisher.

        If publisher parameter is null then returns an empty Valve.

        Type Parameters:
        T - a type of published items
        Parameters:
        publisher - a publisher to provide as a Valve
        Returns:
        the new instance
      • empty

        public static <T> Valve<T> empty()
        Returns an empty Valve - instance, which report complete as soon as handler is registered.

        For performance reason, this particular Valve accepts any amount of handlers.

        Type Parameters:
        T - type of the item (which is not there :-) )
        Returns:
        singleton instance