Class OnHeapCompactingMessageStore

java.lang.Object
de.otto.synapse.messagestore.OnHeapCompactingMessageStore
All Implemented Interfaces:
MessageStore, java.lang.AutoCloseable

@ThreadSafe
public class OnHeapCompactingMessageStore
extends java.lang.Object
implements MessageStore
Thread-safe in-memory (on heap) implementation of a MessageStore that is compacting entries by the message's Key.compactionKey().

Features:

  • Thread-Safe
  • Supports a maximum capacity, with eviction of least-recently used (LRU) messages
  • Supports instant compaction of messages.
  • No indexing of messages is supported.
  • Constructor Summary

    Constructors 
    Constructor Description
    OnHeapCompactingMessageStore​(boolean removeNullPayloadMessages)  
    OnHeapCompactingMessageStore​(boolean removeNullPayloadMessages, long maxCapacity)  
  • Method Summary

    Modifier and Type Method Description
    void add​(MessageStoreEntry entry)
    Appends the specified element to the end of this list (optional operation).
    java.util.Set<java.lang.String> getChannelNames()
    Returns a set containing the channel names of the messages contained in the MessageStore
    com.google.common.collect.ImmutableSet<Index> getIndexes()  
    ChannelPosition getLatestChannelPosition​(java.lang.String channelName)
    Returns the latest ChannelPosition of the given channel, derived from the messages contained in this MessageStore.
    long size()
    Returns the number of messages contained in the MessageStore.
    java.util.stream.Stream<MessageStoreEntry> stream()
    Returns a Stream of all entries contained in the MessageStore.
    java.util.stream.Stream<MessageStoreEntry> stream​(Index index, java.lang.String value)
    Returns a Stream of all entries contained in the MessageStore that have are matching the given Index value (optional operation).

    Methods inherited from class java.lang.Object

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

    Methods inherited from interface de.otto.synapse.messagestore.MessageStore

    close, getLatestChannelPosition, isCompacting
  • Constructor Details

  • Method Details

    • add

      public void add​(MessageStoreEntry entry)
      Description copied from interface: MessageStore
      Appends the specified element to the end of this list (optional operation).

      MessageStores that support this operation may place limitations on what elements may be added to this list. In particular, some stores will refuse to add entries for more than a single channel. MessageStore classes should clearly specify in their documentation any restrictions on what elements may be added.

      Specified by:
      add in interface MessageStore
      Parameters:
      entry - element to be appended to this message store
    • getChannelNames

      public java.util.Set<java.lang.String> getChannelNames()
      Description copied from interface: MessageStore
      Returns a set containing the channel names of the messages contained in the MessageStore
      Specified by:
      getChannelNames in interface MessageStore
      Returns:
      set of channel names
    • getIndexes

      public com.google.common.collect.ImmutableSet<Index> getIndexes()
      Specified by:
      getIndexes in interface MessageStore
    • getLatestChannelPosition

      public ChannelPosition getLatestChannelPosition​(java.lang.String channelName)
      Description copied from interface: MessageStore
      Returns the latest ChannelPosition of the given channel, derived from the messages contained in this 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()

      Specified by:
      getLatestChannelPosition in interface MessageStore
      Parameters:
      channelName - the name of the channel
      Returns:
      ChannelPosition
    • stream

      public java.util.stream.Stream<MessageStoreEntry> stream()
      Description copied from interface: MessageStore
      Returns a Stream of all entries contained in the MessageStore.

      The stream will maintain the insertion order of the entries.

      Specified by:
      stream in interface MessageStore
      Returns:
      Stream of entries
    • stream

      public java.util.stream.Stream<MessageStoreEntry> stream​(Index index, java.lang.String value)
      Description copied from interface: MessageStore
      Returns a Stream of all entries contained in the MessageStore that have are matching the given Index value (optional operation).

      The stream will maintain the insertion order of the entries.

      Specified by:
      stream in interface MessageStore
      Parameters:
      index - the Index
      value - the value identifying the requested messages in the specified index
      Returns:
      stream of message-store entries matching the index or emptyStream, if the index is not known, or if there are no entries
    • size

      public long size()
      Description copied from interface: MessageStore
      Returns the number of messages contained in the MessageStore.

      Primarily 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.

      Specified by:
      size in interface MessageStore
      Returns:
      number of messages