Package io.grpc.internal
Class GrpcUtil
java.lang.Object
io.grpc.internal.GrpcUtil
Common utilities for GRPC.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classstatic classPercent encode theauthoritybased on https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.static final classstatic enumAll error codes identified by the HTTP/2 spec.(package private) static classMarshals a nanoseconds representation of the timeout to and from a string representation, consisting of an ASCII decimal representation of a number with at most 8 digits, followed by a unit. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.google.common.base.Splitterstatic final CallOptions.Key<Boolean> RPCs created on the Channel returned byLoadBalancer.Subchannel.asChannel()will have this option with valuetrue.static final StringThe accepted content-encodings that can be used to compress the full gRPC stream.static final Metadata.Key<byte[]> Metadata.Keyfor the stream's accepted content encoding header.static final StringThe content-encoding used to compress the full gRPC stream.static final Metadata.Key<String> Metadata.Keyfor the stream's content encoding header.(package private) static final Metadata.Key<String> static final StringContent-Type used for GRPC-over-HTTP/2.static final Metadata.Key<String> Metadata.Keyfor the Content-Type request/response header.static final longThe default timeout in nanos for a keepalive ping request.static final StringThe very default load-balancing policy.static final intThe default maximum size (in bytes) for inbound header/trailer.static final intThe default maximum uncompressed size (in bytes) for inbound messages.static final intThe default port for plain-text connections.static final intThe default port for SSL connections.static final ProxyDetectorThe default proxy detector.static final longThe default delay in nanos for server keepalive.static final longThe default timeout in nanos for a server keepalive ping request.static final StringThe HTTP method used for GRPC requests.static final Stringprivate static final Set<Status.Code> static final longThe magic keepalive time value that disables client keepalive.private static final Loggerstatic final StringThe accepted message encodings (i.e.static final Metadata.Key<byte[]> Metadata.Keyfor the accepted message encodings header.static final StringThe message encoding (i.e.static final Metadata.Key<String> Metadata.Keyfor the message encoding header.static final ProxyDetectorA proxy detector that always claims no proxy is needed.private static final ClientStreamTracerstatic final longThe 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.Keyfor the Transfer encoding.static final StringThe TE (transport encoding) header for requests over HTTP/2.static final StringThe Timeout header name.static final Metadata.Key<Long> Metadata.Keyfor the timeout header.static final SharedResourceHolder.Resource<ScheduledExecutorService> Shared single-threaded executor for managing channel timers.static final Charsetstatic final Metadata.Key<String> Metadata.Keyfor the Content-Type request/response header. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringauthorityFromHostAndPort(String host, int port) Combine a host and port into an authority string.static URIauthorityToUri(String authority) Parse an authority into a URI for retrieving the host and port.static StringcheckAuthority(String authority) Verifyauthorityis valid for use with gRPC.(package private) static voidcloseQuietly(StreamListener.MessageProducer producer) Quietly closes all messages in MessageProducer.static voidcloseQuietly(Closeable message) Closes a Closeable, ignoring IOExceptions.static voidexhaust(InputStream in) Readsinuntil end of stream.static ClientStreamTracer[]getClientStreamTracers(CallOptions callOptions, Metadata headers, int previousAttempts, boolean isTransparentRetry) Gets stream tracers based on CallOptions.static booleanstatic GrpcUtil.GrpcBuildVersionReturns the build version of gRPC.static StringgetGrpcUserAgent(String transportName, String applicationUserAgent) Gets the User-Agent string for the gRPC transport.static ThreadFactorygetThreadFactory(String nameFormat, boolean daemon) Get aThreadFactorysuitable for use in the current environment.(package private) static ClientTransportgetTransportFromPickResult(LoadBalancer.PickResult result, boolean isWaitForReady) Returns a transport out of a PickResult, ornullif the result is "buffer".private static Status.CodehttpStatusToGrpcCode(int httpStatusCode) static StatushttpStatusToGrpcStatus(int httpStatusCode) Maps HTTP error response status codes to transport codes, as defined in http-grpc-status-mapping.md.static booleanisGrpcContentType(String contentType) Indicates whether or not the given value is a valid gRPC content-type.(package private) static <T> booleaniterableContains(Iterable<T> iterable, T item) Checks whether the given item exists in the iterable.static StatusSome status codes from the control plane are not appropritate to use in the data plane.static booleanshouldBeCountedForInUse(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
-
log
-
INAPPROPRIATE_CONTROL_PLANE_STATUS
-
US_ASCII
-
TIMEOUT_KEY
Metadata.Keyfor the timeout header. -
MESSAGE_ENCODING_KEY
Metadata.Keyfor the message encoding header. -
MESSAGE_ACCEPT_ENCODING_KEY
Metadata.Keyfor the accepted message encodings header. -
CONTENT_ENCODING_KEY
Metadata.Keyfor the stream's content encoding header. -
CONTENT_ACCEPT_ENCODING_KEY
Metadata.Keyfor the stream's accepted content encoding header. -
CONTENT_LENGTH_KEY
-
CONTENT_TYPE_KEY
Metadata.Keyfor the Content-Type request/response header. -
TE_HEADER
Metadata.Keyfor the Transfer encoding. -
USER_AGENT_KEY
Metadata.Keyfor 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. -
NOOP_TRACER
-
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.
-
-
Constructor Details
-
GrpcUtil
private GrpcUtil()
-
-
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. -
httpStatusToGrpcCode
-
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
Verifyauthorityis valid for use with gRPC. The syntax must be valid and it must not include userinfo.- Returns:
- the
authorityprovided
-
authorityFromHostAndPort
Combine a host and port into an authority string. -
getThreadFactory
Get aThreadFactorysuitable for use in the current environment.- Parameters:
nameFormat- to apply to threads created by the factory.daemon-trueif the threads the factory creates are daemon threads,falseotherwise.- Returns:
- a
ThreadFactory.
-
getTransportFromPickResult
@Nullable static ClientTransport getTransportFromPickResult(LoadBalancer.PickResult result, boolean isWaitForReady) Returns a transport out of a PickResult, ornullif the result is "buffer". -
getClientStreamTracers
public static ClientStreamTracer[] getClientStreamTracers(CallOptions callOptions, Metadata headers, int previousAttempts, boolean isTransparentRetry) Gets stream tracers based on CallOptions. -
closeQuietly
Quietly closes all messages in MessageProducer. -
closeQuietly
Closes a Closeable, ignoring IOExceptions. This method exists because Guava'sCloseables.closeQuietly()is beta. -
exhaust
Readsinuntil 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. -
iterableContains
Checks whether the given item exists in the iterable. This is copied from Guava Collect'sIterables.contains()because Guava Collect is not Android-friendly thus core can't depend on it. -
getFlag
-