Class DeadlineUtils

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long EIGHT_NINES
      gRPC spec requires timeout value to be 8 or fewer ASCII integer digits.
      static AsyncContextMap.Key<java.lang.Long> GRPC_DEADLINE_KEY
      gRPC timeout is stored in 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 java.time.Duration GRPC_MAX_TIMEOUT
      Maximum timeout which can be specified for a gRPC request.
      static java.lang.CharSequence GRPC_TIMEOUT_HEADER_KEY
      HTTP header name for gRPC deadline/timeout.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.CharSequence makeTimeoutHeader​(java.time.Duration timeout)
      Make a timeout header value from the specified duration.
      static java.time.Duration parseTimeoutHeader​(java.lang.CharSequence grpcTimeoutValue)
      Parse a gRPC timeout header value as a duration.
      static java.time.Duration readTimeoutHeader​(HttpHeaders headers)
      Extract the timeout duration from the HTTP headers if present.
      static java.time.Duration readTimeoutHeader​(HttpRequestMetaData request)
      Extract the timeout duration from the request HTTP headers if present.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • GRPC_TIMEOUT_HEADER_KEY

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

        public static final AsyncContextMap.Key<java.lang.Long> GRPC_DEADLINE_KEY
        gRPC timeout is stored in 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:
        Constant Field Values
      • GRPC_MAX_TIMEOUT

        public static final java.time.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 Detail

      • makeTimeoutHeader

        @Nullable
        public static java.lang.CharSequence makeTimeoutHeader​(@Nullable
                                                               java.time.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 java.time.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:
        java.lang.IllegalArgumentException - if the timeout value is malformed
      • readTimeoutHeader

        @Nullable
        public static java.time.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:
        java.lang.IllegalArgumentException - if the timeout value is malformed
      • parseTimeoutHeader

        public static java.time.Duration parseTimeoutHeader​(java.lang.CharSequence grpcTimeoutValue)
                                                     throws java.lang.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:
        java.lang.IllegalArgumentException - if the timeout value is malformed