Class DefaultRequestHandler

java.lang.Object
io.fluxzero.sdk.publishing.DefaultRequestHandler
All Implemented Interfaces:
Namespaced<RequestHandler>, RequestHandler, AutoCloseable

public class DefaultRequestHandler extends Object implements RequestHandler
Default implementation of the RequestHandler interface.

This handler supports both single and batch request dispatching, tracking responses using an internal ConcurrentHashMap keyed by requestId. When a request is sent, the handler subscribes to a corresponding result log (e.g., result or web response) via a TrackingClient, which listens for responses targeted at this client only.

Each request is assigned a unique requestId and tagged with the client's source identifier. When a response with a matching requestId is received, the corresponding CompletableFuture is completed.

If no response is received within the configured timeout (default: 200 seconds), the future is completed exceptionally.

This request handle supports chunked responses. Request senders that can deal with chunked responses should use sendRequest(SerializedMessage, Consumer, Duration, Consumer)}. If a chunked response is received, but the request sender expected a single response, the intermediate responses are aggregated before completing the request.

Features:

  • Supports both single and batch request dispatching.
  • Tracks responses via the configured MessageType and filters using filterMessageTarget = true.
  • Ensures startup of the underlying result tracker on first request dispatch.
  • Cleans up subscriptions and pending futures on close().
See Also:
  • Constructor Details

    • DefaultRequestHandler

      public DefaultRequestHandler(Client client, MessageType resultType, Duration timeout, String responseConsumerName)
      Constructs a DefaultRequestHandler with the specified client, message type, timeout, and response consumer name. This constructor creates an internal worker pool for handling requests and responses.
      Parameters:
      client - the client responsible for sending and receiving messages
      resultType - the type of message expected as a result
      timeout - the maximum duration to wait for a response
      responseConsumerName - the name of the consumer responsible for handling the response
    • DefaultRequestHandler

      public DefaultRequestHandler(Client client, MessageType resultType)
      Constructs a DefaultRequestHandler with the specified client and message type, and a default timeout of 200 seconds. This constructor creates an internal worker pool for handling requests and responses.

      Uses a default name for the result consumer based on the application name.

      Parameters:
      client - the client responsible for sending and receiving messages
      resultType - the type of message expected as a result
  • Method Details