Class BufferStrategies

java.lang.Object
io.servicetalk.concurrent.api.BufferStrategies

public final class BufferStrategies extends Object
A static factory of BufferStrategy instances.
  • Method Details

    • forCountOrTime

      public static <T> BufferStrategy<T,BufferStrategy.Accumulator<T,Iterable<T>>,Iterable<T>> forCountOrTime(int count, Duration duration)
      Returns a BufferStrategy that creates buffer boundaries based on number of items buffered or time elapsed since the current buffer boundary started. This does not guarantee that the emitted buffers after applying the returned BufferStrategy will have exactly count number of items. The emitted buffers may have less or more items than the count.
      Type Parameters:
      T - Type of items added to the buffer.
      Parameters:
      count - Number of items to add before closing the current buffer boundary, if not already closed. The emitted buffers may have less or more items than this count.
      duration - Duration after which the current buffer boundary is closed, if not already closed.
      Returns:
      BufferStrategy that creates buffer boundaries based on number of items buffered or time elapsed since the current buffer boundary started.
    • forCountOrTime

      public static <T> BufferStrategy<T,BufferStrategy.Accumulator<T,Iterable<T>>,Iterable<T>> forCountOrTime(int count, Duration duration, Executor executor)
      Returns a BufferStrategy that creates buffer boundaries based on number of items buffered or time elapsed since the current buffer boundary started. This does not guarantee that the emitted buffers after applying the returned BufferStrategy will have exactly count number of items. The emitted buffers may have less or more items than the count.
      Type Parameters:
      T - Type of items added to the buffer.
      Parameters:
      count - Number of items to add before closing the current buffer boundary, if not already closed.
      duration - Duration after which the current buffer boundary is closed, if not already closed.
      executor - Executor to use for recording the passed duration.
      Returns:
      BufferStrategy that creates buffer boundaries based on number of items buffered or time elapsed since the current buffer boundary started.
    • forCountOrTime

      public static <T, BC extends BufferStrategy.Accumulator<T, B>, B> BufferStrategy<T,BufferStrategy.Accumulator<T,B>,B> forCountOrTime(int count, Duration duration, Supplier<BC> accumulatorSupplier)
      Returns a BufferStrategy that creates buffer boundaries based on number of items buffered or time elapsed since the current buffer boundary started. This does not guarantee that the emitted buffers after applying the returned BufferStrategy will have exactly count number of items. The emitted buffers may have less or more items than the count.
      Type Parameters:
      T - Type of items added to the buffer.
      BC - Type of BufferStrategy.Accumulator used to accumulate items in a buffer.
      B - Type of object created after an BufferStrategy.Accumulator is finished.
      Parameters:
      count - Number of items to add before closing the current buffer boundary, if not already closed.
      duration - Duration after which the current buffer boundary is closed, if not already closed.
      accumulatorSupplier - A Supplier of BufferStrategy.Accumulator every time a buffer boundary is closed. Methods on the BufferStrategy.Accumulator returned from this Supplier may or may not be called.
      Returns:
      BufferStrategy that creates buffer boundaries based on number of items buffered or time elapsed since the current buffer boundary started.
    • forCountOrTime

      public static <T, BC extends BufferStrategy.Accumulator<T, B>, B> BufferStrategy<T,BufferStrategy.Accumulator<T,B>,B> forCountOrTime(int count, Duration duration, Supplier<BC> accumulatorSupplier, Executor executor)
      Returns a BufferStrategy that creates buffer boundaries based on number of items buffered or time elapsed since the current buffer boundary started. This does not guarantee that the emitted buffers after applying the returned BufferStrategy will have exactly count number of items. The emitted buffers may have less or more items than the count.
      Type Parameters:
      T - Type of items added to the buffer.
      BC - Type of BufferStrategy.Accumulator used to accumulate items in a buffer.
      B - Type of object created after an BufferStrategy.Accumulator is finished.
      Parameters:
      count - Number of items to add before closing the current buffer boundary, if not already closed.
      duration - Duration after which the current buffer boundary is closed, if not already closed.
      accumulatorSupplier - A Supplier of BufferStrategy.Accumulator every time a buffer boundary is closed. Methods on the BufferStrategy.Accumulator returned from this Supplier may or may not be called.
      executor - Executor to use for recording the passed duration.
      Returns:
      BufferStrategy that creates buffer boundaries based on number of items buffered or time elapsed since the current buffer boundary started.