Class DeadlineUtils

java.lang.Object
io.servicetalk.grpc.internal.DeadlineUtils

public final class DeadlineUtils extends Object
Constants and utilities related to gRPC deadlines.
See Also:
  • Field Details

    • GRPC_TIMEOUT_HEADER_KEY

      public static final CharSequence GRPC_TIMEOUT_HEADER_KEY
      HTTP header name for gRPC deadline/timeout.
    • GRPC_DEADLINE_KEY

      public static final ContextMap.Key<Long> 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_NINES
      gRPC spec requires timeout value to be 8 or fewer ASCII integer digits.
      See Also:
    • GRPC_MAX_TIMEOUT

      public static final Duration GRPC_MAX_TIMEOUT
      Maximum timeout which can be specified for a gRPC request. Note that this maximum is effectively infinite as the duration is more than 11,000 years.
  • Method Details

    • makeTimeoutHeader

      @Nullable public static CharSequence makeTimeoutHeader(@Nullable Duration timeout)
      Make a timeout header value from the specified duration.
      Parameters:
      timeout - the timeout Duration
      Returns:
      The timeout header text value or null for infinite timeouts
    • readTimeoutHeader

      @Nullable public static Duration readTimeoutHeader(HttpRequestMetaData request)
      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

      @Nullable public static Duration readTimeoutHeader(HttpHeaders headers)
      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 of GRPC_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