Class StreamingPhysicsExpander

java.lang.Object
org.mockserver.llm.StreamingPhysicsExpander

public class StreamingPhysicsExpander extends Object
Applies streaming physics (timing delays) to a list of SSE events.

Algorithm (per spec section 2.3.2):

  • If physics is null or all fields are null, return the events unchanged.
  • Event 0 delay = timeToFirstToken (default 0 ms).
  • Events 1..n delay = baseDelay * (1 + uniform(-jitter, +jitter)) where baseDelay = 1000 / tokensPerSecond ms.
  • Uses java.util.Random seeded with physics.seed (default System.nanoTime()) for reproducible jitter.
  • Method Details

    • applyPhysics

      public static List<SseEvent> applyPhysics(List<SseEvent> rawEvents, StreamingPhysics physics)
      Apply streaming physics delays to SSE events.
      Parameters:
      rawEvents - the raw events from the codec (not mutated)
      physics - streaming physics parameters (may be null)
      Returns:
      a new list of events with per-event delays set