20
20
import static com .google .common .base .Preconditions .checkNotNull ;
21
21
import static io .grpc .internal .GrpcUtil .DEFAULT_MAX_MESSAGE_SIZE ;
22
22
23
- import android .util .Log ;
24
23
import com .google .common .annotations .VisibleForTesting ;
25
24
import com .google .common .base .Preconditions ;
26
25
import com .google .common .util .concurrent .MoreExecutors ;
38
37
import io .grpc .internal .ManagedChannelImplBuilder .ClientTransportFactoryBuilder ;
39
38
import io .grpc .internal .SharedResourceHolder ;
40
39
import io .grpc .internal .TransportTracer ;
41
- import java .lang .reflect .InvocationTargetException ;
42
- import java .lang .reflect .Method ;
43
40
import java .net .InetSocketAddress ;
44
41
import java .net .SocketAddress ;
45
42
import java .util .Collection ;
49
46
import javax .annotation .Nullable ;
50
47
import org .chromium .net .BidirectionalStream ;
51
48
import org .chromium .net .CronetEngine ;
52
- import org .chromium .net .ExperimentalBidirectionalStream ;
53
- import org .chromium .net .ExperimentalCronetEngine ;
54
49
55
50
/** Convenience class for building channels with the cronet transport. */
56
51
@ ExperimentalApi ("There is no plan to make this API stable, given transport API instability" )
57
52
public final class CronetChannelBuilder extends ForwardingChannelBuilder2 <CronetChannelBuilder > {
58
53
59
- private static final String LOG_TAG = "CronetChannelBuilder" ;
60
-
61
54
/** BidirectionalStream.Builder factory used for getting the gRPC BidirectionalStream. */
62
55
public static abstract class StreamBuilderFactory {
63
56
public abstract BidirectionalStream .Builder newBidirectionalStreamBuilder (
@@ -296,11 +289,6 @@ public Collection<Class<? extends SocketAddress>> getSupportedSocketAddressTypes
296
289
* StreamBuilderFactory impl that applies TrafficStats tags to stream builders that are produced.
297
290
*/
298
291
private static class TaggingStreamFactory extends StreamBuilderFactory {
299
- private static volatile boolean loadSetTrafficStatsTagAttempted ;
300
- private static volatile boolean loadSetTrafficStatsUidAttempted ;
301
- private static volatile Method setTrafficStatsTagMethod ;
302
- private static volatile Method setTrafficStatsUidMethod ;
303
-
304
292
private final CronetEngine cronetEngine ;
305
293
private final boolean trafficStatsTagSet ;
306
294
private final int trafficStatsTag ;
@@ -323,74 +311,16 @@ private static class TaggingStreamFactory extends StreamBuilderFactory {
323
311
@ Override
324
312
public BidirectionalStream .Builder newBidirectionalStreamBuilder (
325
313
String url , BidirectionalStream .Callback callback , Executor executor ) {
326
- ExperimentalBidirectionalStream .Builder builder =
327
- (( ExperimentalCronetEngine ) cronetEngine )
314
+ BidirectionalStream .Builder builder =
315
+ cronetEngine
328
316
.newBidirectionalStreamBuilder (url , callback , executor );
329
317
if (trafficStatsTagSet ) {
330
- setTrafficStatsTag (builder , trafficStatsTag );
318
+ builder . setTrafficStatsTag (trafficStatsTag );
331
319
}
332
320
if (trafficStatsUidSet ) {
333
- setTrafficStatsUid (builder , trafficStatsUid );
321
+ builder . setTrafficStatsUid (trafficStatsUid );
334
322
}
335
323
return builder ;
336
324
}
337
-
338
- private static void setTrafficStatsTag (ExperimentalBidirectionalStream .Builder builder ,
339
- int tag ) {
340
- if (!loadSetTrafficStatsTagAttempted ) {
341
- synchronized (TaggingStreamFactory .class ) {
342
- if (!loadSetTrafficStatsTagAttempted ) {
343
- try {
344
- setTrafficStatsTagMethod = ExperimentalBidirectionalStream .Builder .class
345
- .getMethod ("setTrafficStatsTag" , int .class );
346
- } catch (NoSuchMethodException e ) {
347
- Log .w (LOG_TAG ,
348
- "Failed to load method ExperimentalBidirectionalStream.Builder.setTrafficStatsTag" ,
349
- e );
350
- } finally {
351
- loadSetTrafficStatsTagAttempted = true ;
352
- }
353
- }
354
- }
355
- }
356
- if (setTrafficStatsTagMethod != null ) {
357
- try {
358
- setTrafficStatsTagMethod .invoke (builder , tag );
359
- } catch (InvocationTargetException e ) {
360
- throw new RuntimeException (e .getCause () == null ? e .getTargetException () : e .getCause ());
361
- } catch (IllegalAccessException e ) {
362
- Log .w (LOG_TAG , "Failed to set traffic stats tag: " + tag , e );
363
- }
364
- }
365
- }
366
-
367
- private static void setTrafficStatsUid (ExperimentalBidirectionalStream .Builder builder ,
368
- int uid ) {
369
- if (!loadSetTrafficStatsUidAttempted ) {
370
- synchronized (TaggingStreamFactory .class ) {
371
- if (!loadSetTrafficStatsUidAttempted ) {
372
- try {
373
- setTrafficStatsUidMethod = ExperimentalBidirectionalStream .Builder .class
374
- .getMethod ("setTrafficStatsUid" , int .class );
375
- } catch (NoSuchMethodException e ) {
376
- Log .w (LOG_TAG ,
377
- "Failed to load method ExperimentalBidirectionalStream.Builder.setTrafficStatsUid" ,
378
- e );
379
- } finally {
380
- loadSetTrafficStatsUidAttempted = true ;
381
- }
382
- }
383
- }
384
- }
385
- if (setTrafficStatsUidMethod != null ) {
386
- try {
387
- setTrafficStatsUidMethod .invoke (builder , uid );
388
- } catch (InvocationTargetException e ) {
389
- throw new RuntimeException (e .getCause () == null ? e .getTargetException () : e .getCause ());
390
- } catch (IllegalAccessException e ) {
391
- Log .w (LOG_TAG , "Failed to set traffic stats uid: " + uid , e );
392
- }
393
- }
394
- }
395
325
}
396
326
}
0 commit comments