Class SimpleMessageStore

All Implemented Interfaces:
Iterable<MessageGroup>, BasicMessageGroupStore, ChannelMessageStore, MessageGroupStore, MessageStore

public class SimpleMessageStore extends AbstractMessageGroupStore implements MessageStore, ChannelMessageStore
Map-based in-memory implementation of MessageStore and MessageGroupStore. Enforces a maximum capacity for the store.
Since:
2.0
Author:
Iwein Fuld, Mark Fisher, Dave Syer, Oleg Zhurakousky, Gary Russell, Ryan Barker, Artem Bilan
  • Constructor Details

    • SimpleMessageStore

      public SimpleMessageStore(int individualCapacity, int groupCapacity)
      Creates a SimpleMessageStore with a maximum size limited by the given capacity, or unlimited size if the given capacity is less than 1. The capacities are applied independently to messages stored via addMessage(Message) and to those stored via AbstractMessageGroupStore.addMessageToGroup(Object, Message). In both cases the capacity applies to the number of messages that can be stored, and once that limit is reached attempting to store another will result in an exception.
      Parameters:
      individualCapacity - The message capacity.
      groupCapacity - The capacity of each group.
    • SimpleMessageStore

      public SimpleMessageStore(int individualCapacity, int groupCapacity, long upperBoundTimeout)
      Create a SimpleMessageStore with a maximum size limited by the given capacity and the timeout in millisecond to wait for the empty slot in the store.
      Parameters:
      individualCapacity - The message capacity.
      groupCapacity - The capacity of each group.
      upperBoundTimeout - The time to wait if the store is at max capacity.
      Since:
      4.3
      See Also:
    • SimpleMessageStore

      public SimpleMessageStore(int individualCapacity, int groupCapacity, LockRegistry lockRegistry)
      Creates a SimpleMessageStore with a maximum size limited by the given capacity and LockRegistry for the message group operations concurrency.
      Parameters:
      individualCapacity - The message capacity.
      groupCapacity - The capacity of each group.
      lockRegistry - The lock registry.
      See Also:
    • SimpleMessageStore

      public SimpleMessageStore(int individualCapacity, int groupCapacity, long upperBoundTimeout, LockRegistry lockRegistry)
      Creates a SimpleMessageStore with a maximum size limited by the given capacity, the timeout in millisecond to wait for the empty slot in the store and LockRegistry for the message group operations concurrency.
      Parameters:
      individualCapacity - The message capacity.
      groupCapacity - The capacity of each group.
      upperBoundTimeout - The time to wait if the store is at max capacity
      lockRegistry - The lock registry.
      Since:
      4.3
    • SimpleMessageStore

      public SimpleMessageStore(int capacity)
      Creates a SimpleMessageStore with the same capacity for individual and grouped messages.
      Parameters:
      capacity - The capacity.
    • SimpleMessageStore

      public SimpleMessageStore()
      Create a SimpleMessageStore with unlimited capacity.
  • Method Details

    • setCopyOnGet

      public void setCopyOnGet(boolean copyOnGet)
      Set as false to disable copying the group in getMessageGroup(Object). Starting with 4.1, this is false by default.
      Parameters:
      copyOnGet - True to copy, false to not.
      Since:
      4.0.1
    • setLockRegistry

      public void setLockRegistry(LockRegistry lockRegistry)
    • setLazyLoadMessageGroups

      public void setLazyLoadMessageGroups(boolean lazyLoadMessageGroups)
      Description copied from class: AbstractMessageGroupStore
      Specify if the result of the BasicMessageGroupStore.getMessageGroup(Object) should be wrapped to the PersistentMessageGroup - a lazy-load proxy for messages in group Defaults to true.

      The target logic is based on the SimpleMessageGroupFactory.GroupType.PERSISTENT.

      Overrides:
      setLazyLoadMessageGroups in class AbstractMessageGroupStore
      Parameters:
      lazyLoadMessageGroups - the boolean flag to use.
    • 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.
    • 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.
    • getMessage

      public Message<?> getMessage(UUID key)
      Specified by:
      getMessage in interface MessageStore
      Parameters:
      key - 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 id)
      Description copied from interface: MessageStore
      Return a MessageMetadata for the Message by provided id.
      Specified by:
      getMessageMetadata in interface MessageStore
      Parameters:
      id - 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).
    • removeMessage

      public Message<?> removeMessage(UUID key)
      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. If this method is implemented on a MessageGroupStore, the message is removed from the store only if no groups holding this message.
      Specified by:
      removeMessage in interface MessageStore
      Parameters:
      key - the message identifier.
      Returns:
      the message (if any).
    • getMessageGroup

      public MessageGroup getMessageGroup(Object groupId)
      Description copied from interface: BasicMessageGroupStore
      Return all Messages currently in the MessageStore that were stored using BasicMessageGroupStore.addMessageToGroup(Object, Message) with this group id.
      Specified by:
      getMessageGroup in interface BasicMessageGroupStore
      Parameters:
      groupId - The group identifier.
      Returns:
      A group of messages, empty if none exists for this key.
    • copy

      protected MessageGroup copy(MessageGroup group)
      Description copied from class: AbstractMessageGroupStore
      Used by expireMessageGroups. We need to return a snapshot of the group at the time the reaper runs, so we can properly detect if the group changed between now and the attempt to expire the group. Not necessary for persistent stores, so the default behavior is to just return the group.
      Overrides:
      copy in class AbstractMessageGroupStore
      Parameters:
      group - The group.
      Returns:
      The group, or a copy.
    • 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.
    • removeMessageGroup

      public void removeMessageGroup(Object groupId)
      Description copied from interface: BasicMessageGroupStore
      Remove the message group with this id.
      Specified by:
      removeMessageGroup in interface BasicMessageGroupStore
      Parameters:
      groupId - The id of the group to remove.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • 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.
    • clearMessageGroup

      public void clearMessageGroup(Object groupId)