Class MultiplexedChannel<REQ,RESP>

java.lang.Object
io.bytestreams.exchange.core.AbstractChannel<REQ,RESP>
io.bytestreams.exchange.core.MultiplexedChannel<REQ,RESP>
Type Parameters:
REQ - the request message type
RESP - the response message type
All Implemented Interfaces:
Channel, ClientChannel<REQ,RESP>
Direct Known Subclasses:
SymmetricChannel

public class MultiplexedChannel<REQ,RESP> extends AbstractChannel<REQ,RESP>
A ClientChannel backed by a Transport using ID-based (multiplexed) correlation.

Responses are matched to requests by message ID, allowing out-of-order completion. Supports bounded concurrency (backpressure). Uncorrelated responses are dispatched to the UnhandledMessageHandler, which subclasses may override via onUncorrelatedMessage(Object).

  • Field Details

    • tracer

      protected final io.opentelemetry.api.trace.Tracer tracer
    • writeLock

      protected final Object writeLock
    • errorHandler

      protected final ErrorHandler<REQ,RESP> errorHandler
  • Method Details

    • builder

      public static <REQ, RESP> MultiplexedChannel.Builder<REQ,RESP> builder()
    • onInbound

      protected void onInbound(RESP response)
      Specified by:
      onInbound in class AbstractChannel<REQ,RESP>
    • onUncorrelatedMessage

      protected void onUncorrelatedMessage(RESP response)
      Called when the read loop receives a response that cannot be correlated to any pending request.

      The default implementation delegates to the UnhandledMessageHandler provided at construction time. Subclasses (e.g. SymmetricChannel) may override this to handle inbound requests that arrive on the same connection.

      Parameters:
      response - the uncorrelated response message
    • hasPending

      protected boolean hasPending()
      Specified by:
      hasPending in class AbstractChannel<REQ,RESP>
    • request

      public CompletableFuture<RESP> request(REQ request)
      Description copied from interface: ClientChannel
      Sends a message using the channel's configured default timeout and returns a future that completes when a correlated response arrives.
      Specified by:
      request in interface ClientChannel<REQ,RESP>
      Parameters:
      request - the message to send
      Returns:
      a future that completes with the correlated response
    • request

      public CompletableFuture<RESP> request(REQ request, Duration timeout)
      Description copied from interface: ClientChannel
      Sends a message with a per-request timeout override.
      Specified by:
      request in interface ClientChannel<REQ,RESP>
      Parameters:
      request - the message to send
      timeout - the timeout for this request; must be positive
      Returns:
      a future that completes with the correlated response