193 lines
8.1 KiB
Java
193 lines
8.1 KiB
Java
package io.grpc;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
import io.grpc.ClientCall;
|
|
import io.grpc.MethodDescriptor;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public class ClientInterceptors {
|
|
private static final ClientCall<Object, Object> NOOP_CALL = new ClientCall<Object, Object>() { // from class: io.grpc.ClientInterceptors.2
|
|
@Override // io.grpc.ClientCall
|
|
public void cancel(String str, Throwable th) {
|
|
}
|
|
|
|
@Override // io.grpc.ClientCall
|
|
public void halfClose() {
|
|
}
|
|
|
|
@Override // io.grpc.ClientCall
|
|
public boolean isReady() {
|
|
return false;
|
|
}
|
|
|
|
@Override // io.grpc.ClientCall
|
|
public void request(int i) {
|
|
}
|
|
|
|
@Override // io.grpc.ClientCall
|
|
public void sendMessage(Object obj) {
|
|
}
|
|
|
|
@Override // io.grpc.ClientCall
|
|
public void start(ClientCall.Listener<Object> listener, Metadata metadata) {
|
|
}
|
|
};
|
|
|
|
private ClientInterceptors() {
|
|
}
|
|
|
|
public static Channel interceptForward(Channel channel, ClientInterceptor... clientInterceptorArr) {
|
|
return interceptForward(channel, (List<? extends ClientInterceptor>) Arrays.asList(clientInterceptorArr));
|
|
}
|
|
|
|
public static Channel interceptForward(Channel channel, List<? extends ClientInterceptor> list) {
|
|
ArrayList arrayList = new ArrayList(list);
|
|
Collections.reverse(arrayList);
|
|
return intercept(channel, arrayList);
|
|
}
|
|
|
|
public static Channel intercept(Channel channel, ClientInterceptor... clientInterceptorArr) {
|
|
return intercept(channel, (List<? extends ClientInterceptor>) Arrays.asList(clientInterceptorArr));
|
|
}
|
|
|
|
public static Channel intercept(Channel channel, List<? extends ClientInterceptor> list) {
|
|
Preconditions.checkNotNull(channel, "channel");
|
|
Iterator<? extends ClientInterceptor> it = list.iterator();
|
|
while (it.hasNext()) {
|
|
channel = new InterceptorChannel(channel, it.next(), null);
|
|
}
|
|
return channel;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* renamed from: io.grpc.ClientInterceptors$1, reason: invalid class name */
|
|
/* loaded from: classes6.dex */
|
|
public class AnonymousClass1 implements ClientInterceptor {
|
|
final ClientInterceptor val$interceptor;
|
|
final MethodDescriptor.Marshaller val$reqMarshaller;
|
|
final MethodDescriptor.Marshaller val$respMarshaller;
|
|
|
|
AnonymousClass1(MethodDescriptor.Marshaller marshaller, MethodDescriptor.Marshaller marshaller2, ClientInterceptor clientInterceptor) {
|
|
this.val$reqMarshaller = marshaller;
|
|
this.val$respMarshaller = marshaller2;
|
|
this.val$interceptor = clientInterceptor;
|
|
}
|
|
|
|
@Override // io.grpc.ClientInterceptor
|
|
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions, Channel channel) {
|
|
return new C00741(this, this.val$interceptor.interceptCall(methodDescriptor.toBuilder(this.val$reqMarshaller, this.val$respMarshaller).build(), callOptions, channel), methodDescriptor);
|
|
}
|
|
|
|
/* JADX INFO: Add missing generic type declarations: [ReqT, RespT] */
|
|
/* renamed from: io.grpc.ClientInterceptors$1$1, reason: invalid class name and collision with other inner class name */
|
|
/* loaded from: classes6.dex */
|
|
class C00741<ReqT, RespT> extends PartialForwardingClientCall<ReqT, RespT> {
|
|
final AnonymousClass1 this$0;
|
|
final MethodDescriptor val$method;
|
|
final ClientCall val$wrappedCall;
|
|
|
|
C00741(AnonymousClass1 anonymousClass1, ClientCall clientCall, MethodDescriptor methodDescriptor) {
|
|
this.this$0 = anonymousClass1;
|
|
this.val$wrappedCall = clientCall;
|
|
this.val$method = methodDescriptor;
|
|
}
|
|
|
|
@Override // io.grpc.ClientCall
|
|
public void start(ClientCall.Listener<RespT> listener, Metadata metadata) {
|
|
this.val$wrappedCall.start(new PartialForwardingClientCallListener<WRespT>(this, listener) { // from class: io.grpc.ClientInterceptors.1.1.1
|
|
final C00741 this$1;
|
|
final ClientCall.Listener val$responseListener;
|
|
|
|
{
|
|
this.this$1 = this;
|
|
this.val$responseListener = listener;
|
|
}
|
|
|
|
@Override // io.grpc.ClientCall.Listener
|
|
public void onMessage(WRespT wrespt) {
|
|
this.val$responseListener.onMessage(this.this$1.val$method.getResponseMarshaller().parse(this.this$1.this$0.val$respMarshaller.stream(wrespt)));
|
|
}
|
|
|
|
@Override // io.grpc.PartialForwardingClientCallListener
|
|
protected ClientCall.Listener<?> delegate() {
|
|
return this.val$responseListener;
|
|
}
|
|
}, metadata);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // io.grpc.ClientCall
|
|
public void sendMessage(ReqT reqt) {
|
|
this.val$wrappedCall.sendMessage(this.this$0.val$reqMarshaller.parse(this.val$method.getRequestMarshaller().stream(reqt)));
|
|
}
|
|
|
|
@Override // io.grpc.PartialForwardingClientCall
|
|
protected ClientCall<?, ?> delegate() {
|
|
return this.val$wrappedCall;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static <WReqT, WRespT> ClientInterceptor wrapClientInterceptor(ClientInterceptor clientInterceptor, MethodDescriptor.Marshaller<WReqT> marshaller, MethodDescriptor.Marshaller<WRespT> marshaller2) {
|
|
return new AnonymousClass1(marshaller, marshaller2, clientInterceptor);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes6.dex */
|
|
public static class InterceptorChannel extends Channel {
|
|
private final Channel channel;
|
|
private final ClientInterceptor interceptor;
|
|
|
|
/* synthetic */ InterceptorChannel(Channel channel, ClientInterceptor clientInterceptor, AnonymousClass1 anonymousClass1) {
|
|
this(channel, clientInterceptor);
|
|
}
|
|
|
|
private InterceptorChannel(Channel channel, ClientInterceptor clientInterceptor) {
|
|
this.channel = channel;
|
|
this.interceptor = (ClientInterceptor) Preconditions.checkNotNull(clientInterceptor, "interceptor");
|
|
}
|
|
|
|
@Override // io.grpc.Channel
|
|
public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> methodDescriptor, CallOptions callOptions) {
|
|
return this.interceptor.interceptCall(methodDescriptor, callOptions, this.channel);
|
|
}
|
|
|
|
@Override // io.grpc.Channel
|
|
public String authority() {
|
|
return this.channel.authority();
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
public static abstract class CheckedForwardingClientCall<ReqT, RespT> extends ForwardingClientCall<ReqT, RespT> {
|
|
private ClientCall<ReqT, RespT> delegate;
|
|
|
|
protected abstract void checkedStart(ClientCall.Listener<RespT> listener, Metadata metadata) throws Exception;
|
|
|
|
protected CheckedForwardingClientCall(ClientCall<ReqT, RespT> clientCall) {
|
|
this.delegate = clientCall;
|
|
}
|
|
|
|
@Override // io.grpc.ForwardingClientCall, io.grpc.ClientCall
|
|
public final void start(ClientCall.Listener<RespT> listener, Metadata metadata) {
|
|
try {
|
|
checkedStart(listener, metadata);
|
|
} catch (Exception e) {
|
|
this.delegate = ClientInterceptors.NOOP_CALL;
|
|
listener.onClose(Status.fromThrowable(e), new Metadata());
|
|
}
|
|
}
|
|
|
|
@Override // io.grpc.ForwardingClientCall, io.grpc.PartialForwardingClientCall
|
|
protected final ClientCall<ReqT, RespT> delegate() {
|
|
return this.delegate;
|
|
}
|
|
}
|
|
}
|