Class BoundedMessageStore

java.lang.Object
org.mockserver.async.subscribe.BoundedMessageStore

public class BoundedMessageStore extends Object
A thread-safe, bounded FIFO store for RecordedMessage instances. When the store reaches its capacity, the oldest message is evicted to make room.

Uses a synchronized ArrayDeque internally — efficient O(1) add/evict, and safe for concurrent producer (broker thread) + reader (control-plane HTTP thread) patterns with a lock per-channel (not global).

  • Field Details

    • DEFAULT_MAX_RECORDED_MESSAGES

      public static final int DEFAULT_MAX_RECORDED_MESSAGES
      Default maximum number of recorded messages per channel.
      See Also:
  • Constructor Details

    • BoundedMessageStore

      public BoundedMessageStore()
    • BoundedMessageStore

      public BoundedMessageStore(int maxSize)
  • Method Details

    • add

      public void add(RecordedMessage message)
      Add a message to the store. If the store is at capacity, the oldest message is evicted (FIFO). Thread-safe.
    • snapshot

      public List<RecordedMessage> snapshot()
      Return a snapshot copy of all messages currently in the store. The returned list is independent of the store (safe to iterate without locking).
    • size

      public int size()
      Return the current number of messages in the store.
    • clear

      public void clear()
      Clear all messages.