Class BufferedConsumer<T>

java.lang.Object
com.sodius.oslc.server.trs.store.BufferedConsumer<T>
Type Parameters:
T - the type of the input to the operation
All Implemented Interfaces:
Flushable, Consumer<T>

public abstract class BufferedConsumer<T> extends Object implements Consumer<T>, Flushable
Buffers the consumed elements so that they can be processing by chunks. This class is useful in case performing one action on a list of elements provides better performance than an action for each element of the list.
Since:
1.10.0
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    BufferedConsumer(int bufferSize)
    Creates a consumer whose buffer with a specified maximum size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    accept(T t)
    This implementation appends the element into the buffer.
    void
    Calls flush(List) to process the buffer of consumed elements at once.
    protected abstract void
    flush(List<T> buffer)
    Performs the operation on the buffer of consumed elements.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.util.function.Consumer

    andThen
  • Constructor Details

    • BufferedConsumer

      protected BufferedConsumer(int bufferSize)
      Creates a consumer whose buffer with a specified maximum size. Once the size of the buffer of consumed elements reaches this maximum, the flush() method is called to process the buffer.
      Parameters:
      bufferSize - the size of the buffer.
  • Method Details

    • accept

      public void accept(T t)
      This implementation appends the element into the buffer. If the buffer of consumed elements reaches this maximum size, the flush() method is called to process the buffer.
      Specified by:
      accept in interface Consumer<T>
    • flush

      public void flush()
      Calls flush(List) to process the buffer of consumed elements at once. The buffer is then reset to empty.
      Specified by:
      flush in interface Flushable
    • flush

      protected abstract void flush(List<T> buffer)
      Performs the operation on the buffer of consumed elements.
      Parameters:
      buffer - the consumed elements to process.