Package com.sodius.oslc.server.trs.store
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
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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
accept(T t)
This implementation appends the element into the buffer.void
flush()
Callsflush(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.
-
-
-
Constructor Detail
-
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, theflush()
method is called to process the buffer.- Parameters:
bufferSize
- the size of the buffer.
-
-
Method Detail
-
accept
public void accept(T t)
This implementation appends the element into the buffer. If the buffer of consumed elements reaches this maximum size, theflush()
method is called to process the buffer.
-
flush
public void flush()
Callsflush(List)
to process the buffer of consumed elements at once. The buffer is then reset to empty.
-
-