mirror of https://github.com/grpc/grpc-java.git
core: only try to resolve InternalCensusStatsAccessor once
This commit is contained in:
parent
22863dda38
commit
cb2b68e39d
|
|
@ -104,6 +104,30 @@ public final class ManagedChannelImplBuilder
|
||||||
private static final long DEFAULT_RETRY_BUFFER_SIZE_IN_BYTES = 1L << 24; // 16M
|
private static final long DEFAULT_RETRY_BUFFER_SIZE_IN_BYTES = 1L << 24; // 16M
|
||||||
private static final long DEFAULT_PER_RPC_BUFFER_LIMIT_IN_BYTES = 1L << 20; // 1M
|
private static final long DEFAULT_PER_RPC_BUFFER_LIMIT_IN_BYTES = 1L << 20; // 1M
|
||||||
|
|
||||||
|
private static final Method GET_CLIENT_INTERCEPTOR_METHOD;
|
||||||
|
|
||||||
|
static {
|
||||||
|
Method getClientInterceptorMethod = null;
|
||||||
|
try {
|
||||||
|
Class<?> censusStatsAccessor =
|
||||||
|
Class.forName("io.grpc.census.InternalCensusStatsAccessor");
|
||||||
|
getClientInterceptorMethod =
|
||||||
|
censusStatsAccessor.getDeclaredMethod(
|
||||||
|
"getClientInterceptor",
|
||||||
|
boolean.class,
|
||||||
|
boolean.class,
|
||||||
|
boolean.class,
|
||||||
|
boolean.class);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
// Replace these separate catch statements with multicatch when Android min-API >= 19
|
||||||
|
log.log(Level.FINE, "Unable to apply census stats", e);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
log.log(Level.FINE, "Unable to apply census stats", e);
|
||||||
|
}
|
||||||
|
GET_CLIENT_INTERCEPTOR_METHOD = getClientInterceptorMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ObjectPool<? extends Executor> executorPool = DEFAULT_EXECUTOR_POOL;
|
ObjectPool<? extends Executor> executorPool = DEFAULT_EXECUTOR_POOL;
|
||||||
|
|
||||||
ObjectPool<? extends Executor> offloadExecutorPool = DEFAULT_EXECUTOR_POOL;
|
ObjectPool<? extends Executor> offloadExecutorPool = DEFAULT_EXECUTOR_POOL;
|
||||||
|
|
@ -647,34 +671,24 @@ public final class ManagedChannelImplBuilder
|
||||||
}
|
}
|
||||||
if (!isGlobalInterceptorsSet && statsEnabled) {
|
if (!isGlobalInterceptorsSet && statsEnabled) {
|
||||||
ClientInterceptor statsInterceptor = null;
|
ClientInterceptor statsInterceptor = null;
|
||||||
try {
|
|
||||||
Class<?> censusStatsAccessor =
|
if (GET_CLIENT_INTERCEPTOR_METHOD != null) {
|
||||||
Class.forName("io.grpc.census.InternalCensusStatsAccessor");
|
try {
|
||||||
Method getClientInterceptorMethod =
|
statsInterceptor =
|
||||||
censusStatsAccessor.getDeclaredMethod(
|
(ClientInterceptor) GET_CLIENT_INTERCEPTOR_METHOD
|
||||||
"getClientInterceptor",
|
.invoke(
|
||||||
boolean.class,
|
null,
|
||||||
boolean.class,
|
recordStartedRpcs,
|
||||||
boolean.class,
|
recordFinishedRpcs,
|
||||||
boolean.class);
|
recordRealTimeMetrics,
|
||||||
statsInterceptor =
|
recordRetryMetrics);
|
||||||
(ClientInterceptor) getClientInterceptorMethod
|
} catch (IllegalAccessException e) {
|
||||||
.invoke(
|
log.log(Level.FINE, "Unable to apply census stats", e);
|
||||||
null,
|
} catch (InvocationTargetException e) {
|
||||||
recordStartedRpcs,
|
log.log(Level.FINE, "Unable to apply census stats", e);
|
||||||
recordFinishedRpcs,
|
}
|
||||||
recordRealTimeMetrics,
|
|
||||||
recordRetryMetrics);
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
// Replace these separate catch statements with multicatch when Android min-API >= 19
|
|
||||||
log.log(Level.FINE, "Unable to apply census stats", e);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
log.log(Level.FINE, "Unable to apply census stats", e);
|
|
||||||
} catch (IllegalAccessException e) {
|
|
||||||
log.log(Level.FINE, "Unable to apply census stats", e);
|
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
log.log(Level.FINE, "Unable to apply census stats", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (statsInterceptor != null) {
|
if (statsInterceptor != null) {
|
||||||
// First interceptor runs last (see ClientInterceptors.intercept()), so that no
|
// First interceptor runs last (see ClientInterceptors.intercept()), so that no
|
||||||
// other interceptor can override the tracer factory we set in CallOptions.
|
// other interceptor can override the tracer factory we set in CallOptions.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue