Package io.servicetalk.grpc.internal
Class DeadlineUtils
java.lang.Object
io.servicetalk.grpc.internal.DeadlineUtils
Constants and utilities related to
gRPC deadlines.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final long
gRPC spec requires timeout value to be 8 or fewer ASCII integer digits.static final ContextMap.Key<Long>
gRPC timeout is stored in a context as a deadline so that when propagated to a new request the remaining time to be included in the request can be calculated.static final Duration
static final CharSequence
HTTP header name for gRPC deadline/timeout. -
Method Summary
Modifier and TypeMethodDescriptionstatic CharSequence
makeTimeoutHeader
(Duration timeout) Make a timeout header value from the specified duration.static Duration
parseTimeoutHeader
(CharSequence grpcTimeoutValue) Parse a gRPC timeout header value as a duration.static Duration
readTimeoutHeader
(HttpHeaders headers) Extract the timeout duration from the HTTP headers if present.static Duration
readTimeoutHeader
(HttpRequestMetaData request) Extract the timeout duration from the request HTTP headers if present.
-
Field Details
-
GRPC_TIMEOUT_HEADER_KEY
HTTP header name for gRPC deadline/timeout. -
GRPC_DEADLINE_KEY
gRPC timeout is stored in a context as a deadline so that when propagated to a new request the remaining time to be included in the request can be calculated. -
EIGHT_NINES
public static final long EIGHT_NINESgRPC spec requires timeout value to be 8 or fewer ASCII integer digits.- See Also:
-
GRPC_MAX_TIMEOUT
-
-
Method Details
-
makeTimeoutHeader
Make a timeout header value from the specified duration.- Parameters:
timeout
- the timeoutDuration
- Returns:
- The timeout header text value or null for infinite timeouts
-
readTimeoutHeader
Extract the timeout duration from the request HTTP headers if present.- Parameters:
request
- The HTTP request to be used as source of the GRPC timeout header- Returns:
- The non-negative timeout duration which may null if not present
- Throws:
IllegalArgumentException
- if the timeout value is malformed
-
readTimeoutHeader
Extract the timeout duration from the HTTP headers if present.- Parameters:
headers
- The HTTP headers to be used as source of the GRPC timeout header- Returns:
- The non-negative timeout duration which may null if not present
- Throws:
IllegalArgumentException
- if the timeout value is malformed
-
parseTimeoutHeader
public static Duration parseTimeoutHeader(CharSequence grpcTimeoutValue) throws IllegalArgumentException Parse a gRPC timeout header value as a duration.- Parameters:
grpcTimeoutValue
- the text value ofGRPC_TIMEOUT_HEADER_KEY
header header to be parsed to a timeout duration- Returns:
- The non-negative timeout duration
- Throws:
IllegalArgumentException
- if the timeout value is malformed
-