@ExperimentalApi(value="https://github.com/grpc/grpc-java/issues/1785") public class OkHttpChannelBuilder extends io.grpc.internal.AbstractManagedChannelImplBuilder<OkHttpChannelBuilder>
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_FLOW_CONTROL_WINDOW |
| Modifier | Constructor and Description |
|---|---|
protected |
OkHttpChannelBuilder(String host,
int port) |
| Modifier and Type | Method and Description |
|---|---|
protected io.grpc.internal.ClientTransportFactory |
buildTransportFactory() |
OkHttpChannelBuilder |
connectionSpec(ConnectionSpec connectionSpec)
For secure connection, provides a ConnectionSpec to specify Cipher suite and
TLS versions.
|
OkHttpChannelBuilder |
enableKeepAlive(boolean enable)
Deprecated.
|
OkHttpChannelBuilder |
enableKeepAlive(boolean enable,
long keepAliveTime,
TimeUnit delayUnit,
long keepAliveTimeout,
TimeUnit timeoutUnit)
Deprecated.
|
OkHttpChannelBuilder |
flowControlWindow(int flowControlWindow)
Sets the flow control window in bytes.
|
static OkHttpChannelBuilder |
forAddress(String host,
int port)
Creates a new builder for the given server host and port.
|
static OkHttpChannelBuilder |
forTarget(String target)
Creates a new builder for the given target that will be resolved by
NameResolver. |
protected int |
getDefaultPort() |
OkHttpChannelBuilder |
hostnameVerifier(HostnameVerifier hostnameVerifier)
Set the hostname verifier to use when using TLS negotiation.
|
OkHttpChannelBuilder |
keepAliveTime(long keepAliveTime,
TimeUnit timeUnit)
Sets the time without read activity before sending a keepalive ping.
|
OkHttpChannelBuilder |
keepAliveTimeout(long keepAliveTimeout,
TimeUnit timeUnit)
Sets the time waiting for read activity after sending a keepalive ping.
|
OkHttpChannelBuilder |
keepAliveWithoutCalls(boolean enable)
Sets whether keepalive will be performed when there are no outstanding RPC on a connection.
|
OkHttpChannelBuilder |
maxInboundMetadataSize(int bytes)
Sets the maximum size of metadata allowed to be received.
|
OkHttpChannelBuilder |
negotiationType(NegotiationType type)
Deprecated.
use
usePlaintext() or useTransportSecurity() instead. |
OkHttpChannelBuilder |
scheduledExecutorService(ScheduledExecutorService scheduledExecutorService)
Provides a custom scheduled executor service.
|
OkHttpChannelBuilder |
socketFactory(SocketFactory socketFactory)
Override the default
SocketFactory used to create sockets. |
OkHttpChannelBuilder |
sslSocketFactory(SSLSocketFactory factory)
Override the default
SSLSocketFactory and enable TLS negotiation. |
OkHttpChannelBuilder |
transportExecutor(Executor transportExecutor)
Override the default executor necessary for internal transport use.
|
OkHttpChannelBuilder |
usePlaintext()
Sets the negotiation type for the HTTP/2 connection to plaintext.
|
OkHttpChannelBuilder |
usePlaintext(boolean skipNegotiation)
Deprecated.
use
usePlaintext() instead. |
OkHttpChannelBuilder |
useTransportSecurity()
Sets the negotiation type for the HTTP/2 connection to TLS (this is the default).
|
build, checkAuthority, compressorRegistry, decompressorRegistry, defaultLoadBalancingPolicy, defaultServiceConfig, directExecutor, disableRetry, disableServiceConfigLookUp, enableFullStreamDecompression, enableRetry, executor, idleTimeout, intercept, intercept, loadBalancerFactory, maxHedgedAttempts, maxInboundMessageSize, maxInboundMessageSize, maxRetryAttempts, maxTraceEvents, nameResolverFactory, overrideAuthority, overrideCensusStatsModule, perRpcBufferLimit, proxyDetector, retryBufferSize, setBinaryLog, setStatsEnabled, setStatsRecordFinishedRpcs, setStatsRecordRealTimeMetrics, setStatsRecordStartedRpcs, setTracingEnabled, userAgentpublic static final int DEFAULT_FLOW_CONTROL_WINDOW
protected OkHttpChannelBuilder(String host, int port)
public static OkHttpChannelBuilder forAddress(String host, int port)
public static OkHttpChannelBuilder forTarget(String target)
NameResolver.public final OkHttpChannelBuilder transportExecutor(@Nullable Executor transportExecutor)
The channel does not take ownership of the given executor. It is the caller' responsibility to shutdown the executor when appropriate.
public final OkHttpChannelBuilder socketFactory(@Nullable SocketFactory socketFactory)
SocketFactory used to create sockets. If the socket factory is not
set or set to null, a default one will be used.@Deprecated public final OkHttpChannelBuilder negotiationType(NegotiationType type)
usePlaintext() or useTransportSecurity() instead.If TLS is enabled a default SSLSocketFactory is created using the best
Provider available and is NOT based on
SSLSocketFactory.getDefault(). To more precisely control the TLS configuration call
sslSocketFactory to override the socket factory used.
Default: TLS
@Deprecated public final OkHttpChannelBuilder enableKeepAlive(boolean enable)
keepAliveTime(long, java.util.concurrent.TimeUnit) instead@Deprecated public final OkHttpChannelBuilder enableKeepAlive(boolean enable, long keepAliveTime, TimeUnit delayUnit, long keepAliveTimeout, TimeUnit timeoutUnit)
keepAliveTime(long, java.util.concurrent.TimeUnit) and keepAliveTimeout(long, java.util.concurrent.TimeUnit) insteadpublic OkHttpChannelBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit)
Long.MAX_VALUE nano seconds or an unreasonably large
value will disable keepalive. Defaults to infinite.
Clients must receive permission from the service owner before enabling this option. Keepalives can increase the load on services and are commonly "invisible" making it hard to notice when they are causing excessive load. Clients are strongly encouraged to use only as small of a value as necessary.
keepAliveTime in class ManagedChannelBuilder<OkHttpChannelBuilder>public OkHttpChannelBuilder keepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)
This value should be at least multiple times the RTT to allow for lost packets.
keepAliveTimeout in class ManagedChannelBuilder<OkHttpChannelBuilder>public OkHttpChannelBuilder flowControlWindow(int flowControlWindow)
DEFAULT_FLOW_CONTROL_WINDOW).public OkHttpChannelBuilder keepAliveWithoutCalls(boolean enable)
false.
Clients must receive permission from the service owner before enabling this option.
Keepalives on unused connections can easilly accidentally consume a considerable amount of
bandwidth and CPU. idleTimeout() should generally be
used instead of this option.
keepAliveWithoutCalls in class ManagedChannelBuilder<OkHttpChannelBuilder>keepAliveTime(long, TimeUnit)public final OkHttpChannelBuilder sslSocketFactory(SSLSocketFactory factory)
SSLSocketFactory and enable TLS negotiation.public final OkHttpChannelBuilder hostnameVerifier(@Nullable HostnameVerifier hostnameVerifier)
Be careful when setting a custom hostname verifier! By setting a non-null value, you are replacing all default verification behavior. If the hostname verifier you supply does not effectively supply the same checks, you may be removing the security assurances that TLS aims to provide.
This method should not be used to avoid hostname verification, even during testing, since
AbstractManagedChannelImplBuilder.overrideAuthority(java.lang.String) is a safer alternative as it does not disable any security checks.
OkHostnameVerifierpublic final OkHttpChannelBuilder connectionSpec(ConnectionSpec connectionSpec)
By default a modern, HTTP/2-compatible spec will be used.
This method is only used when building a secure connection. For plaintext
connection, use usePlaintext() instead.
IllegalArgumentException - If connectionSpec is not with TLS@Deprecated public final OkHttpChannelBuilder usePlaintext(boolean skipNegotiation)
usePlaintext() instead.negotiationType with PLAINTEXT.usePlaintext in class ManagedChannelBuilder<OkHttpChannelBuilder>skipNegotiation - @{code true} if there is a priori knowledge that the endpoint supports
plaintext, false if plaintext use must be negotiated.public final OkHttpChannelBuilder usePlaintext()
usePlaintext in class ManagedChannelBuilder<OkHttpChannelBuilder>public final OkHttpChannelBuilder useTransportSecurity()
With TLS enabled, a default SSLSocketFactory is created using the best Provider available and is NOT based on SSLSocketFactory.getDefault(). To
more precisely control the TLS configuration call sslSocketFactory to override the
socket factory used.
useTransportSecurity in class ManagedChannelBuilder<OkHttpChannelBuilder>public final OkHttpChannelBuilder scheduledExecutorService(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 OkHttpChannelBuilder maxInboundMetadataSize(int bytes)
Integer.MAX_VALUE disables
the enforcement. Defaults to no limit (Integer.MAX_VALUE).
The implementation does not currently limit memory usage; this value is checked only after the metadata is decoded from the wire. It does prevent large metadata from being passed to the application.
maxInboundMetadataSize in class ManagedChannelBuilder<OkHttpChannelBuilder>bytes - the maximum size of received metadataIllegalArgumentException - if bytes is non-positive@Internal protected final io.grpc.internal.ClientTransportFactory buildTransportFactory()
buildTransportFactory in class io.grpc.internal.AbstractManagedChannelImplBuilder<OkHttpChannelBuilder>protected int getDefaultPort()
getDefaultPort in class io.grpc.internal.AbstractManagedChannelImplBuilder<OkHttpChannelBuilder>