MCPcopy Create free account
hub / github.com/grpc/grpc-java / ServerImpl

Class ServerImpl

core/src/main/java/io/grpc/internal/ServerImpl.java:94–980  ·  view source on GitHub ↗

Default implementation of io.grpc.Server, for creation by transports. Expected usage (by a theoretical TCP transport): public class TcpTransportServerFactory { public static Server newServer(Executor executor, HandlerRegistry registry, String configuration) { retur

Source from the content-addressed store, hash-verified

92 * server stops servicing new requests and waits for all connections to terminate.
93 */
94public final class ServerImpl extends io.grpc.Server implements InternalInstrumented<ServerStats> {
95 private static final Logger log = Logger.getLogger(ServerImpl.class.getName());
96 private static final ServerStreamListener NOOP_LISTENER = new NoopListener();
97
98 private final InternalLogId logId;
99 private final ObjectPool<? extends Executor> executorPool;
100 /** Executor for application processing. Safe to read after {@link #start()}. */
101 private Executor executor;
102 private final InternalHandlerRegistry registry;
103 private final HandlerRegistry fallbackRegistry;
104 private final List<ServerTransportFilter> transportFilters;
105 // This is iterated on a per-call basis. Use an array instead of a Collection to avoid iterator
106 // creations.
107 private final ServerInterceptor[] interceptors;
108 private final long handshakeTimeoutMillis;
109 @GuardedBy("lock") private boolean started;
110 @GuardedBy("lock") private boolean shutdown;
111 /** non-{@code null} if immediate shutdown has been requested. */
112 @GuardedBy("lock") private Status shutdownNowStatus;
113 /** {@code true} if ServerListenerImpl.serverShutdown() was called. */
114 @GuardedBy("lock") private boolean serverShutdownCallbackInvoked;
115 @GuardedBy("lock") private boolean terminated;
116 /** Service encapsulating something similar to an accept() socket. */
117 private final InternalServer transportServer;
118 private final Object lock = new Object();
119 @GuardedBy("lock") private boolean transportServersTerminated;
120 /** {@code transportServer} and services encapsulating something similar to a TCP connection. */
121 @GuardedBy("lock") private final Set<ServerTransport> transports = new HashSet<>();
122
123 private final Context rootContext;
124
125 private final DecompressorRegistry decompressorRegistry;
126 private final CompressorRegistry compressorRegistry;
127 private final BinaryLog binlog;
128
129 private final InternalChannelz channelz;
130 private final CallTracer serverCallTracer;
131 private final Deadline.Ticker ticker;
132 private final ServerCallExecutorSupplier executorSupplier;
133
134 /**
135 * Construct a server.
136 *
137 * @param builder builder with configuration for server
138 * @param transportServer transport servers that will create new incoming transports
139 * @param rootContext context that callbacks for new RPCs should be derived from
140 */
141 ServerImpl(
142 ServerImplBuilder builder,
143 InternalServer transportServer,
144 Context rootContext) {
145 this.executorPool = Preconditions.checkNotNull(builder.executorPool, "executorPool");
146 this.registry = Preconditions.checkNotNull(builder.registryBuilder.build(), "registryBuilder");
147 this.fallbackRegistry =
148 Preconditions.checkNotNull(builder.fallbackRegistry, "fallbackRegistry");
149 this.transportServer = Preconditions.checkNotNull(transportServer, "transportServer");
150 this.logId =
151 InternalLogId.allocate("Server", String.valueOf(getListenSocketsIgnoringLifecycle()));

Callers

nothing calls this directly

Calls 1

getNameMethod · 0.65

Tested by

no test coverage detected