package io.grpc.inprocess; import com.google.common.base.MoreObjects; import com.google.common.base.Preconditions; import io.grpc.InternalChannelz; import io.grpc.InternalInstrumented; import io.grpc.ServerStreamTracer; import io.grpc.internal.InternalServer; import io.grpc.internal.ObjectPool; import io.grpc.internal.ServerListener; import io.grpc.internal.ServerTransportListener; import java.io.IOException; import java.net.SocketAddress; import java.util.Collections; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ScheduledExecutorService; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public final class InProcessServer implements InternalServer { private static final ConcurrentMap registry = new ConcurrentHashMap(); private final SocketAddress listenAddress; private ServerListener listener; private final int maxInboundMetadataSize; private ScheduledExecutorService scheduler; private final ObjectPool schedulerPool; private boolean shutdown; private final List streamTracerFactories; @Override // io.grpc.internal.InternalServer public final InternalInstrumented getListenSocketStats() { return null; } @Override // io.grpc.internal.InternalServer public final List> getListenSocketStatsList() { return null; } /* JADX INFO: Access modifiers changed from: package-private */ public static InProcessServer findServer(SocketAddress socketAddress) { if (socketAddress instanceof AnonymousInProcessSocketAddress) { return ((AnonymousInProcessSocketAddress) socketAddress).getServer(); } if (socketAddress instanceof InProcessSocketAddress) { return registry.get(((InProcessSocketAddress) socketAddress).getName()); } return null; } /* JADX INFO: Access modifiers changed from: package-private */ public InProcessServer(InProcessServerBuilder inProcessServerBuilder, List list) { this.listenAddress = inProcessServerBuilder.listenAddress; this.schedulerPool = inProcessServerBuilder.schedulerPool; this.maxInboundMetadataSize = inProcessServerBuilder.maxInboundMetadataSize; this.streamTracerFactories = Collections.unmodifiableList((List) Preconditions.checkNotNull(list, "streamTracerFactories")); } @Override // io.grpc.internal.InternalServer public final void start(ServerListener serverListener) throws IOException { this.listener = serverListener; this.scheduler = this.schedulerPool.getObject(); registerInstance(); } private void registerInstance() throws IOException { SocketAddress socketAddress = this.listenAddress; if (socketAddress instanceof AnonymousInProcessSocketAddress) { ((AnonymousInProcessSocketAddress) socketAddress).setServer(this); } else { if (socketAddress instanceof InProcessSocketAddress) { String name = ((InProcessSocketAddress) socketAddress).getName(); if (registry.putIfAbsent(name, this) != null) { throw new IOException("name already registered: ".concat(String.valueOf(name))); } return; } throw new AssertionError(); } } @Override // io.grpc.internal.InternalServer public final List getListenSocketAddresses() { return Collections.singletonList(getListenSocketAddress()); } @Override // io.grpc.internal.InternalServer public final void shutdown() { unregisterInstance(); this.scheduler = this.schedulerPool.returnObject(this.scheduler); synchronized (this) { this.shutdown = true; this.listener.serverShutdown(); } } private void unregisterInstance() { SocketAddress socketAddress = this.listenAddress; if (socketAddress instanceof AnonymousInProcessSocketAddress) { ((AnonymousInProcessSocketAddress) socketAddress).clearServer(this); } else { if (socketAddress instanceof InProcessSocketAddress) { if (!registry.remove(((InProcessSocketAddress) socketAddress).getName(), this)) { throw new AssertionError(); } return; } throw new AssertionError(); } } public final String toString() { return MoreObjects.toStringHelper(this).add("listenAddress", this.listenAddress).toString(); } /* JADX INFO: Access modifiers changed from: package-private */ public final ServerTransportListener register(InProcessTransport inProcessTransport) { synchronized (this) { if (this.shutdown) { return null; } return this.listener.transportCreated(inProcessTransport); } } /* JADX INFO: Access modifiers changed from: package-private */ public final List getStreamTracerFactories() { return this.streamTracerFactories; } /* JADX INFO: Access modifiers changed from: package-private */ public final ObjectPool getScheduledExecutorServicePool() { return this.schedulerPool; } /* JADX INFO: Access modifiers changed from: package-private */ public final int getMaxInboundMetadataSize() { return this.maxInboundMetadataSize; } @Override // io.grpc.internal.InternalServer public final SocketAddress getListenSocketAddress() { return this.listenAddress; } }