public final class GrpcUtil extends Object
Modifier and Type | Class and Description |
---|---|
static class |
GrpcUtil.Http2Error
All error codes identified by the HTTP/2 spec.
|
Modifier and Type | Field and Description |
---|---|
static com.google.common.base.Splitter |
ACCEPT_ENCODING_SPLITTER |
static 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 . |
static String |
CONTENT_ACCEPT_ENCODING
The accepted content-encodings that can be used to compress the full gRPC stream.
|
static Metadata.Key<byte[]> |
CONTENT_ACCEPT_ENCODING_KEY
Metadata.Key for the stream's accepted content encoding header. |
static String |
CONTENT_ENCODING
The content-encoding used to compress the full gRPC stream.
|
static Metadata.Key<String> |
CONTENT_ENCODING_KEY
Metadata.Key for the stream's content encoding header. |
static String |
CONTENT_TYPE_GRPC
Content-Type used for GRPC-over-HTTP/2.
|
static Metadata.Key<String> |
CONTENT_TYPE_KEY
Metadata.Key for the Content-Type request/response header. |
static long |
DEFAULT_KEEPALIVE_TIME_NANOS
The default delay in nanos before we send a keepalive.
|
static long |
DEFAULT_KEEPALIVE_TIMEOUT_NANOS
The default timeout in nanos for a keepalive ping request.
|
static String |
DEFAULT_LB_POLICY
The very default load-balancing policy.
|
static int |
DEFAULT_MAX_HEADER_LIST_SIZE
The default maximum size (in bytes) for inbound header/trailer.
|
static int |
DEFAULT_MAX_MESSAGE_SIZE
The default maximum uncompressed size (in bytes) for inbound messages.
|
static int |
DEFAULT_PORT_PLAINTEXT
The default port for plain-text connections.
|
static int |
DEFAULT_PORT_SSL
The default port for SSL connections.
|
static ProxyDetector |
DEFAULT_PROXY_DETECTOR
The default proxy detector.
|
static long |
DEFAULT_SERVER_KEEPALIVE_TIME_NANOS
The default delay in nanos for server keepalive.
|
static long |
DEFAULT_SERVER_KEEPALIVE_TIMEOUT_NANOS
The default timeout in nanos for a server keepalive ping request.
|
static String |
HTTP_METHOD
The HTTP method used for GRPC requests.
|
static boolean |
IS_RESTRICTED_APPENGINE |
static long |
KEEPALIVE_TIME_NANOS_DISABLED
The magic keepalive time value that disables client keepalive.
|
static String |
MESSAGE_ACCEPT_ENCODING
The accepted message encodings (i.e.
|
static Metadata.Key<byte[]> |
MESSAGE_ACCEPT_ENCODING_KEY
Metadata.Key for the accepted message encodings header. |
static String |
MESSAGE_ENCODING
The message encoding (i.e.
|
static Metadata.Key<String> |
MESSAGE_ENCODING_KEY
Metadata.Key for the message encoding header. |
static ProxyDetector |
NOOP_PROXY_DETECTOR
A proxy detector that always claims no proxy is needed.
|
static long |
SERVER_KEEPALIVE_TIME_NANOS_DISABLED
The magic keepalive time value that disables keepalive.
|
static SharedResourceHolder.Resource<Executor> |
SHARED_CHANNEL_EXECUTOR
Shared executor for channels.
|
static com.google.common.base.Supplier<com.google.common.base.Stopwatch> |
STOPWATCH_SUPPLIER
The factory of default Stopwatches.
|
static Metadata.Key<String> |
TE_HEADER
Metadata.Key for the Transfer encoding. |
static String |
TE_TRAILERS
The TE (transport encoding) header for requests over HTTP/2.
|
static String |
TIMEOUT
The Timeout header name.
|
static Metadata.Key<Long> |
TIMEOUT_KEY
Metadata.Key for the timeout header. |
static SharedResourceHolder.Resource<ScheduledExecutorService> |
TIMER_SERVICE
Shared single-threaded executor for managing channel timers.
|
static Charset |
US_ASCII |
static Metadata.Key<String> |
USER_AGENT_KEY
Metadata.Key for the Content-Type request/response header. |
Modifier and Type | Method and Description |
---|---|
static 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)
Verify
authority is valid for use with gRPC. |
static void |
closeQuietly(InputStream message)
Closes an InputStream, ignoring IOExceptions.
|
static ProxyDetector |
getDefaultProxyDetector()
Returns a proxy detector appropriate for the current environment.
|
static String |
getGrpcUserAgent(String transportName,
String applicationUserAgent)
Gets the User-Agent string for the gRPC transport.
|
static String |
getHost(InetSocketAddress addr)
Returns the host via
InetSocketAddress.getHostString() if it is possible,
i.e. |
static ThreadFactory |
getThreadFactory(String nameFormat,
boolean daemon)
Get a
ThreadFactory 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 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.
|
public static final Charset US_ASCII
public static final boolean IS_RESTRICTED_APPENGINE
public static final Metadata.Key<Long> TIMEOUT_KEY
Metadata.Key
for the timeout header.public static final Metadata.Key<String> MESSAGE_ENCODING_KEY
Metadata.Key
for the message encoding header.public static final Metadata.Key<byte[]> MESSAGE_ACCEPT_ENCODING_KEY
Metadata.Key
for the accepted message encodings header.public static final Metadata.Key<String> CONTENT_ENCODING_KEY
Metadata.Key
for the stream's content encoding header.public static final Metadata.Key<byte[]> CONTENT_ACCEPT_ENCODING_KEY
Metadata.Key
for the stream's accepted content encoding header.public static final Metadata.Key<String> CONTENT_TYPE_KEY
Metadata.Key
for the Content-Type request/response header.public static final Metadata.Key<String> TE_HEADER
Metadata.Key
for the Transfer encoding.public static final Metadata.Key<String> USER_AGENT_KEY
Metadata.Key
for the Content-Type request/response header.public static final int DEFAULT_PORT_PLAINTEXT
public static final int DEFAULT_PORT_SSL
public static final String CONTENT_TYPE_GRPC
public static final String HTTP_METHOD
public static final String TE_TRAILERS
public static final String TIMEOUT
public static final String MESSAGE_ENCODING
public static final String MESSAGE_ACCEPT_ENCODING
public static final String CONTENT_ENCODING
public static final String CONTENT_ACCEPT_ENCODING
public static final int DEFAULT_MAX_MESSAGE_SIZE
public static final int DEFAULT_MAX_HEADER_LIST_SIZE
public static final com.google.common.base.Splitter ACCEPT_ENCODING_SPLITTER
public static final long DEFAULT_KEEPALIVE_TIME_NANOS
public static final long DEFAULT_KEEPALIVE_TIMEOUT_NANOS
public static final long KEEPALIVE_TIME_NANOS_DISABLED
public static final long DEFAULT_SERVER_KEEPALIVE_TIME_NANOS
public static final long DEFAULT_SERVER_KEEPALIVE_TIMEOUT_NANOS
public static final long SERVER_KEEPALIVE_TIME_NANOS_DISABLED
public static final ProxyDetector DEFAULT_PROXY_DETECTOR
public static final ProxyDetector NOOP_PROXY_DETECTOR
public static final String DEFAULT_LB_POLICY
public static final CallOptions.Key<Boolean> CALL_OPTIONS_RPC_OWNED_BY_BALANCER
LoadBalancer.Subchannel.asChannel()
will have this option with value true
. They will be treated differently from
the ones created by application.public static final SharedResourceHolder.Resource<Executor> SHARED_CHANNEL_EXECUTOR
public static final SharedResourceHolder.Resource<ScheduledExecutorService> TIMER_SERVICE
public static final com.google.common.base.Supplier<com.google.common.base.Stopwatch> STOPWATCH_SUPPLIER
public static boolean shouldBeCountedForInUse(CallOptions callOptions)
public static ProxyDetector getDefaultProxyDetector()
public static Status httpStatusToGrpcStatus(int httpStatusCode)
status.isOk()
is
true
.public static boolean isGrpcContentType(String contentType)
public static String getGrpcUserAgent(String transportName, @Nullable String applicationUserAgent)
public static URI authorityToUri(String authority)
public static String checkAuthority(String authority)
authority
is valid for use with gRPC. The syntax must be valid and it must not
include userinfo.authority
providedpublic static String authorityFromHostAndPort(String host, int port)
public static ThreadFactory getThreadFactory(String nameFormat, boolean daemon)
ThreadFactory
suitable for use in the current environment.nameFormat
- to apply to threads created by the factory.daemon
- true
if the threads the factory creates are daemon threads, false
otherwise.ThreadFactory
.public static String getHost(InetSocketAddress addr)
InetSocketAddress.getHostString()
if it is possible,
i.e. in jdk >= 7.
Otherwise, return it via InetSocketAddress.getHostName()
which may incur a DNS lookup.public static void closeQuietly(@Nullable InputStream message)
Closeables.closeQuietly()
is beta.Copyright © 2019. All rights reserved.