cronet: use reflection to load and invoke experimental APIs in ExperimentalBidirectionalStream.Builder #6111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
grpc-cronet relies on the feature of cronet's
BidirectionalStream, which is created byExperimentalCronetEngine#newBidirectionalStreamBuilder(...)(returns aExperimentalBidirectionalStream.Builder). Since it's "experimental", we want to avoid calling APIs onExperimentalBidirectionalStream.Builder.We've removed grpc-cronet APIs that depends on
ExperimentalBidirectionalStream.Builder's APIs and only allow restricted internal usages. External users should have no chance calling them and result in breakage. Now we switch to load those unstableExperimentalBidirectionalStream.BuilderAPIs and invoke them through reflection at runtime.The three potentially unstable APIs are
setTrafficStatsTag,setTrafficStatsUidandaddRequestAnnotation. For now, we handle method not found or method invocation exceptions by logging a warning and skip calling them. This handling should be tolerable and won't cause severe breakage. But later, we may choose to fail the RPC if failing to call those methods at runtime.I'd expect the class
ExperimentalBidirectionalStream.Builderto be there for stable as it is the return type ofExperimentalCronetEngine#newBidirectionalStreamBuilder(...). So we would not need to loadExperimentalBidirectionalStream.Builderclass through reflection while only for invoking those less likely stable methods.