Interface BufferedBlockingConsumer<T>

  • Type Parameters:
    T - the type of the input to the operation
    All Superinterfaces:
    BlockingConsumer<T>

    public interface BufferedBlockingConsumer<T>
    extends BlockingConsumer<T>
    A BlockingConsumer that retains a maximum number of values in a buffer before sending them to a delegate consumer.

    This maintains the same order of the values.

    Author:
    Randall Hauch
    • Method Detail

      • close

        void close​(Function<T,​T> function)
            throws InterruptedException
        Flush all of the buffered values to the delegate by first running each buffered value through the given function to generate a new value to be flushed to the delegate consumer.

        BlockingConsumer.accept(Object) may not be called after this method has been called.

        Parameters:
        function - the function to apply to the values that are flushed
        Throws:
        InterruptedException - if the thread is interrupted while this consumer is blocked
      • bufferLast

        static <T> BufferedBlockingConsumer<T> bufferLast​(BlockingConsumer<T> delegate)
        Get a BufferedBlockingConsumer that buffers just the last value seen by the consumer. When another value is then added to the consumer, this buffered consumer will push the prior value into the delegate and buffer the latest.

        The resulting consumer is threadsafe.

        Parameters:
        delegate - the delegate to which values should be flushed; may not be null
        Returns:
        the blocking consumer that buffers a single value at a time; never null