Class DefaultResultGateway

java.lang.Object
io.fluxzero.sdk.common.AbstractNamespaced<ResultGateway>
io.fluxzero.sdk.publishing.DefaultResultGateway
All Implemented Interfaces:
Namespaced<ResultGateway>, ResultGateway, AutoCloseable

public class DefaultResultGateway extends AbstractNamespaced<ResultGateway> implements ResultGateway, AutoCloseable
Default implementation of the ResultGateway interface for sending response messages.

This class is responsible for handling responses to commands, queries, dispatching the result message to the specified target using a GatewayClient.

The dispatch process utilizes the DispatchInterceptor and ResponseMapper to modify or monitor messages before they are sent.

See Also:
  • Constructor Details

    • DefaultResultGateway

      public DefaultResultGateway()
  • Method Details

    • createForNamespace

      protected ResultGateway createForNamespace(String namespace)
      Specified by:
      createForNamespace in class AbstractNamespaced<ResultGateway>
    • respond

      public CompletableFuture<Void> respond(Object payload, io.fluxzero.common.api.Metadata metadata, String target, Integer requestId, io.fluxzero.common.Guarantee guarantee)
      Description copied from interface: ResultGateway
      Sends a response with the specified payload, metadata, target, request ID, and delivery guarantee.

      This method gives full control over how and when the response is delivered.

      Specified by:
      respond in interface ResultGateway
      Parameters:
      payload - the payload of the response
      metadata - additional metadata to include
      target - the intended recipient of the response
      requestId - the identifier of the original request
      guarantee - delivery guarantee (e.g., Guarantee.SENT or Guarantee.STORED)
      Returns:
      a CompletableFuture that completes when the response is dispatched (depending on the guarantee)
    • respondBatched

      public CompletableFuture<Void> respondBatched(Object response, String target, Integer requestId)
      Enqueues an automatically published handler response for ordered, context-preserving batch serialization.

      The originating handler context is captured before the response is enqueued. Mapping, interception and serialization then run with that context active on the result workers, allowing the complete response pipeline to overlap with subsequent tracking work. Monitoring and appending remain ordered. The returned future completes when the resulting transport append completes.

    • respondBatched

      public CompletableFuture<Void> respondBatched(Object response, String target, Integer requestId, DefaultResultGateway.ResultPreparationErrorHandler errorHandler)
      Enqueues an automatically published handler response and delegates asynchronous preparation failures to the originating consumer's error handler.
    • respondBatchedAndForget

      public void respondBatchedAndForget(Object response, String target, Integer requestId, DefaultResultGateway.ResultPreparationErrorHandler errorHandler)
      Enqueues an automatically published handler response without allocating an individual completion future.

      The ordered result backlog still waits for the actual transport append before publishing its next batch. This method is intended for consumers that explicitly do not await asynchronous result publication.

    • interceptDispatch

      protected io.fluxzero.common.api.SerializedMessage interceptDispatch(Object payload, io.fluxzero.common.api.Metadata metadata)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Overrides:
      close in class AbstractNamespaced<ResultGateway>