@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1783") public final class InProcessServerBuilder extends io.grpc.internal.AbstractServerImplBuilder<InProcessServerBuilder>
The server is intended to be fully-featured, high performance, and useful in testing.
InProcessServer
and a ManagedChannel
. This
test rule contains the boilerplate code shown below. The classes "HelloWorldServerTest" and
"HelloWorldClientTest" (from "grpc-java/examples") demonstrate basic usage.
String uniqueName = InProcessServerBuilder.generateName(); Server server = InProcessServerBuilder.forName(uniqueName) .directExecutor() // directExecutor is fine for unit tests .addService(/* your code here */) .build().start(); ManagedChannel channel = InProcessChannelBuilder.forName(uniqueName) .directExecutor() .build();
TestServiceGrpc.TestServiceBlockingStub blockingStub = TestServiceGrpc.newBlockingStub(channel);
Modifier and Type | Method | Description |
---|---|---|
protected java.util.List<io.grpc.inprocess.InProcessServer> |
buildTransportServers(java.util.List<? extends io.grpc.ServerStreamTracer.Factory> streamTracerFactories) |
|
InProcessServerBuilder |
deadlineTicker(io.grpc.Deadline.Ticker ticker) |
Provides a custom deadline ticker that this server will use to create incoming
Deadline s. |
static InProcessServerBuilder |
forName(java.lang.String name) |
Create a server builder that will bind with the given name.
|
static InProcessServerBuilder |
forPort(int port) |
Always fails.
|
static java.lang.String |
generateName() |
Generates a new server name that is unique each time.
|
InProcessServerBuilder |
maxInboundMetadataSize(int bytes) |
Sets the maximum size of metadata allowed to be received.
|
InProcessServerBuilder |
scheduledExecutorService(java.util.concurrent.ScheduledExecutorService scheduledExecutorService) |
Provides a custom scheduled executor service.
|
InProcessServerBuilder |
useTransportSecurity(java.io.File certChain,
java.io.File privateKey) |
addService, addService, addStreamTracerFactory, addTransportFilter, build, compressorRegistry, decompressorRegistry, directExecutor, executor, fallbackHandlerRegistry, getChannelz, getTransportTracerFactory, handshakeTimeout, intercept, overrideCensusStatsModule, setBinaryLog, setDeadlineTicker, setStatsEnabled, setStatsRecordFinishedRpcs, setStatsRecordRealTimeMetrics, setStatsRecordStartedRpcs, setTracingEnabled, setTransportTracerFactory
public static InProcessServerBuilder forName(java.lang.String name)
name
- the identity of the server for clients to connect topublic static InProcessServerBuilder forPort(int port)
forName(java.lang.String)
instead.public static java.lang.String generateName()
public InProcessServerBuilder scheduledExecutorService(java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
It's an optional parameter. If the user has not provided a scheduled executor service when the channel is built, the builder will use a static cached thread pool.
public InProcessServerBuilder deadlineTicker(io.grpc.Deadline.Ticker ticker)
Deadline
s.
This is intended for unit tests that fake out the clock. You should also have a fake ScheduledExecutorService
whose clock is synchronized with this ticker and set it to scheduledExecutorService(java.util.concurrent.ScheduledExecutorService)
. DO NOT use this in production.
Deadline.after(long, TimeUnit, Deadline.Ticker)
public InProcessServerBuilder maxInboundMetadataSize(int bytes)
Integer.MAX_VALUE
disables
the enforcement. Defaults to no limit (Integer.MAX_VALUE
).
There is potential for performance penalty when this setting is enabled, as the Metadata must actually be serialized. Since the current implementation of Metadata pre-serializes, it's currently negligible. But Metadata is free to change its implementation.
maxInboundMetadataSize
in class io.grpc.ServerBuilder<InProcessServerBuilder>
bytes
- the maximum size of received metadatajava.lang.IllegalArgumentException
- if bytes is non-positiveprotected java.util.List<io.grpc.inprocess.InProcessServer> buildTransportServers(java.util.List<? extends io.grpc.ServerStreamTracer.Factory> streamTracerFactories)
buildTransportServers
in class io.grpc.internal.AbstractServerImplBuilder<InProcessServerBuilder>
public InProcessServerBuilder useTransportSecurity(java.io.File certChain, java.io.File privateKey)
useTransportSecurity
in class io.grpc.ServerBuilder<InProcessServerBuilder>