Skip to content

Commit 58bb66e

Browse files
committed
Inline AbstractServerImplBuilder: the rest and properties
1 parent 9cc30fd commit 58bb66e

File tree

2 files changed

+70
-99
lines changed

2 files changed

+70
-99
lines changed

core/src/main/java/io/grpc/internal/AbstractServerImplBuilder.java

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,7 @@
1616

1717
package io.grpc.internal;
1818

19-
import io.grpc.BinaryLog;
20-
import io.grpc.CompressorRegistry;
21-
import io.grpc.Deadline;
22-
import io.grpc.DecompressorRegistry;
23-
import io.grpc.HandlerRegistry;
2419
import io.grpc.ServerBuilder;
25-
import io.grpc.ServerInterceptor;
26-
import io.grpc.ServerMethodDefinition;
27-
import io.grpc.ServerServiceDefinition;
28-
import io.grpc.ServerStreamTracer;
29-
import io.grpc.ServerTransportFilter;
30-
import java.util.ArrayList;
31-
import java.util.Collections;
32-
import java.util.List;
33-
import java.util.concurrent.Executor;
34-
import java.util.concurrent.TimeUnit;
35-
import javax.annotation.Nullable;
3620

3721
/**
3822
* The base class for server builders.
@@ -45,70 +29,4 @@ public abstract class AbstractServerImplBuilder<T extends AbstractServerImplBuil
4529
public static ServerBuilder<?> forPort(int port) {
4630
throw new UnsupportedOperationException("Subclass failed to hide static factory");
4731
}
48-
49-
// defaults
50-
protected static final ObjectPool<? extends Executor> DEFAULT_EXECUTOR_POOL =
51-
SharedResourcePool.forResource(GrpcUtil.SHARED_CHANNEL_EXECUTOR);
52-
protected static final HandlerRegistry DEFAULT_FALLBACK_REGISTRY = new DefaultFallbackRegistry();
53-
protected static final DecompressorRegistry DEFAULT_DECOMPRESSOR_REGISTRY =
54-
DecompressorRegistry.getDefaultInstance();
55-
protected static final CompressorRegistry DEFAULT_COMPRESSOR_REGISTRY =
56-
CompressorRegistry.getDefaultInstance();
57-
protected static final long DEFAULT_HANDSHAKE_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(120);
58-
59-
// mutable state
60-
final InternalHandlerRegistry.Builder registryBuilder =
61-
new InternalHandlerRegistry.Builder();
62-
final List<ServerTransportFilter> transportFilters = new ArrayList<>();
63-
final List<ServerInterceptor> interceptors = new ArrayList<>();
64-
protected final List<ServerStreamTracer.Factory> streamTracerFactories = new ArrayList<>();
65-
HandlerRegistry fallbackRegistry = DEFAULT_FALLBACK_REGISTRY;
66-
ObjectPool<? extends Executor> executorPool = DEFAULT_EXECUTOR_POOL;
67-
DecompressorRegistry decompressorRegistry = DEFAULT_DECOMPRESSOR_REGISTRY;
68-
CompressorRegistry compressorRegistry = DEFAULT_COMPRESSOR_REGISTRY;
69-
long handshakeTimeoutMillis = DEFAULT_HANDSHAKE_TIMEOUT_MILLIS;
70-
Deadline.Ticker ticker = Deadline.getSystemTicker();
71-
protected boolean statsEnabled = true;
72-
protected boolean recordStartedRpcs = true;
73-
protected boolean recordFinishedRpcs = true;
74-
protected boolean recordRealTimeMetrics = false;
75-
protected boolean tracingEnabled = true;
76-
@Nullable BinaryLog binlog;
77-
TransportTracer.Factory transportTracerFactory = TransportTracer.getDefaultFactory();
78-
CallTracer.Factory callTracerFactory = CallTracer.getDefaultFactory();
79-
80-
protected final TransportTracer.Factory getTransportTracerFactory() {
81-
return transportTracerFactory;
82-
}
83-
84-
/**
85-
* Children of AbstractServerBuilder should override this method to provide transport specific
86-
* information for the server. This method is mean for Transport implementors and should not be
87-
* used by normal users.
88-
*
89-
* @param streamTracerFactories an immutable list of stream tracer factories
90-
*/
91-
protected abstract List<? extends io.grpc.internal.InternalServer> buildTransportServers(
92-
List<? extends ServerStreamTracer.Factory> streamTracerFactories);
93-
94-
private static final class DefaultFallbackRegistry extends HandlerRegistry {
95-
@Override
96-
public List<ServerServiceDefinition> getServices() {
97-
return Collections.emptyList();
98-
}
99-
100-
@Nullable
101-
@Override
102-
public ServerMethodDefinition<?, ?> lookupMethod(
103-
String methodName, @Nullable String authority) {
104-
return null;
105-
}
106-
}
107-
108-
/**
109-
* Returns the internal ExecutorPool for offloading tasks.
110-
*/
111-
protected ObjectPool<? extends Executor> getExecutorPool() {
112-
return this.executorPool;
113-
}
11432
}

core/src/main/java/io/grpc/internal/ServerImplBuilder.java

Lines changed: 70 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import io.grpc.Server;
3131
import io.grpc.ServerBuilder;
3232
import io.grpc.ServerInterceptor;
33+
import io.grpc.ServerMethodDefinition;
3334
import io.grpc.ServerServiceDefinition;
3435
import io.grpc.ServerStreamTracer;
3536
import io.grpc.ServerTransportFilter;
@@ -52,7 +53,42 @@ public final class ServerImplBuilder extends AbstractServerImplBuilder<ServerImp
5253

5354
private static final Logger log = Logger.getLogger(ServerImplBuilder.class.getName());
5455

