Class InFlightRequest

java.lang.Object
org.mockserver.netty.InFlightRequest

public final class InFlightRequest extends Object
Per-request in-flight token used by the WS7.2 graceful-shutdown connection drain.

A token is created and LifeCycle.requestProcessingStarted() is incremented exactly once when a data-plane HTTP request begins processing in HttpRequestHandler.channelRead0(io.netty.channel.ChannelHandlerContext, org.mockserver.model.HttpRequest). The matching LifeCycle.requestProcessingComplete() decrement is driven by complete(), which is invoked from whichever of these fires first:

  • the response funnel — NettyResponseWriter.sendResponse(...), through which every data-plane response flows (normal, streaming, chunked, forward/proxy, error/exception, breakpoint-modified); or
  • the channel closeFuture safety net — covers requests that never produce a response (connection drop or pipeline-killing exception mid-processing).

An AtomicBoolean guard guarantees the decrement fires exactly once regardless of how many of those hooks fire, so the in-flight counter can never leak (which would make stop() always wait the full drain timeout) nor be decremented twice.

Author:
jamesdbloom
  • Method Details

    • started

      public static InFlightRequest started(LifeCycle server)
      Increment the in-flight counter and return a token whose complete() will decrement it exactly once. Returns null when no LifeCycle is available (so callers can no-op safely).
    • complete

      public void complete()
      Decrement the in-flight counter, but only the first time this is called for this token. Safe to call from any thread and from multiple completion hooks.