Class BlockingCloseableBuffer<T>
- java.lang.Object
-
- io.axoniq.axonserver.connector.impl.buffer.BlockingCloseableBuffer<T>
-
- Type Parameters:
T- the type of messages in this buffer
- All Implemented Interfaces:
CloseableBuffer<T>,CloseableReadonlyBuffer<T>
public class BlockingCloseableBuffer<T> extends Object implements CloseableBuffer<T>
An implementation of theCloseableBufferthat uses aLinkedBlockingQueueas the backing buffer.- Since:
- 4.6.0
- Author:
- Milan Savic, Stefan Dragisic, Allard Buijze
-
-
Constructor Summary
Constructors Constructor Description BlockingCloseableBuffer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcapacity()Returns the overall capacity of this buffer.voidclose()Closes this buffer from the producing side.booleanclosed()Indicates whether the buffer is closed by the producing side.voidcloseExceptionally(ErrorMessage errorMessage)Closes this buffer exceptionally from the producing side.Optional<ErrorMessage>error()Returns an error from this buffer, if any.booleanisEmpty()Indicates whether there are messages in the buffer.protected voidnotifyOnAvailable()voidonAvailable(Runnable onAvailable)Registers an action to be triggered when there is a new message added to the buffer, or the buffer is closed, or the buffer is closed with an error.Optional<T>poll()Polls the message from this buffer.voidput(T message)Puts a message in this buffer.intsize()Returns the number of elements in this buffer.
-
-
-
Method Detail
-
poll
public Optional<T> poll()
Description copied from interface:CloseableReadonlyBufferPolls the message from this buffer. If the returnedOptionalis empty, that doesn't mean that this buffer stays empty forever. TheCloseableReadonlyBuffer.closed()method should be consolidated to validate this.- Specified by:
pollin interfaceCloseableReadonlyBuffer<T>- Returns:
- an
Optionalwith polled message
-
isEmpty
public boolean isEmpty()
Description copied from interface:CloseableReadonlyBufferIndicates whether there are messages in the buffer. If this returnsfalse, that doesn't mean that this buffer stays empty forever. TheCloseableReadonlyBuffer.closed()method should be consolidated to validate this.- Specified by:
isEmptyin interfaceCloseableReadonlyBuffer<T>- Returns:
trueif buffer is empty,falseotherwise
-
capacity
public int capacity()
Description copied from interface:CloseableReadonlyBufferReturns the overall capacity of this buffer.- Specified by:
capacityin interfaceCloseableReadonlyBuffer<T>- Returns:
- the overall capacity of this buffer
-
size
public int size()
Returns the number of elements in this buffer.- Returns:
- the number of elements in this buffer
-
onAvailable
public void onAvailable(Runnable onAvailable)
Description copied from interface:CloseableReadonlyBufferRegisters an action to be triggered when there is a new message added to the buffer, or the buffer is closed, or the buffer is closed with an error. The action can checkCloseableReadonlyBuffer.poll(),CloseableReadonlyBuffer.closed(), andCloseableReadonlyBuffer.error()to validate this.- Specified by:
onAvailablein interfaceCloseableReadonlyBuffer<T>- Parameters:
onAvailable- to be invoked when there are changes in this buffer
-
put
public void put(T message)
Description copied from interface:CloseableBufferPuts a message in this buffer.- Specified by:
putin interfaceCloseableBuffer<T>- Parameters:
message- the message to be put in this buffer
-
closed
public boolean closed()
Description copied from interface:CloseableReadonlyBufferIndicates whether the buffer is closed by the producing side.- Specified by:
closedin interfaceCloseableReadonlyBuffer<T>- Returns:
trueif closed,falseotherwise
-
error
public Optional<ErrorMessage> error()
Description copied from interface:CloseableReadonlyBufferReturns an error from this buffer, if any.- Specified by:
errorin interfaceCloseableReadonlyBuffer<T>- Returns:
- an
Optionalof an error, if any
-
close
public void close()
Description copied from interface:CloseableBufferCloses this buffer from the producing side.- Specified by:
closein interfaceCloseableBuffer<T>
-
closeExceptionally
public void closeExceptionally(ErrorMessage errorMessage)
Description copied from interface:CloseableBufferCloses this buffer exceptionally from the producing side.- Specified by:
closeExceptionallyin interfaceCloseableBuffer<T>- Parameters:
errorMessage- an error indicating why this buffer is closed
-
notifyOnAvailable
protected void notifyOnAvailable()
-
-