Class RoundRobinMultiReadonlyBuffer<T>
- java.lang.Object
-
- io.axoniq.axonserver.connector.impl.buffer.RoundRobinMultiReadonlyBuffer<T>
-
- Type Parameters:
T- the type of messages this buffer contain
- All Implemented Interfaces:
CloseableReadonlyBuffer<T>,DisposableReadonlyBuffer<T>
public class RoundRobinMultiReadonlyBuffer<T> extends Object implements DisposableReadonlyBuffer<T>
An implementation of theDisposableReadonlyBufferthat operates across multipleDisposableReadonlyBufferinstances. Operations are delegated to these instances in a round-robin fashion.- Since:
- 4.6.0
- Author:
- Milan Savic, Stefan Dragisic, Allard Buijze
-
-
Constructor Summary
Constructors Constructor Description RoundRobinMultiReadonlyBuffer(List<? extends DisposableReadonlyBuffer<T>> buffers)Instantiates this buffer with a list of delegates.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcapacity()Sums up capacities of all buffers.booleanclosed()Checks whether all buffers are closed.voiddispose()Calls aDisposableReadonlyBuffer.dispose()on each and every buffer.Optional<ErrorMessage>error()Retrieves an error from the first buffer if all buffers errored out.booleanisEmpty()Checks whether all buffers are empty.voidonAvailable(Runnable onAvailable)RegistersonAvailablehandler to all buffersOptional<T>poll()Polls the element from one of the buffers in a round-robin fashion.
-
-
-
Constructor Detail
-
RoundRobinMultiReadonlyBuffer
public RoundRobinMultiReadonlyBuffer(List<? extends DisposableReadonlyBuffer<T>> buffers)
Instantiates this buffer with a list of delegates.- Parameters:
buffers- a list of delegates
-
-
Method Detail
-
poll
public Optional<T> poll()
Polls the element from one of the buffers in a round-robin fashion.- Specified by:
pollin interfaceCloseableReadonlyBuffer<T>- Returns:
- an
Optionalwith polled message - See Also:
CloseableReadonlyBuffer.poll()
-
closed
public boolean closed()
Checks whether all buffers are closed.- Specified by:
closedin interfaceCloseableReadonlyBuffer<T>- Returns:
trueif all buffers are closed,falseotherwise- See Also:
CloseableReadonlyBuffer.closed()
-
error
public Optional<ErrorMessage> error()
Retrieves an error from the first buffer if all buffers errored out.- Specified by:
errorin interfaceCloseableReadonlyBuffer<T>- Returns:
- the error from the first buffer if all buffers errored out
- See Also:
CloseableReadonlyBuffer.error()
-
isEmpty
public boolean isEmpty()
Checks whether all buffers are empty.- Specified by:
isEmptyin interfaceCloseableReadonlyBuffer<T>- Returns:
trueif all buffers are empty,falseotherwise- See Also:
CloseableReadonlyBuffer.isEmpty()
-
capacity
public int capacity()
Sums up capacities of all buffers.- Specified by:
capacityin interfaceCloseableReadonlyBuffer<T>- Returns:
- the sum of capacities of all buffers
- See Also:
CloseableReadonlyBuffer.capacity()
-
onAvailable
public void onAvailable(Runnable onAvailable)
RegistersonAvailablehandler to all buffers- Specified by:
onAvailablein interfaceCloseableReadonlyBuffer<T>- Parameters:
onAvailable- to be invoked when there are changes in buffers- See Also:
CloseableReadonlyBuffer.onAvailable(Runnable)
-
dispose
public void dispose()
Calls aDisposableReadonlyBuffer.dispose()on each and every buffer.- Specified by:
disposein interfaceDisposableReadonlyBuffer<T>- See Also:
DisposableReadonlyBuffer.dispose()
-
-