Class AbstractKeyValueMessageStore

All Implemented Interfaces:
Iterable<MessageGroup>, BasicMessageGroupStore, MessageGroupStore, MessageStore
Direct Known Subclasses:
HazelcastMessageStore, RedisMessageStore

public abstract class AbstractKeyValueMessageStore extends AbstractMessageGroupStore implements MessageStore
Base class for implementations of Key/Value style MessageGroupStore and MessageStore.
Since:
2.1
Author:
Oleg Zhurakousky, Gary Russell, Artem Bilan
  • Field Details

  • Constructor Details

    • AbstractKeyValueMessageStore

      protected AbstractKeyValueMessageStore()
    • AbstractKeyValueMessageStore

      protected AbstractKeyValueMessageStore(String prefix)
      Construct an instance based on the provided prefix for keys to distinguish between different store instances in the same target key-value data base. Defaults to an empty string - no prefix. The actual prefix for messages is prefix + MESSAGE_; for message groups - prefix + MESSAGE_GROUP_
      Parameters:
      prefix - the prefix to use
      Since:
      4.3.12
  • Method Details

    • getMessagePrefix

      protected String getMessagePrefix()
      Return the configured prefix for message keys to distinguish between different store instances in the same target key-value data base. Defaults to the "MESSAGE_" - without a custom prefix.
      Returns:
      the prefix for keys
      Since:
      4.3.12
    • getGroupPrefix

      public String getGroupPrefix()
      Return the configured prefix for message group keys to distinguish between different store instances in the same target key-value data base. Defaults to the "MESSAGE_GROUP_" - without custom prefix.
      Returns:
      the prefix for keys
      Since:
      4.3.12
    • getMessage

      public Message<?> getMessage(UUID messageId)
      Specified by:
      getMessage in interface MessageStore
      Parameters:
      messageId - The message identifier.
      Returns:
      The Message with the given id, or null if no Message with that id exists in the MessageStore.
    • getMessageMetadata

      public MessageMetadata getMessageMetadata(UUID messageId)
      Description copied from interface: MessageStore
      Return a MessageMetadata for the Message by provided id.
      Specified by:
      getMessageMetadata in interface MessageStore
      Parameters:
      messageId - The message identifier.
      Returns:
      The MessageMetadata with the given id, or null if no Message with that id exists in the MessageStore or the message has no metadata (legacy message from an earlier version).
    • addMessage

      public <T> Message<T> addMessage(Message<T> message)
      Description copied from interface: MessageStore
      Put the provided Message into the MessageStore. The store may need to mutate the message internally, and if it does then the return value can be different than the input. The id of the return value will be used as an index so that the MessageStore.getMessage(UUID) and MessageStore.removeMessage(UUID) behave properly. Since messages are immutable, putting the same message more than once is a no-op.
      Specified by:
      addMessage in interface MessageStore
      Type Parameters:
      T - The payload type.
      Parameters:
      message - The message.
      Returns:
      The message that was stored.
    • doAddMessage

      protected void doAddMessage(Message<?> message)
    • removeMessage

      public Message<?> removeMessage(UUID id)
      Description copied from interface: MessageStore
      Remove the Message with the given id from the MessageStore, if present, and return it. If no Message with that id is present in the store, this will return null.
      Specified by:
      removeMessage in interface MessageStore
      Parameters:
      id - THe message identifier.
      Returns:
      The message.
    • getMessageCount

      @ManagedAttribute public long getMessageCount()
      Description copied from interface: MessageStore
      Optional attribute giving the number of messages in the store. Implementations may decline to respond by throwing an exception.
      Specified by:
      getMessageCount in interface MessageStore
      Returns:
      The number of messages.
    • getMessageGroup

      public MessageGroup getMessageGroup(Object groupId)
      Will create a new instance of SimpleMessageGroup if necessary.
      Specified by:
      getMessageGroup in interface BasicMessageGroupStore
      Parameters:
      groupId - The group identifier.
      Returns:
      A group of messages, empty if none exists for this key.
    • getGroupMetadata

      public MessageGroupMetadata getGroupMetadata(Object groupId)
      Description copied from interface: MessageGroupStore
      Obtain the group metadata without fetching any messages; must supply all other group properties; may include the id of the first message.
      Specified by:
      getGroupMetadata in interface MessageGroupStore
      Overrides:
      getGroupMetadata in class AbstractMessageGroupStore
      Parameters:
      groupId - The group id.
      Returns:
      The metadata.
    • addMessagesToGroup

      public void addMessagesToGroup(Object groupId, Message<?>... messages)
      Description copied from interface: MessageGroupStore
      Store messages with an association to a group id. This can be used to group messages together.
      Specified by:
      addMessagesToGroup in interface MessageGroupStore
      Parameters:
      groupId - The group id to store messages under.
      messages - The messages to add.
    • removeMessagesFromGroup

      public void removeMessagesFromGroup(Object groupId, Collection<Message<?>> messages)
      Description copied from interface: MessageGroupStore
      Persist the deletion of messages from the group.
      Specified by:
      removeMessagesFromGroup in interface MessageGroupStore
      Parameters:
      groupId - The groupId for the group containing the message(s).
      messages - The messages to be removed.
    • completeGroup

      public void completeGroup(Object groupId)
      Description copied from interface: MessageGroupStore
      Completes this MessageGroup. Completion of the MessageGroup generally means that this group should not be allowing any more mutating operation to be performed on it. For example any attempt to add/remove new Message form the group should not be allowed.
      Specified by:
      completeGroup in interface MessageGroupStore
      Parameters:
      groupId - The group identifier.
    • removeMessageGroup

      public void removeMessageGroup(Object groupId)
      Remove the MessageGroup with the provided group ID.
      Specified by:
      removeMessageGroup in interface BasicMessageGroupStore
      Parameters:
      groupId - The id of the group to remove.
    • setGroupCondition

      public void setGroupCondition(Object groupId, String condition)
      Description copied from interface: MessageGroupStore
      Add a condition sentence into the group. Can be used later on for making some decisions for group, e.g. release strategy for correlation handler can consult this condition instead of iterating all the messages in group.
      Specified by:
      setGroupCondition in interface MessageGroupStore
      Parameters:
      groupId - The group identifier.
      condition - The condition to store into the group.
    • setLastReleasedSequenceNumberForGroup

      public void setLastReleasedSequenceNumberForGroup(Object groupId, int sequenceNumber)
      Description copied from interface: MessageGroupStore
      Allows you to set the sequence number of the last released Message. Used for Resequencing use cases
      Specified by:
      setLastReleasedSequenceNumberForGroup in interface MessageGroupStore
      Parameters:
      groupId - The group identifier.
      sequenceNumber - The sequence number.
    • pollMessageFromGroup

      public Message<?> pollMessageFromGroup(Object groupId)
      Description copied from interface: BasicMessageGroupStore
      Poll Message from this MessageGroup (in FIFO style if supported by the implementation) while also removing the polled Message.
      Specified by:
      pollMessageFromGroup in interface BasicMessageGroupStore
      Parameters:
      groupId - The group identifier.
      Returns:
      The message.
    • getOneMessageFromGroup

      public Message<?> getOneMessageFromGroup(Object groupId)
      Description copied from interface: MessageGroupStore
      Return the one Message from MessageGroup.
      Specified by:
      getOneMessageFromGroup in interface MessageGroupStore
      Parameters:
      groupId - The group identifier.
      Returns:
      the Message.
    • getMessagesForGroup

      public Collection<Message<?>> getMessagesForGroup(Object groupId)
      Description copied from interface: MessageGroupStore
      Retrieve messages for the provided group id.
      Specified by:
      getMessagesForGroup in interface MessageGroupStore
      Parameters:
      groupId - The group id to retrieve messages for.
      Returns:
      the messages for group.
    • streamMessagesForGroup

      public Stream<Message<?>> streamMessagesForGroup(Object groupId)
      Description copied from interface: MessageGroupStore
      Return a stream for messages stored in the provided group. The persistent implementations return a Stream which has to be closed once fully processed (e.g. through a try-with-resources clause). By default, it streams a result of MessageGroupStore.getMessagesForGroup(Object).
      Specified by:
      streamMessagesForGroup in interface MessageGroupStore
      Parameters:
      groupId - the group id to retrieve messages.
      Returns:
      the Stream for messages in this group.
    • iterator

      public Iterator<MessageGroup> iterator()
      Specified by:
      iterator in interface Iterable<MessageGroup>
      Specified by:
      iterator in interface MessageGroupStore
      Returns:
      The iterator of currently accumulated MessageGroups.
    • messageGroupSize

      public int messageGroupSize(Object groupId)
      Description copied from interface: BasicMessageGroupStore
      Return the size of this MessageGroup.
      Specified by:
      messageGroupSize in interface BasicMessageGroupStore
      Parameters:
      groupId - The group identifier.
      Returns:
      The size.
    • doRetrieve

      protected abstract Object doRetrieve(Object id)
    • doStore

      protected abstract void doStore(Object id, Object objectToStore)
    • doStoreIfAbsent

      protected abstract void doStoreIfAbsent(Object id, Object objectToStore)
    • doRemove

      protected abstract Object doRemove(Object id)
    • doRemoveAll

      protected abstract void doRemoveAll(Collection<Object> ids)
    • doListKeys

      protected abstract Collection<?> doListKeys(String keyPattern)