Class ManagedChannelImplBuilder
- java.lang.Object
-
- io.grpc.ManagedChannelBuilder<ManagedChannelImplBuilder>
-
- io.grpc.internal.ManagedChannelImplBuilder
-
public final class ManagedChannelImplBuilder extends ManagedChannelBuilder<ManagedChannelImplBuilder>
Default managed channel builder, for usage in Transport implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider
An interface for Transport implementors to provide a default port toNameResolver
for use in cases where the target string doesn't include a port.static interface
ManagedChannelImplBuilder.ClientTransportFactoryBuilder
An interface for Transport implementors to provide theClientTransportFactory
appropriate for the channel.private static class
ManagedChannelImplBuilder.DirectAddressNameResolverProvider
static class
ManagedChannelImplBuilder.FixedPortProvider
Default implementation ofManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider
that returns a fixed port.private static class
ManagedChannelImplBuilder.InterceptorFactoryWrapper
private static class
ManagedChannelImplBuilder.ManagedChannelDefaultPortProvider
(package private) static class
ManagedChannelImplBuilder.ResolvedNameResolver
static class
ManagedChannelImplBuilder.UnsupportedClientTransportFactoryBuilder
Convenience ClientTransportFactoryBuilder, throws UnsupportedOperationException().-
Nested classes/interfaces inherited from class io.grpc.ManagedChannelBuilder
ManagedChannelBuilder.InterceptorFactory
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
authorityCheckerDisabled
(package private) java.lang.String
authorityOverride
(package private) BinaryLog
binlog
(package private) CallCredentials
callCredentials
private ManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider
channelBuilderDefaultPortProvider
(package private) ChannelCredentials
channelCredentials
(package private) InternalChannelz
channelz
private ManagedChannelImplBuilder.ClientTransportFactoryBuilder
clientTransportFactoryBuilder
(package private) CompressorRegistry
compressorRegistry
(package private) DecompressorRegistry
decompressorRegistry
private static CompressorRegistry
DEFAULT_COMPRESSOR_REGISTRY
private static DecompressorRegistry
DEFAULT_DECOMPRESSOR_REGISTRY
private static ObjectPool<? extends java.util.concurrent.Executor>
DEFAULT_EXECUTOR_POOL
private static long
DEFAULT_PER_RPC_BUFFER_LIMIT_IN_BYTES
private static long
DEFAULT_RETRY_BUFFER_SIZE_IN_BYTES
(package private) java.lang.String
defaultLbPolicy
(package private) java.util.Map<java.lang.String,?>
defaultServiceConfig
private static java.lang.String
DIRECT_ADDRESS_SCHEME
private java.net.SocketAddress
directServerAddress
(package private) ObjectPool<? extends java.util.concurrent.Executor>
executorPool
(package private) boolean
fullStreamDecompression
private static java.lang.reflect.Method
GET_CLIENT_INTERCEPTOR_METHOD
(package private) static long
IDLE_MODE_DEFAULT_TIMEOUT_MILLIS
The default idle timeout.(package private) static long
IDLE_MODE_MAX_TIMEOUT_DAYS
An idle timeout larger than this would disable idle mode.(package private) static long
IDLE_MODE_MIN_TIMEOUT_MILLIS
An idle timeout smaller than this would be capped to it.(package private) long
idleTimeoutMillis
private java.util.List<ClientInterceptor>
interceptors
private static java.util.logging.Logger
log
(package private) boolean
lookUpServiceConfig
(package private) int
maxHedgedAttempts
(package private) int
maxRetryAttempts
(package private) int
maxTraceEvents
(package private) java.util.List<MetricSink>
metricSinks
(package private) NameResolverRegistry
nameResolverRegistry
(package private) ObjectPool<? extends java.util.concurrent.Executor>
offloadExecutorPool
(package private) long
perRpcBufferLimit
(package private) ProxyDetector
proxyDetector
private boolean
recordFinishedRpcs
private boolean
recordRealTimeMetrics
private boolean
recordRetryMetrics
private boolean
recordStartedRpcs
(package private) long
retryBufferSize
(package private) boolean
retryEnabled
private boolean
statsEnabled
(package private) java.lang.String
target
private boolean
tracingEnabled
(package private) java.util.List<ClientTransportFilter>
transportFilters
(package private) static java.util.regex.Pattern
URI_PATTERN
(package private) java.lang.String
userAgent
-
Constructor Summary
Constructors Constructor Description ManagedChannelImplBuilder(java.lang.String target, ChannelCredentials channelCreds, CallCredentials callCreds, ManagedChannelImplBuilder.ClientTransportFactoryBuilder clientTransportFactoryBuilder, ManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider)
Creates a new managed channel builder with a target string, which can be either a validNameResolver
-compliant URI, or an authority string.ManagedChannelImplBuilder(java.lang.String target, ManagedChannelImplBuilder.ClientTransportFactoryBuilder clientTransportFactoryBuilder, ManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider)
Creates a new managed channel builder with a target string, which can be either a validNameResolver
-compliant URI, or an authority string.ManagedChannelImplBuilder(java.net.SocketAddress directServerAddress, java.lang.String authority, ChannelCredentials channelCreds, CallCredentials callCreds, ManagedChannelImplBuilder.ClientTransportFactoryBuilder clientTransportFactoryBuilder, ManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider)
Creates a new managed channel builder with the given server address, authority string of the channel.ManagedChannelImplBuilder(java.net.SocketAddress directServerAddress, java.lang.String authority, ManagedChannelImplBuilder.ClientTransportFactoryBuilder clientTransportFactoryBuilder, ManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider)
Creates a new managed channel builder with the given server address, authority string of the channel.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected ManagedChannelImplBuilder
addMetricSink(MetricSink metricSink)
Adds aMetricSink
for channel to use for configuring and recording metrics.ManagedChannelImplBuilder
addTransportFilter(ClientTransportFilter hook)
Adds aClientTransportFilter
.ManagedChannel
build()
Builds a channel using the given parameters.(package private) java.lang.String
checkAuthority(java.lang.String authority)
Verifies the authority is valid.private static java.util.List<?>
checkListEntryTypes(java.util.List<?> list)
private static java.util.Map<java.lang.String,?>
checkMapEntryTypes(java.util.Map<?,?> map)
ManagedChannelImplBuilder
compressorRegistry(CompressorRegistry registry)
Set the compression registry for use in the channel.ManagedChannelImplBuilder
decompressorRegistry(DecompressorRegistry registry)
Set the decompression registry for use in the channel.ManagedChannelImplBuilder
defaultLoadBalancingPolicy(java.lang.String policy)
Sets the default load-balancing policy that will be used if the service config doesn't specify one.ManagedChannelImplBuilder
defaultServiceConfig(java.util.Map<java.lang.String,?> serviceConfig)
Provides a service config to the channel.ManagedChannelImplBuilder
directExecutor()
Execute application code directly in the transport thread.ManagedChannelImplBuilder
disableCheckAuthority()
Disable the check whether the authority is valid.ManagedChannelImplBuilder
disableRetry()
Disables the retry and hedging subsystem provided by the gRPC library.ManagedChannelImplBuilder
disableServiceConfigLookUp()
Disables service config look-up from the naming system, which is enabled by default.ManagedChannelImplBuilder
enableCheckAuthority()
Enable previously disabled authority check.ManagedChannelImplBuilder
enableRetry()
Enables the retry and hedging subsystem which will use per-method configuration.ManagedChannelImplBuilder
executor(java.util.concurrent.Executor executor)
Provides a custom executor.static ManagedChannelBuilder<?>
forAddress(java.lang.String name, int port)
static ManagedChannelBuilder<?>
forTarget(java.lang.String target)
(package private) int
getDefaultPort()
Returns a default port toNameResolver
for use in cases where the target string doesn't include a port.(package private) java.util.List<ClientInterceptor>
getEffectiveInterceptors(java.lang.String computedTarget)
(package private) static ManagedChannelImplBuilder.ResolvedNameResolver
getNameResolverProvider(java.lang.String target, NameResolverRegistry nameResolverRegistry, java.util.Collection<java.lang.Class<? extends java.net.SocketAddress>> channelTransportSocketAddressTypes)
ObjectPool<? extends java.util.concurrent.Executor>
getOffloadExecutorPool()
Returns the internal offload executor pool for offloading tasks.ManagedChannelImplBuilder
idleTimeout(long value, java.util.concurrent.TimeUnit unit)
Set the duration without ongoing RPCs before going to idle mode.ManagedChannelImplBuilder
intercept(ClientInterceptor... interceptors)
Adds interceptors that will be called before the channel performs its real work.ManagedChannelImplBuilder
intercept(java.util.List<ClientInterceptor> interceptors)
Adds interceptors that will be called before the channel performs its real work.protected ManagedChannelImplBuilder
interceptWithTarget(ManagedChannelBuilder.InterceptorFactory factory)
Internal-only: Adds a factory that will construct an interceptor based on the channel's target.(package private) static java.lang.String
makeTargetStringForDirectAddress(java.net.SocketAddress address)
Returns a target string for the SocketAddress.ManagedChannelImplBuilder
maxHedgedAttempts(int maxHedgedAttempts)
Sets the maximum number of hedged attempts that may be configured by the service config.ManagedChannelImplBuilder
maxRetryAttempts(int maxRetryAttempts)
Sets the maximum number of retry attempts that may be configured by the service config.ManagedChannelImplBuilder
maxTraceEvents(int maxTraceEvents)
Sets the maximum number of channel trace events to keep in the tracer for each channel or subchannel.ManagedChannelImplBuilder
nameResolverFactory(NameResolver.Factory resolverFactory)
Deprecated.(package private) ManagedChannelImplBuilder
nameResolverRegistry(NameResolverRegistry resolverRegistry)
ManagedChannelImplBuilder
offloadExecutor(java.util.concurrent.Executor executor)
Provides a custom executor that will be used for operations that block or are expensive, to avoid blocking asynchronous code paths.ManagedChannelImplBuilder
overrideAuthority(java.lang.String authority)
Overrides the authority used with TLS and HTTP virtual hosting.ManagedChannelImplBuilder
perRpcBufferLimit(long bytes)
Sets the per RPC buffer limit in bytes used for retry.ManagedChannelImplBuilder
proxyDetector(ProxyDetector proxyDetector)
Sets the proxy detector to be used in addresses name resolution.ManagedChannelImplBuilder
retryBufferSize(long bytes)
Sets the retry buffer size in bytes.ManagedChannelImplBuilder
setBinaryLog(BinaryLog binlog)
Sets the BinaryLog object that this channel should log to.void
setStatsEnabled(boolean value)
Disable or enable stats features.void
setStatsRecordFinishedRpcs(boolean value)
Disable or enable stats recording for RPC completions.void
setStatsRecordRealTimeMetrics(boolean value)
Disable or enable real-time metrics recording.void
setStatsRecordRetryMetrics(boolean value)
void
setStatsRecordStartedRpcs(boolean value)
Disable or enable stats recording for RPC upstarts.void
setTracingEnabled(boolean value)
Disable or enable tracing features.ManagedChannelImplBuilder
userAgent(java.lang.String userAgent)
Provides a customUser-Agent
for the application.-
Methods inherited from class io.grpc.ManagedChannelBuilder
keepAliveTime, keepAliveTimeout, keepAliveWithoutCalls, maxInboundMessageSize, maxInboundMetadataSize, usePlaintext, useTransportSecurity
-
-
-
-
Field Detail
-
DIRECT_ADDRESS_SCHEME
private static final java.lang.String DIRECT_ADDRESS_SCHEME
- See Also:
- Constant Field Values
-
log
private static final java.util.logging.Logger log
-
IDLE_MODE_MAX_TIMEOUT_DAYS
static final long IDLE_MODE_MAX_TIMEOUT_DAYS
An idle timeout larger than this would disable idle mode.- See Also:
- Constant Field Values
-
IDLE_MODE_DEFAULT_TIMEOUT_MILLIS
static final long IDLE_MODE_DEFAULT_TIMEOUT_MILLIS
The default idle timeout.
-
IDLE_MODE_MIN_TIMEOUT_MILLIS
static final long IDLE_MODE_MIN_TIMEOUT_MILLIS
An idle timeout smaller than this would be capped to it.
-
DEFAULT_EXECUTOR_POOL
private static final ObjectPool<? extends java.util.concurrent.Executor> DEFAULT_EXECUTOR_POOL
-
DEFAULT_DECOMPRESSOR_REGISTRY
private static final DecompressorRegistry DEFAULT_DECOMPRESSOR_REGISTRY
-
DEFAULT_COMPRESSOR_REGISTRY
private static final CompressorRegistry DEFAULT_COMPRESSOR_REGISTRY
-
DEFAULT_RETRY_BUFFER_SIZE_IN_BYTES
private static final long DEFAULT_RETRY_BUFFER_SIZE_IN_BYTES
- See Also:
- Constant Field Values
-
DEFAULT_PER_RPC_BUFFER_LIMIT_IN_BYTES
private static final long DEFAULT_PER_RPC_BUFFER_LIMIT_IN_BYTES
- See Also:
- Constant Field Values
-
URI_PATTERN
static final java.util.regex.Pattern URI_PATTERN
-
GET_CLIENT_INTERCEPTOR_METHOD
private static final java.lang.reflect.Method GET_CLIENT_INTERCEPTOR_METHOD
-
executorPool
ObjectPool<? extends java.util.concurrent.Executor> executorPool
-
offloadExecutorPool
ObjectPool<? extends java.util.concurrent.Executor> offloadExecutorPool
-
interceptors
private final java.util.List<ClientInterceptor> interceptors
-
nameResolverRegistry
NameResolverRegistry nameResolverRegistry
-
transportFilters
final java.util.List<ClientTransportFilter> transportFilters
-
target
final java.lang.String target
-
channelCredentials
@Nullable final ChannelCredentials channelCredentials
-
callCredentials
@Nullable final CallCredentials callCredentials
-
directServerAddress
@Nullable private final java.net.SocketAddress directServerAddress
-
userAgent
@Nullable java.lang.String userAgent
-
authorityOverride
@Nullable java.lang.String authorityOverride
-
defaultLbPolicy
java.lang.String defaultLbPolicy
-
fullStreamDecompression
boolean fullStreamDecompression
-
decompressorRegistry
DecompressorRegistry decompressorRegistry
-
compressorRegistry
CompressorRegistry compressorRegistry
-
idleTimeoutMillis
long idleTimeoutMillis
-
maxRetryAttempts
int maxRetryAttempts
-
maxHedgedAttempts
int maxHedgedAttempts
-
retryBufferSize
long retryBufferSize
-
perRpcBufferLimit
long perRpcBufferLimit
-
retryEnabled
boolean retryEnabled
-
channelz
InternalChannelz channelz
-
maxTraceEvents
int maxTraceEvents
-
defaultServiceConfig
@Nullable java.util.Map<java.lang.String,?> defaultServiceConfig
-
lookUpServiceConfig
boolean lookUpServiceConfig
-
binlog
@Nullable BinaryLog binlog
-
proxyDetector
@Nullable ProxyDetector proxyDetector
-
authorityCheckerDisabled
private boolean authorityCheckerDisabled
-
statsEnabled
private boolean statsEnabled
-
recordStartedRpcs
private boolean recordStartedRpcs
-
recordFinishedRpcs
private boolean recordFinishedRpcs
-
recordRealTimeMetrics
private boolean recordRealTimeMetrics
-
recordRetryMetrics
private boolean recordRetryMetrics
-
tracingEnabled
private boolean tracingEnabled
-
metricSinks
java.util.List<MetricSink> metricSinks
-
clientTransportFactoryBuilder
private final ManagedChannelImplBuilder.ClientTransportFactoryBuilder clientTransportFactoryBuilder
-
channelBuilderDefaultPortProvider
private final ManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider
-
-
Constructor Detail
-
ManagedChannelImplBuilder
public ManagedChannelImplBuilder(java.lang.String target, ManagedChannelImplBuilder.ClientTransportFactoryBuilder clientTransportFactoryBuilder, @Nullable ManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider)
Creates a new managed channel builder with a target string, which can be either a validNameResolver
-compliant URI, or an authority string. Transport implementors must provide client transport factory builder, and may set custom channel default port provider.
-
ManagedChannelImplBuilder
public ManagedChannelImplBuilder(java.lang.String target, @Nullable ChannelCredentials channelCreds, @Nullable CallCredentials callCreds, ManagedChannelImplBuilder.ClientTransportFactoryBuilder clientTransportFactoryBuilder, @Nullable ManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider)
Creates a new managed channel builder with a target string, which can be either a validNameResolver
-compliant URI, or an authority string. Transport implementors must provide client transport factory builder, and may set custom channel default port provider.- Parameters:
channelCreds
- The ChannelCredentials provided by the user. These may be used when creating derivative channels.
-
ManagedChannelImplBuilder
public ManagedChannelImplBuilder(java.net.SocketAddress directServerAddress, java.lang.String authority, ManagedChannelImplBuilder.ClientTransportFactoryBuilder clientTransportFactoryBuilder, @Nullable ManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider)
Creates a new managed channel builder with the given server address, authority string of the channel. Transport implementors must provide client transport factory builder, and may set custom channel default port provider.
-
ManagedChannelImplBuilder
public ManagedChannelImplBuilder(java.net.SocketAddress directServerAddress, java.lang.String authority, @Nullable ChannelCredentials channelCreds, @Nullable CallCredentials callCreds, ManagedChannelImplBuilder.ClientTransportFactoryBuilder clientTransportFactoryBuilder, @Nullable ManagedChannelImplBuilder.ChannelBuilderDefaultPortProvider channelBuilderDefaultPortProvider)
Creates a new managed channel builder with the given server address, authority string of the channel. Transport implementors must provide client transport factory builder, and may set custom channel default port provider.- Parameters:
channelCreds
- The ChannelCredentials provided by the user. These may be used when creating derivative channels.
-
-
Method Detail
-
forAddress
public static ManagedChannelBuilder<?> forAddress(java.lang.String name, int port)
-
forTarget
public static ManagedChannelBuilder<?> forTarget(java.lang.String target)
-
makeTargetStringForDirectAddress
static java.lang.String makeTargetStringForDirectAddress(java.net.SocketAddress address)
Returns a target string for the SocketAddress. It is only used as a placeholder, because DirectAddressNameResolverProvider will not actually try to use it. However, it must be a valid URI.
-
directExecutor
public ManagedChannelImplBuilder directExecutor()
Description copied from class:ManagedChannelBuilder
Execute application code directly in the transport thread.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
ManagedChannelBuilder.executor(Executor)
and passing in a direct executor. However, this is the preferred way as it may allow the transport to perform special optimizations.- Specified by:
directExecutor
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
executor
public ManagedChannelImplBuilder executor(java.util.concurrent.Executor executor)
Description copied from class:ManagedChannelBuilder
Provides a custom 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.
- Specified by:
executor
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
offloadExecutor
public ManagedChannelImplBuilder offloadExecutor(java.util.concurrent.Executor executor)
Description copied from class:ManagedChannelBuilder
Provides a custom executor that will be used for operations that block or are expensive, to avoid blocking asynchronous code paths. For example, DNS queries and OAuth token fetching over HTTP could use this 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.
- Overrides:
offloadExecutor
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
intercept
public ManagedChannelImplBuilder intercept(java.util.List<ClientInterceptor> interceptors)
Description copied from class:ManagedChannelBuilder
Adds interceptors that will be called before the channel performs its real work. This is functionally equivalent to usingClientInterceptors.intercept(Channel, List)
, but while still having access to the originalManagedChannel
. Interceptors run in the reverse order in which they are added, just as with consecutive calls toClientInterceptors.intercept()
.- Specified by:
intercept
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
intercept
public ManagedChannelImplBuilder intercept(ClientInterceptor... interceptors)
Description copied from class:ManagedChannelBuilder
Adds interceptors that will be called before the channel performs its real work. This is functionally equivalent to usingClientInterceptors.intercept(Channel, ClientInterceptor...)
, but while still having access to the originalManagedChannel
. Interceptors run in the reverse order in which they are added, just as with consecutive calls toClientInterceptors.intercept()
.- Specified by:
intercept
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
interceptWithTarget
protected ManagedChannelImplBuilder interceptWithTarget(ManagedChannelBuilder.InterceptorFactory factory)
Description copied from class:ManagedChannelBuilder
Internal-only: Adds a factory that will construct an interceptor based on the channel's target. This can be used to work around nameResolverFactory() changing the target string.- Overrides:
interceptWithTarget
in classManagedChannelBuilder<ManagedChannelImplBuilder>
-
addTransportFilter
public ManagedChannelImplBuilder addTransportFilter(ClientTransportFilter hook)
Description copied from class:ManagedChannelBuilder
Adds aClientTransportFilter
. The order of filters being added is the order they will be executed- Overrides:
addTransportFilter
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
nameResolverFactory
@Deprecated public ManagedChannelImplBuilder nameResolverFactory(NameResolver.Factory resolverFactory)
Deprecated.Description copied from class:ManagedChannelBuilder
Provides a customNameResolver.Factory
for the channel. If this method is not called, the builder will try the providers registered in the defaultNameResolverRegistry
for the given target.This method should rarely be used, as name resolvers should provide a
NameResolverProvider
and users rely on service loading to find implementations in the class path. That allows application's configuration to easily choose the name resolver via the 'target' string passed toManagedChannelBuilder.forTarget(String)
.- Specified by:
nameResolverFactory
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
nameResolverRegistry
ManagedChannelImplBuilder nameResolverRegistry(NameResolverRegistry resolverRegistry)
-
defaultLoadBalancingPolicy
public ManagedChannelImplBuilder defaultLoadBalancingPolicy(java.lang.String policy)
Description copied from class:ManagedChannelBuilder
Sets the default load-balancing policy that will be used if the service config doesn't specify one. If not set, the default will be the "pick_first" policy.Policy implementations are looked up in the
default LoadBalancerRegistry
.This method is implemented by all stock channel builders that are shipped with gRPC, but may not be implemented by custom channel builders, in which case this method will throw.
- Overrides:
defaultLoadBalancingPolicy
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
decompressorRegistry
public ManagedChannelImplBuilder decompressorRegistry(DecompressorRegistry registry)
Description copied from class:ManagedChannelBuilder
Set the decompression registry for use in the channel. This is an advanced API call and shouldn't be used unless you are using custom message encoding. The default supported decompressors are inDecompressorRegistry.getDefaultInstance()
.- Specified by:
decompressorRegistry
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
compressorRegistry
public ManagedChannelImplBuilder compressorRegistry(CompressorRegistry registry)
Description copied from class:ManagedChannelBuilder
Set the compression registry for use in the channel. This is an advanced API call and shouldn't be used unless you are using custom message encoding. The default supported compressors are inCompressorRegistry.getDefaultInstance()
.- Specified by:
compressorRegistry
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
userAgent
public ManagedChannelImplBuilder userAgent(@Nullable java.lang.String userAgent)
Description copied from class:ManagedChannelBuilder
Provides a customUser-Agent
for the application.It's an optional parameter. The library will provide a user agent independent of this option. If provided, the given agent will prepend the library's user agent information.
- Specified by:
userAgent
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
overrideAuthority
public ManagedChannelImplBuilder overrideAuthority(java.lang.String authority)
Description copied from class:ManagedChannelBuilder
Overrides the authority used with TLS and HTTP virtual hosting. It does not change what host is actually connected to. Is commonly in the formhost:port
.If the channel builder overrides authority, any authority override from name resolution result (via
EquivalentAddressGroup.ATTR_AUTHORITY_OVERRIDE
) will be discarded.This method is intended for testing, but may safely be used outside of tests as an alternative to DNS overrides.
- Specified by:
overrideAuthority
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
idleTimeout
public ManagedChannelImplBuilder idleTimeout(long value, java.util.concurrent.TimeUnit unit)
Description copied from class:ManagedChannelBuilder
Set the duration without ongoing RPCs before going to idle mode.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. Defaults to 30 minutes.
This is an advisory option. Do not rely on any specific behavior related to this option.
- Specified by:
idleTimeout
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
maxRetryAttempts
public ManagedChannelImplBuilder maxRetryAttempts(int maxRetryAttempts)
Description copied from class:ManagedChannelBuilder
Sets the maximum number of retry attempts that may be configured by the service config. If the service config specifies a larger value it will be reduced to this value. Setting this number to zero is not effectively the same asdisableRetry()
because the former does not disable transparent retry.This method may not work as expected for the current release because retry is not fully implemented yet.
- Overrides:
maxRetryAttempts
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
maxHedgedAttempts
public ManagedChannelImplBuilder maxHedgedAttempts(int maxHedgedAttempts)
Description copied from class:ManagedChannelBuilder
Sets the maximum number of hedged attempts that may be configured by the service config. If the service config specifies a larger value it will be reduced to this value.This method may not work as expected for the current release because retry is not fully implemented yet.
- Overrides:
maxHedgedAttempts
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
retryBufferSize
public ManagedChannelImplBuilder retryBufferSize(long bytes)
Description copied from class:ManagedChannelBuilder
Sets the retry buffer size in bytes. If the buffer limit is exceeded, no RPC could retry at the moment, and in hedging case all hedges but one of the same RPC will cancel. The implementation may only estimate the buffer size being used rather than count the exact physical memory allocated. The method does not have any effect if retry is disabled by the client.This method may not work as expected for the current release because retry is not fully implemented yet.
- Overrides:
retryBufferSize
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
perRpcBufferLimit
public ManagedChannelImplBuilder perRpcBufferLimit(long bytes)
Description copied from class:ManagedChannelBuilder
Sets the per RPC buffer limit in bytes used for retry. The RPC is not retriable if its buffer limit is exceeded. The implementation may only estimate the buffer size being used rather than count the exact physical memory allocated. It does not have any effect if retry is disabled by the client.This method may not work as expected for the current release because retry is not fully implemented yet.
- Overrides:
perRpcBufferLimit
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
disableRetry
public ManagedChannelImplBuilder disableRetry()
Description copied from class:ManagedChannelBuilder
Disables the retry and hedging subsystem provided by the gRPC library. This is designed for the case when users have their own retry implementation and want to avoid their own retry taking place simultaneously with the gRPC library layer retry.- Overrides:
disableRetry
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
enableRetry
public ManagedChannelImplBuilder enableRetry()
Description copied from class:ManagedChannelBuilder
Enables the retry and hedging subsystem which will use per-method configuration. If a method is unconfigured, it will be limited to transparent retries, which are safe for non-idempotent RPCs. Service config is ideally provided by the name resolver, but may also be specified viaManagedChannelBuilder.defaultServiceConfig(java.util.Map<java.lang.String, ?>)
.- Overrides:
enableRetry
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
setBinaryLog
public ManagedChannelImplBuilder setBinaryLog(BinaryLog binlog)
Description copied from class:ManagedChannelBuilder
Sets the BinaryLog object that this channel should log to. The channel does not take ownership of the object, and users are responsible for callingCloseable.close()
.- Overrides:
setBinaryLog
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Parameters:
binlog
- the object to provide logging.- Returns:
- this
-
maxTraceEvents
public ManagedChannelImplBuilder maxTraceEvents(int maxTraceEvents)
Description copied from class:ManagedChannelBuilder
Sets the maximum number of channel trace events to keep in the tracer for each channel or subchannel. If set to 0, channel tracing is effectively disabled.- Overrides:
maxTraceEvents
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
proxyDetector
public ManagedChannelImplBuilder proxyDetector(@Nullable ProxyDetector proxyDetector)
Description copied from class:ManagedChannelBuilder
Sets the proxy detector to be used in addresses name resolution. Ifnull
is passed the default proxy detector will be used. For how proxies work in gRPC, please refer to the documentation onProxyDetector
.- Overrides:
proxyDetector
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
defaultServiceConfig
public ManagedChannelImplBuilder defaultServiceConfig(@Nullable java.util.Map<java.lang.String,?> serviceConfig)
Description copied from class:ManagedChannelBuilder
Provides a service config to the channel. The channel will use the default service config when the name resolver provides no service config or if the channel disables lookup service config from name resolver (seeManagedChannelBuilder.disableServiceConfigLookUp()
). The argumentserviceConfig
is a nested map representing a Json object in the most natural way:Json entry Java Type object Map
array List
string String
number Double
boolean Boolean
null null
If null is passed, then there will be no default service config.
Your preferred JSON parser may not produce results in the format expected. For such cases, you can convert its output. For example, if your parser produces Integers and other Numbers in addition to Double:
@SuppressWarnings("unchecked") private static Object convertNumbers(Object o) { if (o instanceof Map) { ((Map) o).replaceAll((k,v) -> convertNumbers(v)); } else if (o instanceof List) { ((List) o).replaceAll(YourClass::convertNumbers); } else if (o instanceof Number && !(o instanceof Double)) { o = ((Number) o).doubleValue(); } return o; }
- Overrides:
defaultServiceConfig
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
checkMapEntryTypes
@Nullable private static java.util.Map<java.lang.String,?> checkMapEntryTypes(@Nullable java.util.Map<?,?> map)
-
checkListEntryTypes
private static java.util.List<?> checkListEntryTypes(java.util.List<?> list)
-
disableServiceConfigLookUp
public ManagedChannelImplBuilder disableServiceConfigLookUp()
Description copied from class:ManagedChannelBuilder
Disables service config look-up from the naming system, which is enabled by default.- Overrides:
disableServiceConfigLookUp
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
setStatsEnabled
public void setStatsEnabled(boolean value)
Disable or enable stats features. Enabled by default.For the current release, calling
setStatsEnabled(true)
may have a side effect that disables retry.
-
setStatsRecordStartedRpcs
public void setStatsRecordStartedRpcs(boolean value)
Disable or enable stats recording for RPC upstarts. Effective only ifsetStatsEnabled(boolean)
is set to true. Enabled by default.
-
setStatsRecordFinishedRpcs
public void setStatsRecordFinishedRpcs(boolean value)
Disable or enable stats recording for RPC completions. Effective only ifsetStatsEnabled(boolean)
is set to true. Enabled by default.
-
setStatsRecordRealTimeMetrics
public void setStatsRecordRealTimeMetrics(boolean value)
Disable or enable real-time metrics recording. Effective only ifsetStatsEnabled(boolean)
is set to true. Disabled by default.
-
setStatsRecordRetryMetrics
public void setStatsRecordRetryMetrics(boolean value)
-
setTracingEnabled
public void setTracingEnabled(boolean value)
Disable or enable tracing features. Enabled by default.
-
checkAuthority
java.lang.String checkAuthority(java.lang.String authority)
Verifies the authority is valid.
-
disableCheckAuthority
public ManagedChannelImplBuilder disableCheckAuthority()
Disable the check whether the authority is valid.
-
enableCheckAuthority
public ManagedChannelImplBuilder enableCheckAuthority()
Enable previously disabled authority check.
-
addMetricSink
protected ManagedChannelImplBuilder addMetricSink(MetricSink metricSink)
Description copied from class:ManagedChannelBuilder
Adds aMetricSink
for channel to use for configuring and recording metrics.- Overrides:
addMetricSink
in classManagedChannelBuilder<ManagedChannelImplBuilder>
- Returns:
- this
-
build
public ManagedChannel build()
Description copied from class:ManagedChannelBuilder
Builds a channel using the given parameters.- Specified by:
build
in classManagedChannelBuilder<ManagedChannelImplBuilder>
-
getEffectiveInterceptors
java.util.List<ClientInterceptor> getEffectiveInterceptors(java.lang.String computedTarget)
-
getDefaultPort
int getDefaultPort()
Returns a default port toNameResolver
for use in cases where the target string doesn't include a port. The default implementation returnsGrpcUtil.DEFAULT_PORT_SSL
.
-
getNameResolverProvider
static ManagedChannelImplBuilder.ResolvedNameResolver getNameResolverProvider(java.lang.String target, NameResolverRegistry nameResolverRegistry, java.util.Collection<java.lang.Class<? extends java.net.SocketAddress>> channelTransportSocketAddressTypes)
-
getOffloadExecutorPool
public ObjectPool<? extends java.util.concurrent.Executor> getOffloadExecutorPool()
Returns the internal offload executor pool for offloading tasks.
-
-