@ThreadSafe public class InMemoryRingBufferMessageStore extends java.lang.Object implements WritableMessageStore
Each time an element is added to a full message store, the message store automatically removes its head element.
| Constructor and Description |
|---|
InMemoryRingBufferMessageStore()
Creates a new instance with default capacity of 100.
|
InMemoryRingBufferMessageStore(int capacity)
Creates a new instance with specified capacity.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(Message<java.lang.String> message)
Adds a Message to the MessageStore.
|
ChannelPosition |
getLatestChannelPosition()
Returns the latest
ChannelPosition of the MessageStore. |
int |
size()
Returns the number of messages contained in the MessageStore.
|
java.util.stream.Stream<Message<java.lang.String>> |
stream()
Returns a Stream of
messages contained in the MessageStore. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitclosepublic InMemoryRingBufferMessageStore()
public InMemoryRingBufferMessageStore(int capacity)
capacity - the size of the underlying ring buffer.public void add(Message<java.lang.String> message)
If the capacity of the ring buffer is reached, the oldest message is removed
add in interface WritableMessageStoremessage - the message to addpublic ChannelPosition getLatestChannelPosition()
ChannelPosition of the MessageStore.
The position is calculated by merging the
optional positions of the messages.
Messages without positions will not change the latest ChannelPosition. If no message contains
position information, the returned ChannelPosition is ChannelPosition.fromHorizon()
getLatestChannelPosition in interface MessageStorepublic java.util.stream.Stream<Message<java.lang.String>> stream()
messages contained in the MessageStore.
The stream will maintain the insertion order of the messages.
stream in interface MessageStorepublic int size()
MessageStorePrimarily used for testing purposes. If the MessageStore can not implement this without major performance impacts (like, for example, having to download and parse huge files from S3), the method is not required to be implemented.
size in interface MessageStore