Interface ClientTransportWrapper
- All Superinterfaces:
Comparable<ClientTransportWrapper>
Wrappers are discovered via Java's ServiceLoader mechanism. To register a wrapper,
create a file META-INF/services/org.a2aproject.sdk.client.transport.spi.ClientTransportWrapper
containing the fully qualified class name of your implementation.
Wrappers are sorted by priority in descending order (highest priority first).
This interface implements Comparable to enable natural sorting.
Example implementation:
public class TracingWrapper implements ClientTransportWrapper {
@Override
public ClientTransport wrap(ClientTransport transport, ClientTransportConfig<?> config) {
if (config.getParameters().containsKey("tracer")) {
return new TracingTransport(transport, (Tracer) config.getParameters().get("tracer"));
}
return transport;
}
@Override
public int priority() {
return 100; // Higher priority = wraps earlier (outermost)
}
}
-
Method Summary
Modifier and TypeMethodDescriptiondefault intcompareTo(ClientTransportWrapper other) Compares this wrapper with another based on priority.default intpriority()Returns the priority of this wrapper.wrap(ClientTransport transport, ClientTransportConfig<?> config) Wraps the given transport with additional functionality.
-
Method Details
-
wrap
Wraps the given transport with additional functionality.Implementations should check the configuration to determine if they should actually wrap the transport. If the wrapper is not applicable (e.g., required configuration is missing), return the original transport unchanged.
- Parameters:
transport- the transport to wrapconfig- the transport configuration, may contain wrapper-specific parameters- Returns:
- the wrapped transport, or the original if wrapping is not applicable
-
priority
default int priority()Returns the priority of this wrapper. Higher priority wrappers are applied first (wrap the transport earlier, resulting in being the outermost wrapper).Default priority is 0. Suggested ranges:
- 1000+ : Critical infrastructure (security, authentication)
- 500-999: Observability (tracing, metrics, logging)
- 100-499: Enhancement (caching, retry logic)
- 0-99: Optional features
- Returns:
- the priority value, higher values = higher priority
-
compareTo
Compares this wrapper with another based on priority. Returns a negative integer, zero, or a positive integer as this wrapper has higher priority than, equal to, or lower priority than the specified wrapper.Note: This comparison is reversed (higher priority comes first) to enable natural sorting in descending priority order.
- Specified by:
compareToin interfaceComparable<ClientTransportWrapper>- Parameters:
other- the wrapper to compare to- Returns:
- negative if this has higher priority, positive if lower, zero if equal
-