package io.grpc.internal; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import com.google.common.net.HttpHeaders; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.SettableFuture; import io.grpc.Attributes; import io.grpc.BinaryLog; import io.grpc.CompressorRegistry; import io.grpc.Context; import io.grpc.Contexts; import io.grpc.Deadline; import io.grpc.Decompressor; import io.grpc.DecompressorRegistry; import io.grpc.HandlerRegistry; import io.grpc.InternalChannelz; import io.grpc.InternalInstrumented; import io.grpc.InternalLogId; import io.grpc.InternalServerInterceptors; import io.grpc.Metadata; import io.grpc.Server; import io.grpc.ServerCall; import io.grpc.ServerCallExecutorSupplier; import io.grpc.ServerCallHandler; import io.grpc.ServerInterceptor; import io.grpc.ServerMethodDefinition; import io.grpc.ServerServiceDefinition; import io.grpc.ServerTransportFilter; import io.grpc.Status; import io.grpc.internal.StreamListener; import java.io.IOException; import java.io.InputStream; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.Executor; import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; import java.util.logging.Level; import java.util.logging.Logger; import o.C13115fRJ; import o.C13116fRL; import o.fRN; /* loaded from: classes6.dex */ public final class ServerImpl extends Server implements InternalInstrumented { private final BinaryLog binlog; private final InternalChannelz channelz; private final CompressorRegistry compressorRegistry; private final DecompressorRegistry decompressorRegistry; private Executor executor; private final ObjectPool executorPool; private final ServerCallExecutorSupplier executorSupplier; private final HandlerRegistry fallbackRegistry; private final long handshakeTimeoutMillis; private final ServerInterceptor[] interceptors; private final HandlerRegistry registry; private final Context rootContext; private final CallTracer serverCallTracer; private boolean serverShutdownCallbackInvoked; private boolean shutdown; private Status shutdownNowStatus; private boolean started; private boolean terminated; private final Deadline.Ticker ticker; private final List transportFilters; private final InternalServer transportServer; private boolean transportServersTerminated; private static final Logger log = Logger.getLogger(ServerImpl.class.getName()); private static final ServerStreamListener NOOP_LISTENER = new NoopListener(); private final Object lock = new Object(); private final Set transports = new HashSet(); private final InternalLogId logId = InternalLogId.allocate(HttpHeaders.SERVER, String.valueOf(getListenSocketsIgnoringLifecycle())); /* JADX INFO: Access modifiers changed from: package-private */ public ServerImpl(ServerImplBuilder serverImplBuilder, InternalServer internalServer, Context context) { this.executorPool = (ObjectPool) Preconditions.checkNotNull(serverImplBuilder.executorPool, "executorPool"); this.registry = (HandlerRegistry) Preconditions.checkNotNull(serverImplBuilder.registryBuilder.build(), "registryBuilder"); this.fallbackRegistry = (HandlerRegistry) Preconditions.checkNotNull(serverImplBuilder.fallbackRegistry, "fallbackRegistry"); this.transportServer = (InternalServer) Preconditions.checkNotNull(internalServer, "transportServer"); this.rootContext = ((Context) Preconditions.checkNotNull(context, "rootContext")).fork(); this.decompressorRegistry = serverImplBuilder.decompressorRegistry; this.compressorRegistry = serverImplBuilder.compressorRegistry; this.transportFilters = Collections.unmodifiableList(new ArrayList(serverImplBuilder.transportFilters)); this.interceptors = (ServerInterceptor[]) serverImplBuilder.interceptors.toArray(new ServerInterceptor[serverImplBuilder.interceptors.size()]); this.handshakeTimeoutMillis = serverImplBuilder.handshakeTimeoutMillis; this.binlog = serverImplBuilder.binlog; InternalChannelz internalChannelz = serverImplBuilder.channelz; this.channelz = internalChannelz; this.serverCallTracer = serverImplBuilder.callTracerFactory.create(); this.ticker = (Deadline.Ticker) Preconditions.checkNotNull(serverImplBuilder.ticker, "ticker"); internalChannelz.addServer(this); this.executorSupplier = serverImplBuilder.executorSupplier; } @Override // io.grpc.Server public final ServerImpl start() throws IOException { synchronized (this.lock) { Preconditions.checkState(!this.started, "Already started"); Preconditions.checkState(!this.shutdown, "Shutting down"); this.transportServer.start(new ServerListenerImpl()); this.executor = (Executor) Preconditions.checkNotNull(this.executorPool.getObject(), "executor"); this.started = true; } return this; } @Override // io.grpc.Server public final int getPort() { synchronized (this.lock) { Preconditions.checkState(this.started, "Not started"); Preconditions.checkState(!this.terminated, "Already terminated"); for (SocketAddress socketAddress : this.transportServer.getListenSocketAddresses()) { if (socketAddress instanceof InetSocketAddress) { return ((InetSocketAddress) socketAddress).getPort(); } } return -1; } } @Override // io.grpc.Server public final List getListenSockets() { List listenSocketsIgnoringLifecycle; synchronized (this.lock) { Preconditions.checkState(this.started, "Not started"); Preconditions.checkState(!this.terminated, "Already terminated"); listenSocketsIgnoringLifecycle = getListenSocketsIgnoringLifecycle(); } return listenSocketsIgnoringLifecycle; } private List getListenSocketsIgnoringLifecycle() { List unmodifiableList; synchronized (this.lock) { unmodifiableList = Collections.unmodifiableList(this.transportServer.getListenSocketAddresses()); } return unmodifiableList; } @Override // io.grpc.Server public final List getServices() { List services = this.fallbackRegistry.getServices(); if (services.isEmpty()) { return this.registry.getServices(); } List services2 = this.registry.getServices(); ArrayList arrayList = new ArrayList(services2.size() + services.size()); arrayList.addAll(services2); arrayList.addAll(services); return Collections.unmodifiableList(arrayList); } @Override // io.grpc.Server public final List getImmutableServices() { return this.registry.getServices(); } @Override // io.grpc.Server public final List getMutableServices() { return Collections.unmodifiableList(this.fallbackRegistry.getServices()); } @Override // io.grpc.Server public final ServerImpl shutdown() { synchronized (this.lock) { if (this.shutdown) { return this; } this.shutdown = true; boolean z = this.started; if (!z) { this.transportServersTerminated = true; checkForTermination(); } if (z) { this.transportServer.shutdown(); } return this; } } @Override // io.grpc.Server public final ServerImpl shutdownNow() { shutdown(); Status withDescription = Status.UNAVAILABLE.withDescription("Server shutdownNow invoked"); synchronized (this.lock) { if (this.shutdownNowStatus != null) { return this; } this.shutdownNowStatus = withDescription; ArrayList arrayList = new ArrayList(this.transports); boolean z = this.serverShutdownCallbackInvoked; if (z) { Iterator it = arrayList.iterator(); while (it.hasNext()) { ((ServerTransport) it.next()).shutdownNow(withDescription); } } return this; } } @Override // io.grpc.Server public final boolean isShutdown() { boolean z; synchronized (this.lock) { z = this.shutdown; } return z; } @Override // io.grpc.Server public final boolean awaitTermination(long j, TimeUnit timeUnit) throws InterruptedException { boolean z; synchronized (this.lock) { long nanos = timeUnit.toNanos(j); long nanoTime = System.nanoTime(); while (!this.terminated) { long nanoTime2 = (nanoTime + nanos) - System.nanoTime(); if (nanoTime2 <= 0) { break; } TimeUnit.NANOSECONDS.timedWait(this.lock, nanoTime2); } z = this.terminated; } return z; } @Override // io.grpc.Server public final void awaitTermination() throws InterruptedException { synchronized (this.lock) { while (!this.terminated) { this.lock.wait(); } } } @Override // io.grpc.Server public final boolean isTerminated() { boolean z; synchronized (this.lock) { z = this.terminated; } return z; } /* JADX INFO: Access modifiers changed from: private */ public void transportClosed(ServerTransport serverTransport) { synchronized (this.lock) { if (!this.transports.remove(serverTransport)) { throw new AssertionError("Transport already removed"); } this.channelz.removeServerSocket(this, serverTransport); checkForTermination(); } } /* JADX INFO: Access modifiers changed from: private */ public void checkForTermination() { synchronized (this.lock) { if (this.shutdown && this.transports.isEmpty() && this.transportServersTerminated) { if (this.terminated) { throw new AssertionError("Server already terminated"); } this.terminated = true; this.channelz.removeServer(this); Executor executor = this.executor; if (executor != null) { this.executor = this.executorPool.returnObject(executor); } this.lock.notifyAll(); } } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public final class ServerListenerImpl implements ServerListener { final ServerImpl this$0; private ServerListenerImpl(ServerImpl serverImpl) { this.this$0 = serverImpl; } @Override // io.grpc.internal.ServerListener public final ServerTransportListener transportCreated(ServerTransport serverTransport) { synchronized (this.this$0.lock) { this.this$0.transports.add(serverTransport); } ServerTransportListenerImpl serverTransportListenerImpl = new ServerTransportListenerImpl(this.this$0, serverTransport); serverTransportListenerImpl.init(); return serverTransportListenerImpl; } @Override // io.grpc.internal.ServerListener public final void serverShutdown() { synchronized (this.this$0.lock) { if (this.this$0.serverShutdownCallbackInvoked) { return; } ArrayList arrayList = new ArrayList(this.this$0.transports); Status status = this.this$0.shutdownNowStatus; this.this$0.serverShutdownCallbackInvoked = true; Iterator it = arrayList.iterator(); while (it.hasNext()) { ServerTransport serverTransport = (ServerTransport) it.next(); if (status == null) { serverTransport.shutdown(); } else { serverTransport.shutdownNow(status); } } synchronized (this.this$0.lock) { this.this$0.transportServersTerminated = true; this.this$0.checkForTermination(); } } } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public final class ServerTransportListenerImpl implements ServerTransportListener { private Attributes attributes; private Future handshakeTimeoutFuture; final ServerImpl this$0; private final ServerTransport transport; ServerTransportListenerImpl(ServerImpl serverImpl, ServerTransport serverTransport) { this.this$0 = serverImpl; this.transport = serverTransport; } public final void init() { if (this.this$0.handshakeTimeoutMillis != Long.MAX_VALUE) { this.handshakeTimeoutFuture = this.transport.getScheduledExecutorService().schedule(new Runnable(this) { // from class: io.grpc.internal.ServerImpl.ServerTransportListenerImpl.1TransportShutdownNow final ServerTransportListenerImpl this$1; { this.this$1 = this; } @Override // java.lang.Runnable public void run() { this.this$1.transport.shutdownNow(Status.CANCELLED.withDescription("Handshake timeout exceeded")); } }, this.this$0.handshakeTimeoutMillis, TimeUnit.MILLISECONDS); } else { this.handshakeTimeoutFuture = new FutureTask(new Runnable(this) { // from class: io.grpc.internal.ServerImpl.ServerTransportListenerImpl.1 final ServerTransportListenerImpl this$1; @Override // java.lang.Runnable public void run() { } { this.this$1 = this; } }, null); } this.this$0.channelz.addServerSocket(this.this$0, this.transport); } @Override // io.grpc.internal.ServerTransportListener public final Attributes transportReady(Attributes attributes) { this.handshakeTimeoutFuture.cancel(false); this.handshakeTimeoutFuture = null; for (ServerTransportFilter serverTransportFilter : this.this$0.transportFilters) { attributes = (Attributes) Preconditions.checkNotNull(serverTransportFilter.transportReady(attributes), "Filter %s returned null", serverTransportFilter); } this.attributes = attributes; return attributes; } @Override // io.grpc.internal.ServerTransportListener public final void transportTerminated() { Future future = this.handshakeTimeoutFuture; if (future != null) { future.cancel(false); this.handshakeTimeoutFuture = null; } Iterator it = this.this$0.transportFilters.iterator(); while (it.hasNext()) { ((ServerTransportFilter) it.next()).transportTerminated(this.attributes); } this.this$0.transportClosed(this.transport); } @Override // io.grpc.internal.ServerTransportListener public final void streamCreated(ServerStream serverStream, String str, Metadata metadata) { serverStream.streamId(); fRN a = C13115fRJ.a(); C13115fRJ.g(); try { streamCreatedInternal(serverStream, str, metadata, a); } finally { C13115fRJ.i(); } } private void streamCreatedInternal(ServerStream serverStream, String str, Metadata metadata, fRN frn) { Executor serializingExecutor; if (this.this$0.executorSupplier != null || this.this$0.executor != MoreExecutors.directExecutor()) { serializingExecutor = new SerializingExecutor(this.this$0.executor); } else { serializingExecutor = new SerializeReentrantCallsDirectExecutor(); serverStream.optimizeForDirectExecutor(); } Executor executor = serializingExecutor; if (metadata.containsKey(GrpcUtil.MESSAGE_ENCODING_KEY)) { String str2 = (String) metadata.get(GrpcUtil.MESSAGE_ENCODING_KEY); Decompressor lookupDecompressor = this.this$0.decompressorRegistry.lookupDecompressor(str2); if (lookupDecompressor != null) { serverStream.setDecompressor(lookupDecompressor); } else { serverStream.setListener(ServerImpl.NOOP_LISTENER); serverStream.close(Status.UNIMPLEMENTED.withDescription(String.format("Can't find decompressor for %s", str2)), new Metadata()); return; } } StatsTraceContext statsTraceContext = (StatsTraceContext) Preconditions.checkNotNull(serverStream.statsTraceContext(), "statsTraceCtx not present from stream"); Context.CancellableContext createContext = createContext(metadata, statsTraceContext); C13116fRL h = C13115fRJ.h(); JumpToApplicationThreadServerStreamListener jumpToApplicationThreadServerStreamListener = new JumpToApplicationThreadServerStreamListener(executor, this.this$0.executor, serverStream, createContext, frn); serverStream.setListener(jumpToApplicationThreadServerStreamListener); SettableFuture create = SettableFuture.create(); executor.execute(new ContextRunnable(this, createContext, frn, h, str, serverStream, jumpToApplicationThreadServerStreamListener, create, statsTraceContext, metadata, executor) { // from class: io.grpc.internal.ServerImpl.ServerTransportListenerImpl.1MethodLookup final ServerTransportListenerImpl this$1; final Context.CancellableContext val$context; final SettableFuture val$future; final Metadata val$headers; final JumpToApplicationThreadServerStreamListener val$jumpListener; final C13116fRL val$link; final String val$methodName; final StatsTraceContext val$statsTraceCtx; final ServerStream val$stream; final fRN val$tag; final Executor val$wrappedExecutor; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ { super(createContext); this.this$1 = this; this.val$context = createContext; this.val$tag = frn; this.val$link = h; this.val$methodName = str; this.val$stream = serverStream; this.val$jumpListener = jumpToApplicationThreadServerStreamListener; this.val$future = create; this.val$statsTraceCtx = statsTraceContext; this.val$headers = metadata; this.val$wrappedExecutor = executor; } @Override // io.grpc.internal.ContextRunnable public final void runInContext() { C13115fRJ.g(); C13115fRJ.e(); try { runInternal(); } finally { C13115fRJ.i(); } } private void runInternal() { try { ServerMethodDefinition lookupMethod = this.this$1.this$0.registry.lookupMethod(this.val$methodName); if (lookupMethod == null) { lookupMethod = this.this$1.this$0.fallbackRegistry.lookupMethod(this.val$methodName, this.val$stream.getAuthority()); } if (lookupMethod == null) { Status status = Status.UNIMPLEMENTED; StringBuilder sb = new StringBuilder("Method not found: "); sb.append(this.val$methodName); Status withDescription = status.withDescription(sb.toString()); this.val$jumpListener.setListener(ServerImpl.NOOP_LISTENER); this.val$stream.close(withDescription, new Metadata()); this.val$context.cancel(null); this.val$future.cancel(false); return; } this.val$future.set(maySwitchExecutor(this.this$1.wrapMethod(this.val$stream, lookupMethod, this.val$statsTraceCtx), this.val$stream, this.val$headers, this.val$context, this.val$tag)); } catch (Throwable th) { this.val$jumpListener.setListener(ServerImpl.NOOP_LISTENER); this.val$stream.close(Status.fromThrowable(th), new Metadata()); this.val$context.cancel(null); this.val$future.cancel(false); throw th; } } private ServerCallParameters maySwitchExecutor(ServerMethodDefinition serverMethodDefinition, ServerStream serverStream2, Metadata metadata2, Context.CancellableContext cancellableContext, fRN frn2) { Executor executor2; ServerCallImpl serverCallImpl = new ServerCallImpl(serverStream2, serverMethodDefinition.getMethodDescriptor(), metadata2, cancellableContext, this.this$1.this$0.decompressorRegistry, this.this$1.this$0.compressorRegistry, this.this$1.this$0.serverCallTracer, frn2); if (this.this$1.this$0.executorSupplier != null && (executor2 = this.this$1.this$0.executorSupplier.getExecutor(serverCallImpl, metadata2)) != null) { ((SerializingExecutor) this.val$wrappedExecutor).setExecutor(executor2); } return new ServerCallParameters<>(this.this$1, serverCallImpl, serverMethodDefinition.getServerCallHandler()); } }); executor.execute(new C1HandleServerCall(this, createContext, frn, h, create, str, metadata, serverStream, jumpToApplicationThreadServerStreamListener)); } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: io.grpc.internal.ServerImpl$ServerTransportListenerImpl$1HandleServerCall, reason: invalid class name */ /* loaded from: classes6.dex */ public final class C1HandleServerCall extends ContextRunnable { final ServerTransportListenerImpl this$1; final Context.CancellableContext val$context; final SettableFuture val$future; final Metadata val$headers; final JumpToApplicationThreadServerStreamListener val$jumpListener; final C13116fRL val$link; final String val$methodName; final ServerStream val$stream; final fRN val$tag; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ C1HandleServerCall(ServerTransportListenerImpl serverTransportListenerImpl, Context.CancellableContext cancellableContext, fRN frn, C13116fRL c13116fRL, SettableFuture settableFuture, String str, Metadata metadata, ServerStream serverStream, JumpToApplicationThreadServerStreamListener jumpToApplicationThreadServerStreamListener) { super(cancellableContext); this.this$1 = serverTransportListenerImpl; this.val$context = cancellableContext; this.val$tag = frn; this.val$link = c13116fRL; this.val$future = settableFuture; this.val$methodName = str; this.val$headers = metadata; this.val$stream = serverStream; this.val$jumpListener = jumpToApplicationThreadServerStreamListener; } @Override // io.grpc.internal.ContextRunnable public final void runInContext() { C13115fRJ.g(); C13115fRJ.e(); try { runInternal(); } finally { C13115fRJ.i(); } } private void runInternal() { ServerStreamListener serverStreamListener = ServerImpl.NOOP_LISTENER; if (this.val$future.isCancelled()) { return; } try { this.val$jumpListener.setListener(this.this$1.startWrappedCall(this.val$methodName, (ServerCallParameters) Futures.getDone(this.val$future), this.val$headers)); this.val$context.addListener(new Context.CancellationListener(this) { // from class: io.grpc.internal.ServerImpl.ServerTransportListenerImpl.1HandleServerCall.1ServerStreamCancellationListener final C1HandleServerCall this$2; { this.this$2 = this; } @Override // io.grpc.Context.CancellationListener public final void cancelled(Context context) { Status statusFromCancelled = Contexts.statusFromCancelled(context); if (Status.DEADLINE_EXCEEDED.getCode().equals(statusFromCancelled.getCode())) { this.this$2.val$stream.cancel(statusFromCancelled); } } }, MoreExecutors.directExecutor()); } finally { } } } private Context.CancellableContext createContext(Metadata metadata, StatsTraceContext statsTraceContext) { Long l = (Long) metadata.get(GrpcUtil.TIMEOUT_KEY); Context withValue = statsTraceContext.serverFilterContext(this.this$0.rootContext).withValue(io.grpc.InternalServer.SERVER_CONTEXT_KEY, this.this$0); if (l == null) { return withValue.withCancellation(); } return withValue.withDeadline(Deadline.after(l.longValue(), TimeUnit.NANOSECONDS, this.this$0.ticker), this.transport.getScheduledExecutorService()); } /* JADX INFO: Access modifiers changed from: private */ public ServerMethodDefinition wrapMethod(ServerStream serverStream, ServerMethodDefinition serverMethodDefinition, StatsTraceContext statsTraceContext) { statsTraceContext.serverCallStarted(new ServerCallInfoImpl(serverMethodDefinition.getMethodDescriptor(), serverStream.getAttributes(), serverStream.getAuthority())); ServerCallHandler serverCallHandler = serverMethodDefinition.getServerCallHandler(); for (ServerInterceptor serverInterceptor : this.this$0.interceptors) { serverCallHandler = InternalServerInterceptors.interceptCallHandlerCreate(serverInterceptor, serverCallHandler); } ServerMethodDefinition withServerCallHandler = serverMethodDefinition.withServerCallHandler(serverCallHandler); return this.this$0.binlog != null ? this.this$0.binlog.wrapMethodDefinition(withServerCallHandler) : withServerCallHandler; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public final class ServerCallParameters { ServerCallImpl call; ServerCallHandler callHandler; final ServerTransportListenerImpl this$1; public ServerCallParameters(ServerTransportListenerImpl serverTransportListenerImpl, ServerCallImpl serverCallImpl, ServerCallHandler serverCallHandler) { this.this$1 = serverTransportListenerImpl; this.call = serverCallImpl; this.callHandler = serverCallHandler; } } /* JADX INFO: Access modifiers changed from: private */ public ServerStreamListener startWrappedCall(String str, ServerCallParameters serverCallParameters, Metadata metadata) { ServerCall.Listener startCall = serverCallParameters.callHandler.startCall(serverCallParameters.call, metadata); if (startCall == null) { throw new NullPointerException("startCall() returned a null listener for method ".concat(String.valueOf(str))); } return serverCallParameters.call.newServerStreamListener(startCall); } } @Override // io.grpc.InternalInstrumented public final ListenableFuture getStats() { InternalChannelz.ServerStats.Builder builder = new InternalChannelz.ServerStats.Builder(); List> listenSocketStatsList = this.transportServer.getListenSocketStatsList(); if (listenSocketStatsList != null) { builder.addListenSockets(listenSocketStatsList); } this.serverCallTracer.updateBuilder(builder); SettableFuture create = SettableFuture.create(); create.set(builder.build()); return create; } public final String toString() { return MoreObjects.toStringHelper(this).add("logId", this.logId.getId()).add("transportServer", this.transportServer).toString(); } /* loaded from: classes6.dex */ static final class NoopListener implements ServerStreamListener { @Override // io.grpc.internal.ServerStreamListener public final void closed(Status status) { } @Override // io.grpc.internal.ServerStreamListener public final void halfClosed() { } @Override // io.grpc.internal.StreamListener public final void onReady() { } private NoopListener() { } @Override // io.grpc.internal.StreamListener public final void messagesAvailable(StreamListener.MessageProducer messageProducer) { while (true) { InputStream next = messageProducer.next(); if (next == null) { return; } try { next.close(); } catch (IOException e) { while (true) { InputStream next2 = messageProducer.next(); if (next2 == null) { break; } try { next2.close(); } catch (IOException e2) { ServerImpl.log.log(Level.WARNING, "Exception closing stream", (Throwable) e2); } } throw new RuntimeException(e); } } } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static final class JumpToApplicationThreadServerStreamListener implements ServerStreamListener { private final Executor callExecutor; private final Executor cancelExecutor; private final Context.CancellableContext context; private ServerStreamListener listener; private final ServerStream stream; private final fRN tag; public JumpToApplicationThreadServerStreamListener(Executor executor, Executor executor2, ServerStream serverStream, Context.CancellableContext cancellableContext, fRN frn) { this.callExecutor = executor; this.cancelExecutor = executor2; this.stream = serverStream; this.context = cancellableContext; this.tag = frn; } /* JADX INFO: Access modifiers changed from: private */ public ServerStreamListener getListener() { ServerStreamListener serverStreamListener = this.listener; if (serverStreamListener != null) { return serverStreamListener; } throw new IllegalStateException("listener unset"); } final void setListener(ServerStreamListener serverStreamListener) { Preconditions.checkNotNull(serverStreamListener, "listener must not be null"); Preconditions.checkState(this.listener == null, "Listener already set"); this.listener = serverStreamListener; } /* JADX INFO: Access modifiers changed from: private */ public void internalClose(Throwable th) { this.stream.close(Status.UNKNOWN.withCause(th), new Metadata()); } @Override // io.grpc.internal.StreamListener public final void messagesAvailable(StreamListener.MessageProducer messageProducer) { C13115fRJ.g(); try { this.callExecutor.execute(new ContextRunnable(this, C13115fRJ.h(), messageProducer) { // from class: io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener.1MessagesAvailable final JumpToApplicationThreadServerStreamListener this$0; final C13116fRL val$link; final StreamListener.MessageProducer val$producer; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ { super(this.context); this.this$0 = this; this.val$link = r2; this.val$producer = messageProducer; } @Override // io.grpc.internal.ContextRunnable public final void runInContext() { fRN unused = this.this$0.tag; C13115fRJ.g(); C13115fRJ.e(); try { this.this$0.getListener().messagesAvailable(this.val$producer); } finally { } } }); } finally { C13115fRJ.i(); } } @Override // io.grpc.internal.ServerStreamListener public final void halfClosed() { C13115fRJ.g(); try { this.callExecutor.execute(new ContextRunnable(this, C13115fRJ.h()) { // from class: io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener.1HalfClosed final JumpToApplicationThreadServerStreamListener this$0; final C13116fRL val$link; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ { super(this.context); this.this$0 = this; this.val$link = r2; } @Override // io.grpc.internal.ContextRunnable public final void runInContext() { fRN unused = this.this$0.tag; C13115fRJ.g(); C13115fRJ.e(); try { this.this$0.getListener().halfClosed(); } finally { } } }); } finally { C13115fRJ.i(); } } @Override // io.grpc.internal.ServerStreamListener public final void closed(Status status) { C13115fRJ.g(); try { closedInternal(status); } finally { C13115fRJ.i(); } } private void closedInternal(Status status) { if (!status.isOk()) { this.cancelExecutor.execute(new ContextCloser(this.context, status.getCause())); } this.callExecutor.execute(new ContextRunnable(this, C13115fRJ.h(), status) { // from class: io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener.1Closed final JumpToApplicationThreadServerStreamListener this$0; final C13116fRL val$link; final Status val$status; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ { super(this.context); this.this$0 = this; this.val$link = r2; this.val$status = status; } @Override // io.grpc.internal.ContextRunnable public final void runInContext() { fRN unused = this.this$0.tag; C13115fRJ.g(); C13115fRJ.e(); try { this.this$0.getListener().closed(this.val$status); } finally { fRN unused2 = this.this$0.tag; C13115fRJ.i(); } } }); } @Override // io.grpc.internal.StreamListener public final void onReady() { C13115fRJ.g(); try { this.callExecutor.execute(new ContextRunnable(this, C13115fRJ.h()) { // from class: io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener.1OnReady final JumpToApplicationThreadServerStreamListener this$0; final C13116fRL val$link; /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */ { super(this.context); this.this$0 = this; this.val$link = r2; } @Override // io.grpc.internal.ContextRunnable public final void runInContext() { fRN unused = this.this$0.tag; C13115fRJ.g(); C13115fRJ.e(); try { this.this$0.getListener().onReady(); } finally { } } }); } finally { C13115fRJ.i(); } } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static final class ContextCloser implements Runnable { private final Throwable cause; private final Context.CancellableContext context; ContextCloser(Context.CancellableContext cancellableContext, Throwable th) { this.context = cancellableContext; this.cause = th; } @Override // java.lang.Runnable public final void run() { this.context.cancel(this.cause); } } @Override // io.grpc.InternalWithLogId public final InternalLogId getLogId() { return this.logId; } }