242 lines
8.4 KiB
Java
242 lines
8.4 KiB
Java
|
package io.grpc;
|
||
|
|
||
|
import com.google.android.gms.measurement.api.AppMeasurementSdk;
|
||
|
import com.google.common.base.MoreObjects;
|
||
|
import com.google.common.base.Preconditions;
|
||
|
import io.grpc.ClientStreamTracer;
|
||
|
import java.lang.reflect.Array;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.Arrays;
|
||
|
import java.util.Collections;
|
||
|
import java.util.List;
|
||
|
import java.util.concurrent.Executor;
|
||
|
import java.util.concurrent.TimeUnit;
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public final class CallOptions {
|
||
|
public static final CallOptions DEFAULT = new CallOptions();
|
||
|
private String authority;
|
||
|
private String compressorName;
|
||
|
private CallCredentials credentials;
|
||
|
private Object[][] customOptions;
|
||
|
private Deadline deadline;
|
||
|
private Executor executor;
|
||
|
private Integer maxInboundMessageSize;
|
||
|
private Integer maxOutboundMessageSize;
|
||
|
private List<ClientStreamTracer.Factory> streamTracerFactories;
|
||
|
private Boolean waitForReady;
|
||
|
|
||
|
public final CallOptions withAuthority(String str) {
|
||
|
CallOptions callOptions = new CallOptions(this);
|
||
|
callOptions.authority = str;
|
||
|
return callOptions;
|
||
|
}
|
||
|
|
||
|
public final CallOptions withCallCredentials(CallCredentials callCredentials) {
|
||
|
CallOptions callOptions = new CallOptions(this);
|
||
|
callOptions.credentials = callCredentials;
|
||
|
return callOptions;
|
||
|
}
|
||
|
|
||
|
public final CallOptions withCompression(String str) {
|
||
|
CallOptions callOptions = new CallOptions(this);
|
||
|
callOptions.compressorName = str;
|
||
|
return callOptions;
|
||
|
}
|
||
|
|
||
|
public final CallOptions withDeadline(Deadline deadline) {
|
||
|
CallOptions callOptions = new CallOptions(this);
|
||
|
callOptions.deadline = deadline;
|
||
|
return callOptions;
|
||
|
}
|
||
|
|
||
|
public final CallOptions withDeadlineAfter(long j, TimeUnit timeUnit) {
|
||
|
return withDeadline(Deadline.after(j, timeUnit));
|
||
|
}
|
||
|
|
||
|
public final CallOptions withWaitForReady() {
|
||
|
CallOptions callOptions = new CallOptions(this);
|
||
|
callOptions.waitForReady = Boolean.TRUE;
|
||
|
return callOptions;
|
||
|
}
|
||
|
|
||
|
public final CallOptions withoutWaitForReady() {
|
||
|
CallOptions callOptions = new CallOptions(this);
|
||
|
callOptions.waitForReady = Boolean.FALSE;
|
||
|
return callOptions;
|
||
|
}
|
||
|
|
||
|
public final CallOptions withExecutor(Executor executor) {
|
||
|
CallOptions callOptions = new CallOptions(this);
|
||
|
callOptions.executor = executor;
|
||
|
return callOptions;
|
||
|
}
|
||
|
|
||
|
public final CallOptions withStreamTracerFactory(ClientStreamTracer.Factory factory) {
|
||
|
CallOptions callOptions = new CallOptions(this);
|
||
|
ArrayList arrayList = new ArrayList(this.streamTracerFactories.size() + 1);
|
||
|
arrayList.addAll(this.streamTracerFactories);
|
||
|
arrayList.add(factory);
|
||
|
callOptions.streamTracerFactories = Collections.unmodifiableList(arrayList);
|
||
|
return callOptions;
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes6.dex */
|
||
|
public static final class Key<T> {
|
||
|
private final String debugString;
|
||
|
private final T defaultValue;
|
||
|
|
||
|
private Key(String str, T t) {
|
||
|
this.debugString = str;
|
||
|
this.defaultValue = t;
|
||
|
}
|
||
|
|
||
|
@Deprecated
|
||
|
public static <T> Key<T> of(String str, T t) {
|
||
|
Preconditions.checkNotNull(str, "debugString");
|
||
|
return new Key<>(str, t);
|
||
|
}
|
||
|
|
||
|
public static <T> Key<T> create(String str) {
|
||
|
Preconditions.checkNotNull(str, "debugString");
|
||
|
return new Key<>(str, null);
|
||
|
}
|
||
|
|
||
|
public static <T> Key<T> createWithDefault(String str, T t) {
|
||
|
Preconditions.checkNotNull(str, "debugString");
|
||
|
return new Key<>(str, t);
|
||
|
}
|
||
|
|
||
|
public final String toString() {
|
||
|
return this.debugString;
|
||
|
}
|
||
|
|
||
|
public final T getDefault() {
|
||
|
return this.defaultValue;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final <T> CallOptions withOption(Key<T> key, T t) {
|
||
|
Preconditions.checkNotNull(key, "key");
|
||
|
Preconditions.checkNotNull(t, AppMeasurementSdk.ConditionalUserProperty.VALUE);
|
||
|
CallOptions callOptions = new CallOptions(this);
|
||
|
int i = 0;
|
||
|
while (true) {
|
||
|
Object[][] objArr = this.customOptions;
|
||
|
if (i >= objArr.length) {
|
||
|
i = -1;
|
||
|
break;
|
||
|
}
|
||
|
if (key.equals(objArr[i][0])) {
|
||
|
break;
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
Object[][] objArr2 = (Object[][]) Array.newInstance((Class<?>) Object.class, this.customOptions.length + (i == -1 ? 1 : 0), 2);
|
||
|
callOptions.customOptions = objArr2;
|
||
|
Object[][] objArr3 = this.customOptions;
|
||
|
System.arraycopy(objArr3, 0, objArr2, 0, objArr3.length);
|
||
|
if (i == -1) {
|
||
|
callOptions.customOptions[this.customOptions.length] = new Object[]{key, t};
|
||
|
} else {
|
||
|
callOptions.customOptions[i] = new Object[]{key, t};
|
||
|
}
|
||
|
return callOptions;
|
||
|
}
|
||
|
|
||
|
public final <T> T getOption(Key<T> key) {
|
||
|
Preconditions.checkNotNull(key, "key");
|
||
|
int i = 0;
|
||
|
while (true) {
|
||
|
Object[][] objArr = this.customOptions;
|
||
|
if (i >= objArr.length) {
|
||
|
return (T) ((Key) key).defaultValue;
|
||
|
}
|
||
|
if (key.equals(objArr[i][0])) {
|
||
|
return (T) this.customOptions[i][1];
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private CallOptions() {
|
||
|
this.streamTracerFactories = Collections.emptyList();
|
||
|
this.customOptions = (Object[][]) Array.newInstance((Class<?>) Object.class, 0, 2);
|
||
|
}
|
||
|
|
||
|
public final boolean isWaitForReady() {
|
||
|
return Boolean.TRUE.equals(this.waitForReady);
|
||
|
}
|
||
|
|
||
|
public final CallOptions withMaxInboundMessageSize(int i) {
|
||
|
Preconditions.checkArgument(i >= 0, "invalid maxsize %s", i);
|
||
|
CallOptions callOptions = new CallOptions(this);
|
||
|
callOptions.maxInboundMessageSize = Integer.valueOf(i);
|
||
|
return callOptions;
|
||
|
}
|
||
|
|
||
|
public final CallOptions withMaxOutboundMessageSize(int i) {
|
||
|
Preconditions.checkArgument(i >= 0, "invalid maxsize %s", i);
|
||
|
CallOptions callOptions = new CallOptions(this);
|
||
|
callOptions.maxOutboundMessageSize = Integer.valueOf(i);
|
||
|
return callOptions;
|
||
|
}
|
||
|
|
||
|
private CallOptions(CallOptions callOptions) {
|
||
|
this.streamTracerFactories = Collections.emptyList();
|
||
|
this.deadline = callOptions.deadline;
|
||
|
this.authority = callOptions.authority;
|
||
|
this.credentials = callOptions.credentials;
|
||
|
this.executor = callOptions.executor;
|
||
|
this.compressorName = callOptions.compressorName;
|
||
|
this.customOptions = callOptions.customOptions;
|
||
|
this.waitForReady = callOptions.waitForReady;
|
||
|
this.maxInboundMessageSize = callOptions.maxInboundMessageSize;
|
||
|
this.maxOutboundMessageSize = callOptions.maxOutboundMessageSize;
|
||
|
this.streamTracerFactories = callOptions.streamTracerFactories;
|
||
|
}
|
||
|
|
||
|
public final String toString() {
|
||
|
MoreObjects.ToStringHelper add = MoreObjects.toStringHelper(this).add("deadline", this.deadline).add("authority", this.authority).add("callCredentials", this.credentials);
|
||
|
Executor executor = this.executor;
|
||
|
return add.add("executor", executor != null ? executor.getClass() : null).add("compressorName", this.compressorName).add("customOptions", Arrays.deepToString(this.customOptions)).add("waitForReady", isWaitForReady()).add("maxInboundMessageSize", this.maxInboundMessageSize).add("maxOutboundMessageSize", this.maxOutboundMessageSize).add("streamTracerFactories", this.streamTracerFactories).toString();
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
public final Boolean getWaitForReady() {
|
||
|
return this.waitForReady;
|
||
|
}
|
||
|
|
||
|
public final List<ClientStreamTracer.Factory> getStreamTracerFactories() {
|
||
|
return this.streamTracerFactories;
|
||
|
}
|
||
|
|
||
|
public final Integer getMaxOutboundMessageSize() {
|
||
|
return this.maxOutboundMessageSize;
|
||
|
}
|
||
|
|
||
|
public final Integer getMaxInboundMessageSize() {
|
||
|
return this.maxInboundMessageSize;
|
||
|
}
|
||
|
|
||
|
public final Executor getExecutor() {
|
||
|
return this.executor;
|
||
|
}
|
||
|
|
||
|
public final Deadline getDeadline() {
|
||
|
return this.deadline;
|
||
|
}
|
||
|
|
||
|
public final CallCredentials getCredentials() {
|
||
|
return this.credentials;
|
||
|
}
|
||
|
|
||
|
public final String getCompressor() {
|
||
|
return this.compressorName;
|
||
|
}
|
||
|
|
||
|
public final String getAuthority() {
|
||
|
return this.authority;
|
||
|
}
|
||
|
}
|