Class ResponseBinary

  • All Implemented Interfaces:
    Serializable

    public abstract class ResponseBinary
    extends Object
    implements Serializable
    This is a helper class for transporting a http response. We cannot use the okhttp3.Response object as its main payload can only be consumed once and must be closed as soon as possible to prevent holding on to connection resources. This class will hold both the binary response payload as well as its metadata.
    See Also:
    Serialized Form
    • Constructor Detail

      • ResponseBinary

        public ResponseBinary()
    • Method Detail

      • of

        public static ResponseBinary of​(okhttp3.Response response,
                                        com.google.protobuf.ByteString body)
      • getResponse

        public abstract okhttp3.Response getResponse()
        Returns the original Response (less the body) with metadata and header values.
        Returns:
        The response metadata
      • getResponseBodyBytes

        public abstract com.google.protobuf.ByteString getResponseBodyBytes()
        Returns the main body of the response.
        Returns:
        The main body of the response.
      • getApiRetryCounter

        public abstract int getApiRetryCounter()
      • getApiLatency

        @Nullable
        public abstract Long getApiLatency()
        Returns the measured latency in getting the first response from the api. The latency is calculated by measuring the duration between sending the request to the api and receiving (but not processing) the response.
        Returns:
        The measured api latency in milliseconds for producing this response.
      • getApiJobQueueDurationMillies

        @Nullable
        public abstract Long getApiJobQueueDurationMillies()
        Returns the measured queue duration of an async api request. These requests typically represent potentially long-running jobs like contextualization tasks (entity matching, P&ID parsing, etc.). Async api requests first enter a job queue before they are processed by a worker. If the queue duration grows over time, it is a sign that the api is unable to scale up to meet the request demand.
        Returns:
        The job queue duration in milliseconds.
      • getApiJobDurationMillies

        @Nullable
        public abstract Long getApiJobDurationMillies()
        Returns the measured job duration of an async api request. These requests typically represent potentially long-running jobs like contextualization tasks (entity matching, P&ID parsing, etc.).
        Returns:
        The job duration in milliseconds.
      • withApiRetryCounter

        public ResponseBinary withApiRetryCounter​(int count)
      • withApiLatency

        public ResponseBinary withApiLatency​(long latency)
      • withApiJobQueueDuration

        public ResponseBinary withApiJobQueueDuration​(long millies)
        Set the api job queue duration (in milliseconds) associated with this response. Only applicable for async api calls.
        Parameters:
        millies - the api queue duration in milliseconds.
        Returns:
        The ResponseBinary with the queue duration.
      • withApiJobDuration

        public ResponseBinary withApiJobDuration​(long millies)
        Set the api job duration (in milliseconds) associated with this response. Only applicable for async api calls.
        Parameters:
        millies - the api job duration in milliseconds.
        Returns:
        The ResponseBinary with the job duration.