Class SymmetricChannel<T>

Type Parameters:
T - the message type (used for both requests and responses)
All Implemented Interfaces:
Channel, ClientChannel<T,T>

public class SymmetricChannel<T> extends MultiplexedChannel<T,T>
A MultiplexedChannel where request and response types are the same (T=T), enabling bidirectional symmetric messaging on a single connection.

Outbound requests are multiplexed by message ID (via ClientChannel.request(REQ)). Inbound messages that cannot be correlated to a pending outbound request are treated as new inbound requests and dispatched to the registered RequestHandler, which completes a future whose result is enqueued for writing back to the remote peer.

The channel uses SpanKind.INTERNAL and reports channel_type=symmetric in OTel metrics. Outbound requests carry direction=outbound; inbound requests carry direction=inbound.

  • Field Details

    • tracer

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

      protected final Object writeLock
    • errorHandler

      protected final ErrorHandler<T,T> errorHandler
  • Method Details

    • symmetricBuilder

      public static <T> SymmetricChannel.Builder<T> symmetricBuilder()
    • onUncorrelatedMessage

      protected void onUncorrelatedMessage(T message)
      Called by the read loop for inbound messages that cannot be correlated to a pending outbound request. Treats the message as a new inbound request: records metrics, creates a handle span, wires response writing on completion, then dispatches to the registered RequestHandler.
      Overrides:
      onUncorrelatedMessage in class MultiplexedChannel<T,T>
      Parameters:
      message - the uncorrelated (inbound) message
    • hasPending

      protected boolean hasPending()
      Overrides:
      hasPending in class MultiplexedChannel<T,T>
    • request

      public CompletableFuture<T> request(T 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<T> request(T 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