645 lines
23 KiB
Java
645 lines
23 KiB
Java
package io.grpc.internal;
|
|
|
|
import com.google.android.gms.common.internal.ServiceSpecificExtraArgs;
|
|
import com.google.common.base.Preconditions;
|
|
import io.grpc.Attributes;
|
|
import io.grpc.Compressor;
|
|
import io.grpc.Deadline;
|
|
import io.grpc.DecompressorRegistry;
|
|
import io.grpc.Metadata;
|
|
import io.grpc.Status;
|
|
import io.grpc.internal.ClientStreamListener;
|
|
import io.grpc.internal.StreamListener;
|
|
import java.io.InputStream;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes6.dex */
|
|
class DelayedStream implements ClientStream {
|
|
static final boolean $assertionsDisabled = false;
|
|
private DelayedStreamListener delayedListener;
|
|
private Status error;
|
|
private ClientStreamListener listener;
|
|
private volatile boolean passThrough;
|
|
private List<Runnable> pendingCalls = new ArrayList();
|
|
private List<Runnable> preStartPendingCalls = new ArrayList();
|
|
private ClientStream realStream;
|
|
private long startTimeNanos;
|
|
private long streamSetTimeNanos;
|
|
|
|
protected void onEarlyCancellation(Status status) {
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStream
|
|
public void setMaxInboundMessageSize(int i) {
|
|
Preconditions.checkState(this.listener == null, "May only be called before start");
|
|
this.preStartPendingCalls.add(new Runnable(this, i) { // from class: io.grpc.internal.DelayedStream.1
|
|
final DelayedStream this$0;
|
|
final int val$maxSize;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$maxSize = i;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.setMaxInboundMessageSize(this.val$maxSize);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStream
|
|
public void setMaxOutboundMessageSize(int i) {
|
|
Preconditions.checkState(this.listener == null, "May only be called before start");
|
|
this.preStartPendingCalls.add(new Runnable(this, i) { // from class: io.grpc.internal.DelayedStream.2
|
|
final DelayedStream this$0;
|
|
final int val$maxSize;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$maxSize = i;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.setMaxOutboundMessageSize(this.val$maxSize);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStream
|
|
public void setDeadline(Deadline deadline) {
|
|
Preconditions.checkState(this.listener == null, "May only be called before start");
|
|
this.preStartPendingCalls.add(new Runnable(this, deadline) { // from class: io.grpc.internal.DelayedStream.3
|
|
final DelayedStream this$0;
|
|
final Deadline val$deadline;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$deadline = deadline;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.setDeadline(this.val$deadline);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStream
|
|
public void appendTimeoutInsight(InsightBuilder insightBuilder) {
|
|
synchronized (this) {
|
|
if (this.listener == null) {
|
|
return;
|
|
}
|
|
if (this.realStream != null) {
|
|
insightBuilder.appendKeyValue("buffered_nanos", Long.valueOf(this.streamSetTimeNanos - this.startTimeNanos));
|
|
this.realStream.appendTimeoutInsight(insightBuilder);
|
|
} else {
|
|
insightBuilder.appendKeyValue("buffered_nanos", Long.valueOf(System.nanoTime() - this.startTimeNanos));
|
|
insightBuilder.append("waiting_for_connection");
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public final Runnable setStream(ClientStream clientStream) {
|
|
synchronized (this) {
|
|
if (this.realStream != null) {
|
|
return null;
|
|
}
|
|
setRealStream((ClientStream) Preconditions.checkNotNull(clientStream, "stream"));
|
|
ClientStreamListener clientStreamListener = this.listener;
|
|
if (clientStreamListener == null) {
|
|
this.pendingCalls = null;
|
|
this.passThrough = true;
|
|
}
|
|
if (clientStreamListener == null) {
|
|
return null;
|
|
}
|
|
internalStart(clientStreamListener);
|
|
return new Runnable(this) { // from class: io.grpc.internal.DelayedStream.4
|
|
final DelayedStream this$0;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.drainPendingCalls();
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
/* JADX WARN: Code restructure failed: missing block: B:10:0x002a, code lost:
|
|
|
|
if (r0.hasNext() == false) goto L24;
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:11:0x002c, code lost:
|
|
|
|
((java.lang.Runnable) r0.next()).run();
|
|
*/
|
|
/* JADX WARN: Code restructure failed: missing block: B:8:0x0022, code lost:
|
|
|
|
r0 = r1.iterator();
|
|
*/
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
/* JADX WARN: Removed duplicated region for block: B:18:0x0019 */
|
|
/* JADX WARN: Removed duplicated region for block: B:21:? A[RETURN, SYNTHETIC] */
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
public void drainPendingCalls() {
|
|
/*
|
|
r3 = this;
|
|
java.util.ArrayList r0 = new java.util.ArrayList
|
|
r0.<init>()
|
|
L5:
|
|
monitor-enter(r3)
|
|
java.util.List<java.lang.Runnable> r1 = r3.pendingCalls // Catch: java.lang.Throwable -> L3b
|
|
boolean r1 = r1.isEmpty() // Catch: java.lang.Throwable -> L3b
|
|
if (r1 == 0) goto L1d
|
|
r0 = 0
|
|
r3.pendingCalls = r0 // Catch: java.lang.Throwable -> L3b
|
|
r0 = 1
|
|
r3.passThrough = r0 // Catch: java.lang.Throwable -> L3b
|
|
io.grpc.internal.DelayedStream$DelayedStreamListener r0 = r3.delayedListener // Catch: java.lang.Throwable -> L3b
|
|
monitor-exit(r3)
|
|
if (r0 == 0) goto L1c
|
|
r0.drainPendingCallbacks()
|
|
L1c:
|
|
return
|
|
L1d:
|
|
java.util.List<java.lang.Runnable> r1 = r3.pendingCalls // Catch: java.lang.Throwable -> L3b
|
|
r3.pendingCalls = r0 // Catch: java.lang.Throwable -> L3b
|
|
monitor-exit(r3)
|
|
java.util.Iterator r0 = r1.iterator()
|
|
L26:
|
|
boolean r2 = r0.hasNext()
|
|
if (r2 == 0) goto L36
|
|
java.lang.Object r2 = r0.next()
|
|
java.lang.Runnable r2 = (java.lang.Runnable) r2
|
|
r2.run()
|
|
goto L26
|
|
L36:
|
|
r1.clear()
|
|
r0 = r1
|
|
goto L5
|
|
L3b:
|
|
r0 = move-exception
|
|
monitor-exit(r3)
|
|
throw r0
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: io.grpc.internal.DelayedStream.drainPendingCalls():void");
|
|
}
|
|
|
|
private void delayOrExecute(Runnable runnable) {
|
|
Preconditions.checkState(this.listener != null, "May only be called after start");
|
|
synchronized (this) {
|
|
if (!this.passThrough) {
|
|
this.pendingCalls.add(runnable);
|
|
} else {
|
|
runnable.run();
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStream
|
|
public void setAuthority(String str) {
|
|
Preconditions.checkState(this.listener == null, "May only be called before start");
|
|
Preconditions.checkNotNull(str, "authority");
|
|
this.preStartPendingCalls.add(new Runnable(this, str) { // from class: io.grpc.internal.DelayedStream.5
|
|
final DelayedStream this$0;
|
|
final String val$authority;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$authority = str;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.setAuthority(this.val$authority);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStream
|
|
public void start(ClientStreamListener clientStreamListener) {
|
|
Status status;
|
|
boolean z;
|
|
Preconditions.checkNotNull(clientStreamListener, ServiceSpecificExtraArgs.CastExtraArgs.LISTENER);
|
|
Preconditions.checkState(this.listener == null, "already started");
|
|
synchronized (this) {
|
|
status = this.error;
|
|
z = this.passThrough;
|
|
if (!z) {
|
|
DelayedStreamListener delayedStreamListener = new DelayedStreamListener(clientStreamListener);
|
|
this.delayedListener = delayedStreamListener;
|
|
clientStreamListener = delayedStreamListener;
|
|
}
|
|
this.listener = clientStreamListener;
|
|
this.startTimeNanos = System.nanoTime();
|
|
}
|
|
if (status != null) {
|
|
clientStreamListener.closed(status, ClientStreamListener.RpcProgress.PROCESSED, new Metadata());
|
|
} else if (z) {
|
|
internalStart(clientStreamListener);
|
|
}
|
|
}
|
|
|
|
private void internalStart(ClientStreamListener clientStreamListener) {
|
|
Iterator<Runnable> it = this.preStartPendingCalls.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().run();
|
|
}
|
|
this.preStartPendingCalls = null;
|
|
this.realStream.start(clientStreamListener);
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStream
|
|
public Attributes getAttributes() {
|
|
ClientStream clientStream;
|
|
synchronized (this) {
|
|
clientStream = this.realStream;
|
|
}
|
|
if (clientStream != null) {
|
|
return clientStream.getAttributes();
|
|
}
|
|
return Attributes.EMPTY;
|
|
}
|
|
|
|
@Override // io.grpc.internal.Stream
|
|
public void writeMessage(InputStream inputStream) {
|
|
Preconditions.checkState(this.listener != null, "May only be called after start");
|
|
Preconditions.checkNotNull(inputStream, "message");
|
|
if (this.passThrough) {
|
|
this.realStream.writeMessage(inputStream);
|
|
} else {
|
|
delayOrExecute(new Runnable(this, inputStream) { // from class: io.grpc.internal.DelayedStream.6
|
|
final DelayedStream this$0;
|
|
final InputStream val$message;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$message = inputStream;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.writeMessage(this.val$message);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // io.grpc.internal.Stream
|
|
public void flush() {
|
|
Preconditions.checkState(this.listener != null, "May only be called after start");
|
|
if (this.passThrough) {
|
|
this.realStream.flush();
|
|
} else {
|
|
delayOrExecute(new Runnable(this) { // from class: io.grpc.internal.DelayedStream.7
|
|
final DelayedStream this$0;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.flush();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStream
|
|
public void cancel(Status status) {
|
|
boolean z = false;
|
|
Preconditions.checkState(this.listener != null, "May only be called after start");
|
|
Preconditions.checkNotNull(status, "reason");
|
|
synchronized (this) {
|
|
if (this.realStream == null) {
|
|
setRealStream(NoopClientStream.INSTANCE);
|
|
this.error = status;
|
|
} else {
|
|
z = true;
|
|
}
|
|
}
|
|
if (z) {
|
|
delayOrExecute(new Runnable(this, status) { // from class: io.grpc.internal.DelayedStream.8
|
|
final DelayedStream this$0;
|
|
final Status val$reason;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$reason = status;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.cancel(this.val$reason);
|
|
}
|
|
});
|
|
return;
|
|
}
|
|
drainPendingCalls();
|
|
onEarlyCancellation(status);
|
|
this.listener.closed(status, ClientStreamListener.RpcProgress.PROCESSED, new Metadata());
|
|
}
|
|
|
|
private void setRealStream(ClientStream clientStream) {
|
|
ClientStream clientStream2 = this.realStream;
|
|
Preconditions.checkState(clientStream2 == null, "realStream already set to %s", clientStream2);
|
|
this.realStream = clientStream;
|
|
this.streamSetTimeNanos = System.nanoTime();
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStream
|
|
public void halfClose() {
|
|
Preconditions.checkState(this.listener != null, "May only be called after start");
|
|
delayOrExecute(new Runnable(this) { // from class: io.grpc.internal.DelayedStream.9
|
|
final DelayedStream this$0;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.halfClose();
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // io.grpc.internal.Stream
|
|
public void request(int i) {
|
|
Preconditions.checkState(this.listener != null, "May only be called after start");
|
|
if (this.passThrough) {
|
|
this.realStream.request(i);
|
|
} else {
|
|
delayOrExecute(new Runnable(this, i) { // from class: io.grpc.internal.DelayedStream.10
|
|
final DelayedStream this$0;
|
|
final int val$numMessages;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$numMessages = i;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.request(this.val$numMessages);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // io.grpc.internal.Stream
|
|
public void optimizeForDirectExecutor() {
|
|
Preconditions.checkState(this.listener == null, "May only be called before start");
|
|
this.preStartPendingCalls.add(new Runnable(this) { // from class: io.grpc.internal.DelayedStream.11
|
|
final DelayedStream this$0;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.optimizeForDirectExecutor();
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // io.grpc.internal.Stream
|
|
public void setCompressor(Compressor compressor) {
|
|
Preconditions.checkState(this.listener == null, "May only be called before start");
|
|
Preconditions.checkNotNull(compressor, "compressor");
|
|
this.preStartPendingCalls.add(new Runnable(this, compressor) { // from class: io.grpc.internal.DelayedStream.12
|
|
final DelayedStream this$0;
|
|
final Compressor val$compressor;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$compressor = compressor;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.setCompressor(this.val$compressor);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStream
|
|
public void setFullStreamDecompression(boolean z) {
|
|
Preconditions.checkState(this.listener == null, "May only be called before start");
|
|
this.preStartPendingCalls.add(new Runnable(this, z) { // from class: io.grpc.internal.DelayedStream.13
|
|
final DelayedStream this$0;
|
|
final boolean val$fullStreamDecompression;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$fullStreamDecompression = z;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.setFullStreamDecompression(this.val$fullStreamDecompression);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStream
|
|
public void setDecompressorRegistry(DecompressorRegistry decompressorRegistry) {
|
|
Preconditions.checkState(this.listener == null, "May only be called before start");
|
|
Preconditions.checkNotNull(decompressorRegistry, "decompressorRegistry");
|
|
this.preStartPendingCalls.add(new Runnable(this, decompressorRegistry) { // from class: io.grpc.internal.DelayedStream.14
|
|
final DelayedStream this$0;
|
|
final DecompressorRegistry val$decompressorRegistry;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$decompressorRegistry = decompressorRegistry;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.setDecompressorRegistry(this.val$decompressorRegistry);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // io.grpc.internal.Stream
|
|
public boolean isReady() {
|
|
if (this.passThrough) {
|
|
return this.realStream.isReady();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // io.grpc.internal.Stream
|
|
public void setMessageCompression(boolean z) {
|
|
Preconditions.checkState(this.listener != null, "May only be called after start");
|
|
if (this.passThrough) {
|
|
this.realStream.setMessageCompression(z);
|
|
} else {
|
|
delayOrExecute(new Runnable(this, z) { // from class: io.grpc.internal.DelayedStream.15
|
|
final DelayedStream this$0;
|
|
final boolean val$enable;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$enable = z;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realStream.setMessageCompression(this.val$enable);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes6.dex */
|
|
public static class DelayedStreamListener implements ClientStreamListener {
|
|
static final boolean $assertionsDisabled = false;
|
|
private volatile boolean passThrough;
|
|
private List<Runnable> pendingCallbacks = new ArrayList();
|
|
private final ClientStreamListener realListener;
|
|
|
|
public DelayedStreamListener(ClientStreamListener clientStreamListener) {
|
|
this.realListener = clientStreamListener;
|
|
}
|
|
|
|
private void delayOrExecute(Runnable runnable) {
|
|
synchronized (this) {
|
|
if (!this.passThrough) {
|
|
this.pendingCallbacks.add(runnable);
|
|
} else {
|
|
runnable.run();
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // io.grpc.internal.StreamListener
|
|
public void messagesAvailable(StreamListener.MessageProducer messageProducer) {
|
|
if (this.passThrough) {
|
|
this.realListener.messagesAvailable(messageProducer);
|
|
} else {
|
|
delayOrExecute(new Runnable(this, messageProducer) { // from class: io.grpc.internal.DelayedStream.DelayedStreamListener.1
|
|
final DelayedStreamListener this$0;
|
|
final StreamListener.MessageProducer val$producer;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$producer = messageProducer;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realListener.messagesAvailable(this.val$producer);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // io.grpc.internal.StreamListener
|
|
public void onReady() {
|
|
if (this.passThrough) {
|
|
this.realListener.onReady();
|
|
} else {
|
|
delayOrExecute(new Runnable(this) { // from class: io.grpc.internal.DelayedStream.DelayedStreamListener.2
|
|
final DelayedStreamListener this$0;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realListener.onReady();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStreamListener
|
|
public void headersRead(Metadata metadata) {
|
|
delayOrExecute(new Runnable(this, metadata) { // from class: io.grpc.internal.DelayedStream.DelayedStreamListener.3
|
|
final DelayedStreamListener this$0;
|
|
final Metadata val$headers;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$headers = metadata;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realListener.headersRead(this.val$headers);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override // io.grpc.internal.ClientStreamListener
|
|
public void closed(Status status, ClientStreamListener.RpcProgress rpcProgress, Metadata metadata) {
|
|
delayOrExecute(new Runnable(this, status, rpcProgress, metadata) { // from class: io.grpc.internal.DelayedStream.DelayedStreamListener.4
|
|
final DelayedStreamListener this$0;
|
|
final ClientStreamListener.RpcProgress val$rpcProgress;
|
|
final Status val$status;
|
|
final Metadata val$trailers;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$status = status;
|
|
this.val$rpcProgress = rpcProgress;
|
|
this.val$trailers = metadata;
|
|
}
|
|
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
this.this$0.realListener.closed(this.val$status, this.val$rpcProgress, this.val$trailers);
|
|
}
|
|
});
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public void drainPendingCallbacks() {
|
|
List list;
|
|
List arrayList = new ArrayList();
|
|
while (true) {
|
|
synchronized (this) {
|
|
if (this.pendingCallbacks.isEmpty()) {
|
|
this.pendingCallbacks = null;
|
|
this.passThrough = true;
|
|
return;
|
|
} else {
|
|
list = this.pendingCallbacks;
|
|
this.pendingCallbacks = arrayList;
|
|
}
|
|
}
|
|
Iterator it = list.iterator();
|
|
while (it.hasNext()) {
|
|
((Runnable) it.next()).run();
|
|
}
|
|
list.clear();
|
|
arrayList = list;
|
|
}
|
|
}
|
|
}
|
|
|
|
ClientStream getRealStream() {
|
|
return this.realStream;
|
|
}
|
|
}
|