Class GrpcUtil

java.lang.Object
io.grpc.internal.GrpcUtil

public final class GrpcUtil extends Object
Common utilities for GRPC.
  • Field Details

    • US_ASCII

      public static final Charset US_ASCII
    • TIMEOUT_KEY

      public static final Metadata.Key<Long> TIMEOUT_KEY
      Metadata.Key for the timeout header.
    • MESSAGE_ENCODING_KEY

      public static final Metadata.Key<String> MESSAGE_ENCODING_KEY
      Metadata.Key for the message encoding header.
    • MESSAGE_ACCEPT_ENCODING_KEY

      public static final Metadata.Key<byte[]> MESSAGE_ACCEPT_ENCODING_KEY
      Metadata.Key for the accepted message encodings header.
    • CONTENT_ENCODING_KEY

      public static final Metadata.Key<String> CONTENT_ENCODING_KEY
      Metadata.Key for the stream's content encoding header.
    • CONTENT_ACCEPT_ENCODING_KEY

      public static final Metadata.Key<byte[]> CONTENT_ACCEPT_ENCODING_KEY
      Metadata.Key for the stream's accepted content encoding header.
    • CONTENT_TYPE_KEY

      public static final Metadata.Key<String> CONTENT_TYPE_KEY
      Metadata.Key for the Content-Type request/response header.
    • TE_HEADER

      public static final Metadata.Key<String> TE_HEADER
      Metadata.Key for the Transfer encoding.
    • USER_AGENT_KEY

      public static final Metadata.Key<String> USER_AGENT_KEY
      Metadata.Key for the Content-Type request/response header.
    • DEFAULT_PORT_PLAINTEXT

      public static final int DEFAULT_PORT_PLAINTEXT
      The default port for plain-text connections.
      See Also:
    • DEFAULT_PORT_SSL

      public static final int DEFAULT_PORT_SSL
      The default port for SSL connections.
      See Also:
    • CONTENT_TYPE_GRPC

      public static final String CONTENT_TYPE_GRPC
      Content-Type used for GRPC-over-HTTP/2.
      See Also:
    • HTTP_METHOD

      public static final String HTTP_METHOD
      The HTTP method used for GRPC requests.
      See Also:
    • TE_TRAILERS

      public static final String TE_TRAILERS
      The TE (transport encoding) header for requests over HTTP/2.
      See Also:
    • TIMEOUT

      public static final String TIMEOUT
      The Timeout header name.
      See Also:
    • MESSAGE_ENCODING

      public static final String MESSAGE_ENCODING
      The message encoding (i.e. compression) that can be used in the stream.
      See Also:
    • MESSAGE_ACCEPT_ENCODING

      public static final String MESSAGE_ACCEPT_ENCODING
      The accepted message encodings (i.e. compression) that can be used in the stream.
      See Also:
    • CONTENT_ENCODING

      public static final String CONTENT_ENCODING
      The content-encoding used to compress the full gRPC stream.
      See Also:
    • CONTENT_ACCEPT_ENCODING

      public static final String 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_SIZE
      The 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_SIZE
      The 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

      public static final String IMPLEMENTATION_VERSION
      See Also:
    • DEFAULT_KEEPALIVE_TIMEOUT_NANOS

      public static final long DEFAULT_KEEPALIVE_TIMEOUT_NANOS
      The default timeout in nanos for a keepalive ping request.
    • KEEPALIVE_TIME_NANOS_DISABLED

      public static final long KEEPALIVE_TIME_NANOS_DISABLED
      The magic keepalive time value that disables client keepalive.
      See Also:
    • DEFAULT_SERVER_KEEPALIVE_TIME_NANOS

      public static final long DEFAULT_SERVER_KEEPALIVE_TIME_NANOS
      The default delay in nanos for server keepalive.
    • DEFAULT_SERVER_KEEPALIVE_TIMEOUT_NANOS

      public static final long DEFAULT_SERVER_KEEPALIVE_TIMEOUT_NANOS
      The default timeout in nanos for a server keepalive ping request.
    • SERVER_KEEPALIVE_TIME_NANOS_DISABLED

      public static final long SERVER_KEEPALIVE_TIME_NANOS_DISABLED
      The magic keepalive time value that disables keepalive.
      See Also:
    • DEFAULT_PROXY_DETECTOR

      public static final ProxyDetector DEFAULT_PROXY_DETECTOR
      The default proxy detector.
    • NOOP_PROXY_DETECTOR

      public static final ProxyDetector NOOP_PROXY_DETECTOR
      A proxy detector that always claims no proxy is needed.
    • DEFAULT_LB_POLICY

      public static final String DEFAULT_LB_POLICY
      The very default load-balancing policy.
      See Also:
    • CALL_OPTIONS_RPC_OWNED_BY_BALANCER

      public static final CallOptions.Key<Boolean> CALL_OPTIONS_RPC_OWNED_BY_BALANCER
      RPCs created on the Channel returned by LoadBalancer.Subchannel.asChannel() will have this option with value true. They will be treated differently from the ones created by application.
    • SHARED_CHANNEL_EXECUTOR

      public static final SharedResourceHolder.Resource<Executor> SHARED_CHANNEL_EXECUTOR
      Shared executor for channels.
    • TIMER_SERVICE

      public static final SharedResourceHolder.Resource<ScheduledExecutorService> 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_SUPPLIER
      The factory of default Stopwatches.
  • Method Details

    • shouldBeCountedForInUse

      public 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.
    • httpStatusToGrpcStatus

      public static Status httpStatusToGrpcStatus(int httpStatusCode)
      Maps HTTP error response status codes to transport codes, as defined in http-grpc-status-mapping.md. Never returns a status for which status.isOk() is true.
    • isGrpcContentType

      public static boolean isGrpcContentType(String contentType)
      Indicates whether or not the given value is a valid gRPC content-type.
    • getGrpcUserAgent

      public static String getGrpcUserAgent(String transportName, @Nullable String applicationUserAgent)
      Gets the User-Agent string for the gRPC transport.
    • getGrpcBuildVersion

      public static GrpcUtil.GrpcBuildVersion getGrpcBuildVersion()
      Returns the build version of gRPC.
    • authorityToUri

      public static URI authorityToUri(String authority)
      Parse an authority into a URI for retrieving the host and port.
    • checkAuthority

      public static String checkAuthority(String authority)
      Verify authority is valid for use with gRPC. The syntax must be valid and it must not include userinfo.
      Returns:
      the authority provided
    • authorityFromHostAndPort

      public static String authorityFromHostAndPort(String host, int port)
      Combine a host and port into an authority string.
    • getThreadFactory

      public static ThreadFactory getThreadFactory(String nameFormat, boolean daemon)
      Get a ThreadFactory 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

      public static void closeQuietly(@Nullable Closeable message)
      Closes a Closeable, ignoring IOExceptions. This method exists because Guava's Closeables.closeQuietly() is beta.
    • exhaust

      public static void exhaust(InputStream in) throws IOException
      Reads in until end of stream.
      Throws:
      IOException
    • replaceInappropriateControlPlaneStatus

      public static Status replaceInappropriateControlPlaneStatus(Status status)
      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

      public static boolean getFlag(String envVarName, boolean enableByDefault)