T
- The concrete type of this builder.public abstract class ManagedChannelBuilder<T extends ManagedChannelBuilder<T>> extends Object
ManagedChannel
instances.Constructor and Description |
---|
ManagedChannelBuilder() |
Modifier and Type | Method and Description |
---|---|
abstract ManagedChannel |
build()
Builds a channel using the given parameters.
|
abstract T |
compressorRegistry(CompressorRegistry registry)
Set the compression registry for use in the channel.
|
abstract T |
decompressorRegistry(DecompressorRegistry registry)
Set the decompression registry for use in the channel.
|
abstract T |
directExecutor()
Execute application code directly in the transport thread.
|
abstract T |
executor(Executor executor)
Provides a custom executor.
|
static ManagedChannelBuilder<?> |
forAddress(String name,
int port) |
static ManagedChannelBuilder<?> |
forTarget(String target)
Creates a channel with a target string, which can be either a valid
NameResolver -compliant URI, or an authority string. |
abstract T |
idleTimeout(long value,
TimeUnit unit)
Set the duration without ongoing RPCs before going to idle mode.
|
abstract T |
intercept(ClientInterceptor... interceptors)
Adds interceptors that will be called before the channel performs its real work.
|
abstract T |
intercept(List<ClientInterceptor> interceptors)
Adds interceptors that will be called before the channel performs its real work.
|
abstract T |
loadBalancerFactory(LoadBalancer.Factory loadBalancerFactory)
Provides a custom
LoadBalancer.Factory for the channel. |
abstract T |
nameResolverFactory(NameResolver.Factory resolverFactory) |
abstract T |
overrideAuthority(String authority)
Overrides the authority used with TLS and HTTP virtual hosting.
|
abstract T |
usePlaintext(boolean skipNegotiation) |
abstract T |
userAgent(String userAgent)
Provides a custom
User-Agent for the application. |
public static ManagedChannelBuilder<?> forAddress(String name, int port)
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1773") public static ManagedChannelBuilder<?> forTarget(String target)
NameResolver
-compliant URI, or an authority string.
A NameResolver
-compliant URI is an absolute hierarchical URI as defined by URI
. Example URIs:
"dns:///foo.googleapis.com:8080"
"dns:///foo.googleapis.com"
"dns:///%5B2001:db8:85a3:8d3:1319:8a2e:370:7348%5D:443"
"dns://8.8.8.8/foo.googleapis.com:8080"
"dns://8.8.8.8/foo.googleapis.com"
"zookeeper://zk.example.com:9900/example_service"
An authority string will be converted to a NameResolver
-compliant URI, which has
"dns"
as the scheme, no authority, and the original authority string as its path after
properly escaped. Example authority strings:
"localhost"
"127.0.0.1"
"localhost:8080"
"foo.googleapis.com:8080"
"127.0.0.1:8080"
"[2001:db8:85a3:8d3:1319:8a2e:370:7348]"
"[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443"
public abstract T directExecutor()
Depending on the underlying transport, using a direct executor may lead to substantial performance improvements. However, it also requires the application to not block under any circumstances.
Calling this method is semantically equivalent to calling executor(Executor)
and
passing in a direct executor. However, this is the preferred way as it may allow the transport
to perform special optimizations.
public abstract T executor(Executor executor)
It's an optional parameter. If the user has not provided an executor when the channel is built, the builder will use a static cached thread pool.
The channel won't take ownership of the given executor. It's caller's responsibility to shut down the executor when it's desired.
public abstract T intercept(List<ClientInterceptor> interceptors)
ClientInterceptors.intercept(Channel, List)
, but while
still having access to the original ManagedChannel
.public abstract T intercept(ClientInterceptor... interceptors)
ClientInterceptors.intercept(Channel,
ClientInterceptor...)
, but while still having access to the original ManagedChannel
.public abstract T userAgent(String userAgent)
User-Agent
for the application.
It's an optional parameter. If provided, the given agent will be prepended by the
grpc User-Agent
.
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1767") public abstract T overrideAuthority(String authority)
host:port
.
Should only used by tests.
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1772") public abstract T usePlaintext(boolean skipNegotiation)
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1770") public abstract T nameResolverFactory(NameResolver.Factory resolverFactory)
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1771") public abstract T loadBalancerFactory(LoadBalancer.Factory loadBalancerFactory)
LoadBalancer.Factory
for the channel.
If this method is not called, the builder will use DummyLoadBalancerFactory
for the channel.
@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1704") public abstract T decompressorRegistry(DecompressorRegistry registry)
DecompressorRegistry.getDefaultInstance
.@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1704") public abstract T compressorRegistry(CompressorRegistry registry)
CompressorRegistry.getDefaultInstance
.@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/2022") public abstract T idleTimeout(long value, TimeUnit unit)
In idle mode the channel shuts down all connections, the NameResolver and the LoadBalancer. A new RPC would take the channel out of idle mode. A channel starts in idle mode.
By default the channel will never go to idle mode after it leaves the initial idle mode.
This is an advisory option. Do not rely on any specific behavior related to this option.
public abstract ManagedChannel build()