56+
public static ServerBuilder<?> forPort(int port) {
57+
throw new UnsupportedOperationException(
58+
"ClientTransportServersBuilder is required, use a constructor");
59+
}
60+
61+
// defaults
62+
private static final ObjectPool<? extends Executor> DEFAULT_EXECUTOR_POOL =
63+
SharedResourcePool.forResource(GrpcUtil.SHARED_CHANNEL_EXECUTOR);
64+
private static final HandlerRegistry DEFAULT_FALLBACK_REGISTRY = new DefaultFallbackRegistry();
65+
private static final DecompressorRegistry DEFAULT_DECOMPRESSOR_REGISTRY =
66+
DecompressorRegistry.getDefaultInstance();
67+
private static final CompressorRegistry DEFAULT_COMPRESSOR_REGISTRY =
68+
CompressorRegistry.getDefaultInstance();
69+
private static final long DEFAULT_HANDSHAKE_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(120);
70+
71+
// mutable state
72+
final InternalHandlerRegistry.Builder registryBuilder =
73+
new InternalHandlerRegistry.Builder();
74+
final List<ServerTransportFilter> transportFilters = new ArrayList<>();
75+
final List<ServerInterceptor> interceptors = new ArrayList<>();
76+
private final List<ServerStreamTracer.Factory> streamTracerFactories = new ArrayList<>();
77+
HandlerRegistry fallbackRegistry = DEFAULT_FALLBACK_REGISTRY;
78+
ObjectPool<? extends Executor> executorPool = DEFAULT_EXECUTOR_POOL;
79+
DecompressorRegistry decompressorRegistry = DEFAULT_DECOMPRESSOR_REGISTRY;
80+
CompressorRegistry compressorRegistry = DEFAULT_COMPRESSOR_REGISTRY;
81+
long handshakeTimeoutMillis = DEFAULT_HANDSHAKE_TIMEOUT_MILLIS;
82+
Deadline.Ticker ticker = Deadline.getSystemTicker();
83+
private boolean statsEnabled = true;
84+
private boolean recordStartedRpcs = true;
85+
private boolean recordFinishedRpcs = true;
86+
private boolean recordRealTimeMetrics = false;
87+
private boolean tracingEnabled = true;
88+
@Nullable BinaryLog binlog;
89+
TransportTracer.Factory transportTracerFactory = TransportTracer.getDefaultFactory();
5590
InternalChannelz channelz = InternalChannelz.instance();
91+
CallTracer.Factory callTracerFactory = CallTracer.getDefaultFactory();
5692

5793
private final ClientTransportServersBuilder clientTransportServersBuilder;
5894

@@ -74,14 +110,8 @@ public ServerImplBuilder(ClientTransportServersBuilder clientTransportServersBui
74110
}
75111

76112
@Override
77-
public Server build() {
78-
return new ServerImpl(this, buildTransportServers(getTracerFactories()), Context.ROOT);
79-
}
80-
81-
@Override
82-
protected List<? extends InternalServer> buildTransportServers(
83-
List<? extends ServerStreamTracer.Factory> streamTracerFactories) {
84-
return clientTransportServersBuilder.buildClientTransportServers(streamTracerFactories);
113+
public ServerImplBuilder useTransportSecurity(File certChain, File privateKey) {
114+
throw new UnsupportedOperationException("TLS not supported in ServerImplBuilder");
85115
}
86116

87117
@Override
@@ -208,6 +238,11 @@ public void setDeadlineTicker(Deadline.Ticker ticker) {
208238
this.ticker = Preconditions.checkNotNull(ticker, "ticker");
209239
}
210240

241+
@Override
242+
public Server build() {
243+
return new ServerImpl(this, buildTransportServers(getTracerFactories()), Context.ROOT);
244+
}
245+
211246
@VisibleForTesting
212247
List<? extends ServerStreamTracer.Factory> getTracerFactories() {
213248
ArrayList<ServerStreamTracer.Factory> tracerFactories = new ArrayList<>();
@@ -275,18 +310,36 @@ public InternalChannelz getChannelz() {
275310
return channelz;
276311
}
277312

278-
@Override
279-
public ObjectPool<? extends Executor> getExecutorPool() {
280-
return super.getExecutorPool();
313+
/**
314+
* Transport implementors must implement {@link ClientTransportServersBuilder} to transport
315+
* specific information for the server. This method is mean for Transport implementors and should
316+
* not be used by normal users.
317+
*
318+
* @param streamTracerFactories an immutable list of stream tracer factories
319+
*/
320+
List<? extends InternalServer> buildTransportServers(
321+
List<? extends ServerStreamTracer.Factory> streamTracerFactories) {
322+
return clientTransportServersBuilder.buildClientTransportServers(streamTracerFactories);
281323
}
282324

283-
@Override
284-
public ServerImplBuilder useTransportSecurity(File certChain, File privateKey) {
285-
throw new UnsupportedOperationException("TLS not supported in ServerImplBuilder");
325+
private static final class DefaultFallbackRegistry extends HandlerRegistry {
326+
@Override
327+
public List<ServerServiceDefinition> getServices() {
328+
return Collections.emptyList();
329+
}
330+
331+
@Nullable
332+
@Override
333+
public ServerMethodDefinition<?, ?> lookupMethod(
334+
String methodName, @Nullable String authority) {
335+
return null;
336+
}
286337
}
287338

288-
public static ServerBuilder<?> forPort(int port) {
289-
throw new UnsupportedOperationException(
290-
"ClientTransportServersBuilder is required, use a constructor");
339+
/**
340+
* Returns the internal ExecutorPool for offloading tasks.
341+
*/
342+
public ObjectPool<? extends Executor> getExecutorPool() {
343+
return this.executorPool;
291344
}
292345
}

0 commit comments

Comments
 (0)