Package io.grpc.internal
Class GrpcUtil
java.lang.Object
io.grpc.internal.GrpcUtil
Common utilities for GRPC.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Percent encode theauthority
based on https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.static final class
static enum
All error codes identified by the HTTP/2 spec. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.google.common.base.Splitter
static final CallOptions.Key
<Boolean> RPCs created on the Channel returned byLoadBalancer.Subchannel.asChannel()
will have this option with valuetrue
.static final String
The accepted content-encodings that can be used to compress the full gRPC stream.static final Metadata.Key
<byte[]> Metadata.Key
for the stream's accepted content encoding header.static final String
The content-encoding used to compress the full gRPC stream.static final Metadata.Key
<String> Metadata.Key
for the stream's content encoding header.static final String
Content-Type used for GRPC-over-HTTP/2.static final Metadata.Key
<String> Metadata.Key
for the Content-Type request/response header.static final long
The default timeout in nanos for a keepalive ping request.static final String
The very default load-balancing policy.static final int
The default maximum size (in bytes) for inbound header/trailer.static final int
The default maximum uncompressed size (in bytes) for inbound messages.static final int
The default port for plain-text connections.static final int
The default port for SSL connections.static final ProxyDetector
The default proxy detector.static final long
The default delay in nanos for server keepalive.static final long
The default timeout in nanos for a server keepalive ping request.static final String
The HTTP method used for GRPC requests.static final String
static final long
The magic keepalive time value that disables client keepalive.static final String
The accepted message encodings (i.e.static final Metadata.Key
<byte[]> Metadata.Key
for the accepted message encodings header.static final String
The message encoding (i.e.static final Metadata.Key
<String> Metadata.Key
for the message encoding header.static final ProxyDetector
A proxy detector that always claims no proxy is needed.static final long
The magic keepalive time value that disables keepalive.static final SharedResourceHolder.Resource
<Executor> Shared executor for channels.static final com.google.common.base.Supplier
<com.google.common.base.Stopwatch> The factory of default Stopwatches.static final Metadata.Key
<String> Metadata.Key
for the Transfer encoding.static final String
The TE (transport encoding) header for requests over HTTP/2.static final String
The Timeout header name.static final Metadata.Key
<Long> Metadata.Key
for the timeout header.static final SharedResourceHolder.Resource
<ScheduledExecutorService> Shared single-threaded executor for managing channel timers.static final Charset
static final Metadata.Key
<String> Metadata.Key
for the Content-Type request/response header. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
authorityFromHostAndPort
(String host, int port) Combine a host and port into an authority string.static URI
authorityToUri
(String authority) Parse an authority into a URI for retrieving the host and port.static String
checkAuthority
(String authority) Verifyauthority
is valid for use with gRPC.static void
closeQuietly
(Closeable message) Closes a Closeable, ignoring IOExceptions.static void
exhaust
(InputStream in) Readsin
until end of stream.static ClientStreamTracer[]
getClientStreamTracers
(CallOptions callOptions, Metadata headers, int previousAttempts, boolean isTransparentRetry) Gets stream tracers based on CallOptions.static boolean
static GrpcUtil.GrpcBuildVersion
Returns the build version of gRPC.static String
getGrpcUserAgent
(String transportName, String applicationUserAgent) Gets the User-Agent string for the gRPC transport.static ThreadFactory
getThreadFactory
(String nameFormat, boolean daemon) Get aThreadFactory
suitable for use in the current environment.static Status
httpStatusToGrpcStatus
(int httpStatusCode) Maps HTTP error response status codes to transport codes, as defined in http-grpc-status-mapping.md.static boolean
isGrpcContentType
(String contentType) Indicates whether or not the given value is a valid gRPC content-type.static Status
Some status codes from the control plane are not appropritate to use in the data plane.static boolean
shouldBeCountedForInUse
(CallOptions callOptions) Returns true if an RPC with the given properties should be counted when calculating the in-use state of a transport.
-
Field Details
-
US_ASCII
-
TIMEOUT_KEY
Metadata.Key
for the timeout header. -
MESSAGE_ENCODING_KEY
Metadata.Key
for the message encoding header. -
MESSAGE_ACCEPT_ENCODING_KEY
Metadata.Key
for the accepted message encodings header. -
CONTENT_ENCODING_KEY
Metadata.Key
for the stream's content encoding header. -
CONTENT_ACCEPT_ENCODING_KEY
Metadata.Key
for the stream's accepted content encoding header. -
CONTENT_TYPE_KEY
Metadata.Key
for the Content-Type request/response header. -
TE_HEADER
Metadata.Key
for the Transfer encoding. -
USER_AGENT_KEY
Metadata.Key
for the Content-Type request/response header. -
DEFAULT_PORT_PLAINTEXT
public static final int DEFAULT_PORT_PLAINTEXTThe default port for plain-text connections.- See Also:
-
DEFAULT_PORT_SSL
public static final int DEFAULT_PORT_SSLThe default port for SSL connections.- See Also:
-
CONTENT_TYPE_GRPC
Content-Type used for GRPC-over-HTTP/2.- See Also:
-
HTTP_METHOD
The HTTP method used for GRPC requests.- See Also:
-
TE_TRAILERS
The TE (transport encoding) header for requests over HTTP/2.- See Also:
-
TIMEOUT
The Timeout header name.- See Also:
-
MESSAGE_ENCODING
The message encoding (i.e. compression) that can be used in the stream.- See Also:
-
MESSAGE_ACCEPT_ENCODING
The accepted message encodings (i.e. compression) that can be used in the stream.- See Also:
-
CONTENT_ENCODING
The content-encoding used to compress the full gRPC stream.- See Also:
-
CONTENT_ACCEPT_ENCODING
The accepted content-encodings that can be used to compress the full gRPC stream.- See Also:
-
DEFAULT_MAX_MESSAGE_SIZE
public static final int DEFAULT_MAX_MESSAGE_SIZEThe default maximum uncompressed size (in bytes) for inbound messages. Defaults to 4 MiB.- See Also:
-
DEFAULT_MAX_HEADER_LIST_SIZE
public static final int DEFAULT_MAX_HEADER_LIST_SIZEThe default maximum size (in bytes) for inbound header/trailer.- See Also:
-
ACCEPT_ENCODING_SPLITTER
public static final com.google.common.base.Splitter ACCEPT_ENCODING_SPLITTER -
IMPLEMENTATION_VERSION
- See Also:
-
DEFAULT_KEEPALIVE_TIMEOUT_NANOS
public static final long DEFAULT_KEEPALIVE_TIMEOUT_NANOSThe default timeout in nanos for a keepalive ping request. -
KEEPALIVE_TIME_NANOS_DISABLED
public static final long KEEPALIVE_TIME_NANOS_DISABLEDThe magic keepalive time value that disables client keepalive.- See Also:
-
DEFAULT_SERVER_KEEPALIVE_TIME_NANOS
public static final long DEFAULT_SERVER_KEEPALIVE_TIME_NANOSThe default delay in nanos for server keepalive. -
DEFAULT_SERVER_KEEPALIVE_TIMEOUT_NANOS
public static final long DEFAULT_SERVER_KEEPALIVE_TIMEOUT_NANOSThe default timeout in nanos for a server keepalive ping request. -
SERVER_KEEPALIVE_TIME_NANOS_DISABLED
public static final long SERVER_KEEPALIVE_TIME_NANOS_DISABLEDThe magic keepalive time value that disables keepalive.- See Also:
-
DEFAULT_PROXY_DETECTOR
The default proxy detector. -
NOOP_PROXY_DETECTOR
A proxy detector that always claims no proxy is needed. -
DEFAULT_LB_POLICY
The very default load-balancing policy.- See Also:
-
CALL_OPTIONS_RPC_OWNED_BY_BALANCER
RPCs created on the Channel returned byLoadBalancer.Subchannel.asChannel()
will have this option with valuetrue
. They will be treated differently from the ones created by application. -
SHARED_CHANNEL_EXECUTOR
Shared executor for channels. -
TIMER_SERVICE
Shared single-threaded executor for managing channel timers. -
STOPWATCH_SUPPLIER
public static final com.google.common.base.Supplier<com.google.common.base.Stopwatch> STOPWATCH_SUPPLIERThe factory of default Stopwatches.
-
-
Method Details
-
shouldBeCountedForInUse
Returns true if an RPC with the given properties should be counted when calculating the in-use state of a transport. -
httpStatusToGrpcStatus
Maps HTTP error response status codes to transport codes, as defined in http-grpc-status-mapping.md. Never returns a status for whichstatus.isOk()
istrue
. -
isGrpcContentType
Indicates whether or not the given value is a valid gRPC content-type. -
getGrpcUserAgent
Gets the User-Agent string for the gRPC transport. -
getGrpcBuildVersion
Returns the build version of gRPC. -
authorityToUri
Parse an authority into a URI for retrieving the host and port. -
checkAuthority
Verifyauthority
is valid for use with gRPC. The syntax must be valid and it must not include userinfo.- Returns:
- the
authority
provided
-
authorityFromHostAndPort
Combine a host and port into an authority string. -
getThreadFactory
Get aThreadFactory
suitable for use in the current environment.- Parameters:
nameFormat
- to apply to threads created by the factory.daemon
-true
if the threads the factory creates are daemon threads,false
otherwise.- Returns:
- a
ThreadFactory
.
-
getClientStreamTracers
public static ClientStreamTracer[] getClientStreamTracers(CallOptions callOptions, Metadata headers, int previousAttempts, boolean isTransparentRetry) Gets stream tracers based on CallOptions. -
closeQuietly
Closes a Closeable, ignoring IOExceptions. This method exists because Guava'sCloseables.closeQuietly()
is beta. -
exhaust
Readsin
until end of stream.- Throws:
IOException
-
replaceInappropriateControlPlaneStatus
Some status codes from the control plane are not appropritate to use in the data plane. If one is given it will be replaced with INTERNAL, indicating a bug in the control plane implementation. -
getFlag
-