what-the-bank/sources/io/grpc/internal/ReflectionLongAdderCounter....

127 lines
4.3 KiB
Java

package io.grpc.internal;
import com.google.android.gms.analytics.ecommerce.ProductAction;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
/* loaded from: classes6.dex */
public final class ReflectionLongAdderCounter implements LongCounter {
private static final Method addMethod;
private static final Constructor<?> defaultConstructor;
private static final RuntimeException initializationException;
private static final Logger logger = Logger.getLogger(ReflectionLongAdderCounter.class.getName());
private static final Object[] one;
private static final Method sumMethod;
private final Object instance;
static {
Method method;
Method method2;
Constructor<?> constructor;
Class<?> cls;
int i;
try {
cls = Class.forName("java.util.concurrent.atomic.LongAdder");
i = 0;
method = cls.getMethod(ProductAction.ACTION_ADD, Long.TYPE);
try {
method2 = cls.getMethod("sum", new Class[0]);
} catch (Throwable th) {
th = th;
method2 = null;
}
} catch (Throwable th2) {
th = th2;
method = null;
method2 = null;
}
try {
Constructor<?>[] constructors = cls.getConstructors();
int length = constructors.length;
while (true) {
if (i >= length) {
constructor = null;
break;
}
constructor = constructors[i];
if (constructor.getParameterTypes().length == 0) {
break;
} else {
i++;
}
}
th = null;
} catch (Throwable th3) {
th = th3;
logger.log(Level.FINE, "LongAdder can not be found via reflection, this is normal for JDK7 and below", th);
constructor = null;
if (th == null) {
}
defaultConstructor = null;
addMethod = null;
sumMethod = null;
initializationException = new RuntimeException(th);
one = new Object[]{1L};
}
if (th == null || constructor == null) {
defaultConstructor = null;
addMethod = null;
sumMethod = null;
initializationException = new RuntimeException(th);
} else {
defaultConstructor = constructor;
addMethod = method;
sumMethod = method2;
initializationException = null;
}
one = new Object[]{1L};
}
/* JADX INFO: Access modifiers changed from: package-private */
public ReflectionLongAdderCounter() {
RuntimeException runtimeException = initializationException;
if (runtimeException != null) {
throw runtimeException;
}
try {
this.instance = defaultConstructor.newInstance(new Object[0]);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InstantiationException e2) {
throw new RuntimeException(e2);
} catch (InvocationTargetException e3) {
throw new RuntimeException(e3);
}
}
@Override // io.grpc.internal.LongCounter
public final void add(long j) {
try {
addMethod.invoke(this.instance, j == 1 ? one : new Object[]{Long.valueOf(j)});
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e2) {
throw new RuntimeException(e2);
}
}
@Override // io.grpc.internal.LongCounter
public final long value() {
try {
return ((Long) sumMethod.invoke(this.instance, new Object[0])).longValue();
} catch (IllegalAccessException unused) {
throw new RuntimeException();
} catch (InvocationTargetException unused2) {
throw new RuntimeException();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public static boolean isAvailable() {
return initializationException == null;
}
}