|
16 | 16 |
|
17 | 17 | package io.grpc.internal; |
18 | 18 |
|
19 | | -import static com.google.common.base.Preconditions.checkArgument; |
20 | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
21 | 20 |
|
22 | 21 | import com.google.common.annotations.VisibleForTesting; |
23 | | -import com.google.common.util.concurrent.MoreExecutors; |
24 | 22 | import io.grpc.BinaryLog; |
25 | | -import io.grpc.BindableService; |
26 | 23 | import io.grpc.CompressorRegistry; |
27 | 24 | import io.grpc.Deadline; |
28 | 25 | import io.grpc.DecompressorRegistry; |
@@ -60,114 +57,37 @@ public static ServerBuilder<?> forPort(int port) { |
60 | 57 | } |
61 | 58 |
|
62 | 59 | // defaults |
63 | | - private static final ObjectPool<? extends Executor> DEFAULT_EXECUTOR_POOL = |
| 60 | + protected static final ObjectPool<? extends Executor> DEFAULT_EXECUTOR_POOL = |
64 | 61 | SharedResourcePool.forResource(GrpcUtil.SHARED_CHANNEL_EXECUTOR); |
65 | | - private static final HandlerRegistry DEFAULT_FALLBACK_REGISTRY = new DefaultFallbackRegistry(); |
66 | | - private static final DecompressorRegistry DEFAULT_DECOMPRESSOR_REGISTRY = |
| 62 | + protected static final HandlerRegistry DEFAULT_FALLBACK_REGISTRY = new DefaultFallbackRegistry(); |
| 63 | + protected static final DecompressorRegistry DEFAULT_DECOMPRESSOR_REGISTRY = |
67 | 64 | DecompressorRegistry.getDefaultInstance(); |
68 | | - private static final CompressorRegistry DEFAULT_COMPRESSOR_REGISTRY = |
| 65 | + protected static final CompressorRegistry DEFAULT_COMPRESSOR_REGISTRY = |
69 | 66 | CompressorRegistry.getDefaultInstance(); |
70 | | - private static final long DEFAULT_HANDSHAKE_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(120); |
| 67 | + protected static final long DEFAULT_HANDSHAKE_TIMEOUT_MILLIS = TimeUnit.SECONDS.toMillis(120); |
71 | 68 |
|
72 | 69 | // mutable state |
73 | 70 | final InternalHandlerRegistry.Builder registryBuilder = |
74 | 71 | new InternalHandlerRegistry.Builder(); |
75 | 72 | final List<ServerTransportFilter> transportFilters = new ArrayList<>(); |
76 | 73 | final List<ServerInterceptor> interceptors = new ArrayList<>(); |
77 | | - private final List<ServerStreamTracer.Factory> streamTracerFactories = new ArrayList<>(); |
| 74 | + protected final List<ServerStreamTracer.Factory> streamTracerFactories = new ArrayList<>(); |
78 | 75 | HandlerRegistry fallbackRegistry = DEFAULT_FALLBACK_REGISTRY; |
79 | 76 | ObjectPool<? extends Executor> executorPool = DEFAULT_EXECUTOR_POOL; |
80 | 77 | DecompressorRegistry decompressorRegistry = DEFAULT_DECOMPRESSOR_REGISTRY; |
81 | 78 | CompressorRegistry compressorRegistry = DEFAULT_COMPRESSOR_REGISTRY; |
82 | 79 | long handshakeTimeoutMillis = DEFAULT_HANDSHAKE_TIMEOUT_MILLIS; |
83 | 80 | Deadline.Ticker ticker = Deadline.getSystemTicker(); |
84 | | - private boolean statsEnabled = true; |
85 | | - private boolean recordStartedRpcs = true; |
86 | | - private boolean recordFinishedRpcs = true; |
87 | | - private boolean recordRealTimeMetrics = false; |
88 | | - private boolean tracingEnabled = true; |
| 81 | + protected boolean statsEnabled = true; |
| 82 | + protected boolean recordStartedRpcs = true; |
| 83 | + protected boolean recordFinishedRpcs = true; |
| 84 | + protected boolean recordRealTimeMetrics = false; |
| 85 | + protected boolean tracingEnabled = true; |
89 | 86 | @Nullable BinaryLog binlog; |
90 | 87 | TransportTracer.Factory transportTracerFactory = TransportTracer.getDefaultFactory(); |
91 | 88 | InternalChannelz channelz = InternalChannelz.instance(); |
92 | 89 | CallTracer.Factory callTracerFactory = CallTracer.getDefaultFactory(); |
93 | 90 |
|
94 | | - @Override |
95 | | - public final T directExecutor() { |
96 | | - return executor(MoreExecutors.directExecutor()); |
97 | | - } |
98 | | - |
99 | | - @Override |
100 | | - public final T executor(@Nullable Executor executor) { |
101 | | - this.executorPool = executor != null ? new FixedObjectPool<>(executor) : DEFAULT_EXECUTOR_POOL; |
102 | | - return thisT(); |
103 | | - } |
104 | | - |
105 | | - @Override |
106 | | - public final T addService(ServerServiceDefinition service) { |
107 | | - registryBuilder.addService(checkNotNull(service, "service")); |
108 | | - return thisT(); |
109 | | - } |
110 | | - |
111 | | - @Override |
112 | | - public final T addService(BindableService bindableService) { |
113 | | - return addService(checkNotNull(bindableService, "bindableService").bindService()); |
114 | | - } |
115 | | - |
116 | | - @Override |
117 | | - public final T addTransportFilter(ServerTransportFilter filter) { |
118 | | - transportFilters.add(checkNotNull(filter, "filter")); |
119 | | - return thisT(); |
120 | | - } |
121 | | - |
122 | | - @Override |
123 | | - public final T intercept(ServerInterceptor interceptor) { |
124 | | - interceptors.add(checkNotNull(interceptor, "interceptor")); |
125 | | - return thisT(); |
126 | | - } |
127 | | - |
128 | | - @Override |
129 | | - public final T addStreamTracerFactory(ServerStreamTracer.Factory factory) { |
130 | | - streamTracerFactories.add(checkNotNull(factory, "factory")); |
131 | | - return thisT(); |
132 | | - } |
133 | | - |
134 | | - @Override |
135 | | - public final T fallbackHandlerRegistry(@Nullable HandlerRegistry registry) { |
136 | | - this.fallbackRegistry = registry != null ? registry : DEFAULT_FALLBACK_REGISTRY; |
137 | | - return thisT(); |
138 | | - } |
139 | | - |
140 | | - @Override |
141 | | - public final T decompressorRegistry(@Nullable DecompressorRegistry registry) { |
142 | | - this.decompressorRegistry = registry != null ? registry : DEFAULT_DECOMPRESSOR_REGISTRY; |
143 | | - return thisT(); |
144 | | - } |
145 | | - |
146 | | - @Override |
147 | | - public final T compressorRegistry(@Nullable CompressorRegistry registry) { |
148 | | - this.compressorRegistry = registry != null ? registry : DEFAULT_COMPRESSOR_REGISTRY; |
149 | | - return thisT(); |
150 | | - } |
151 | | - |
152 | | - @Override |
153 | | - public final T handshakeTimeout(long timeout, TimeUnit unit) { |
154 | | - checkArgument(timeout > 0, "handshake timeout is %s, but must be positive", timeout); |
155 | | - this.handshakeTimeoutMillis = checkNotNull(unit, "unit").toMillis(timeout); |
156 | | - return thisT(); |
157 | | - } |
158 | | - |
159 | | - @Override |
160 | | - public final T setBinaryLog(@Nullable BinaryLog binaryLog) { |
161 | | - this.binlog = binaryLog; |
162 | | - return thisT(); |
163 | | - } |
164 | | - |
165 | | - @VisibleForTesting |
166 | | - public final T setTransportTracerFactory(TransportTracer.Factory transportTracerFactory) { |
167 | | - this.transportTracerFactory = transportTracerFactory; |
168 | | - return thisT(); |
169 | | - } |
170 | | - |
171 | 91 | /** |
172 | 92 | * Disable or enable stats features. Enabled by default. |
173 | 93 | */ |
@@ -294,12 +214,6 @@ protected final TransportTracer.Factory getTransportTracerFactory() { |
294 | 214 | protected abstract List<? extends io.grpc.internal.InternalServer> buildTransportServers( |
295 | 215 | List<? extends ServerStreamTracer.Factory> streamTracerFactories); |
296 | 216 |
|
297 | | - private T thisT() { |
298 | | - @SuppressWarnings("unchecked") |
299 | | - T thisT = (T) this; |
300 | | - return thisT; |
301 | | - } |
302 | | - |
303 | 217 | private static final class DefaultFallbackRegistry extends HandlerRegistry { |
304 | 218 | @Override |
305 | 219 | public List<ServerServiceDefinition> getServices() { |
|
0 commit comments