Class ReplayDispatcher

java.lang.Object
org.apache.synapse.transport.http.conn.ReplayDispatcher

public class ReplayDispatcher extends Object
Singleton manager class responsible for buffering replay data and asynchronously writing it to a configured ReplayDataWriter. A dedicated background thread consumes records from the queue and writes them using the ReplayDataWriter implementation configured dynamically through properties. This class is thread-safe. On JVM shutdown, queued records are written within a bounded time and the writer is closed once.
  • Method Details

    • getInstance

      public static ReplayDispatcher getInstance()
      Returns the singleton instance of the ReplayDispatcher, creating it if necessary. Dynamically instantiates the writer class configured via properties. Throws an IllegalStateException for missing or invalid configuration.
      Returns:
      singleton instance of this dispatcher
    • addReplayRecord

      public void addReplayRecord(String messageId, Map<String,Object> metadata, byte[] data)
      Adds a replay record to the internal buffer queue for later asynchronous writing. If the queue is full, drops the message and logs drop occurrences at configured frequency.
      Parameters:
      messageId - unique identifier of the message
      metadata - metadata map describing contextual information of the message
      data - raw byte array of the message content
    • addReplayRecord

      public void addReplayRecord(ByteBuffer dataBuffer, int byteWritten, String messageId, Map<String,Object> metadata)
      Convenience method to wrap data in ByteBuffer and delegate to addReplayRecord(String, byte[], Map).
      Parameters:
      dataBuffer - byte buffer containing the raw message data
      byteWritten - number of bytes written to the buffer
      messageId - unique message identifier
      metadata - metadata map for contextual information
    • shutdown

      public void shutdown()
      Stops accepting replay records, waits up to 10000L ms for the workers to write the queued records, and closes the writer once. Called from a JVM shutdown hook. Calling it more than once has no effect.