Class OkHttpPendingResult<T,​R extends ApiResponse<T>>

java.lang.Object
ai.nextbillion.maps.internal.OkHttpPendingResult<T,​R>
All Implemented Interfaces:
PendingResult<T>, okhttp3.Callback

public class OkHttpPendingResult<T,​R extends ApiResponse<T>>
extends java.lang.Object
implements PendingResult<T>, okhttp3.Callback
A PendingResult backed by a HTTP call executed by OkHttp, a deserialization step using Gson, rate limiting and a retry policy.

T is the type of the result of this pending result, and R is the type of the request.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface ai.nextbillion.maps.PendingResult

    PendingResult.Callback<T>
  • Constructor Summary

    Constructors 
    Constructor Description
    OkHttpPendingResult​(okhttp3.Request request, okhttp3.OkHttpClient client, java.lang.Class<R> responseClass, com.google.gson.FieldNamingPolicy fieldNamingPolicy, long errorTimeOut, java.lang.Integer maxRetries, ExceptionsAllowedToRetry exceptionsAllowedToRetry, RequestMetrics metrics)  
  • Method Summary

    Modifier and Type Method Description
    T await()
    Performs the request synchronously.
    T awaitIgnoreError()
    Performs the request synchronously, ignoring exceptions while performing the request and errors returned by the server.
    void cancel()
    Attempts to cancel the request.
    void onFailure​(okhttp3.Call call, java.io.IOException ioe)  
    void onResponse​(okhttp3.Call call, okhttp3.Response response)  
    void setCallback​(PendingResult.Callback<T> callback)
    Performs the request asynchronously, calling onResult or onFailure after the request has been completed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • OkHttpPendingResult

      public OkHttpPendingResult​(okhttp3.Request request, okhttp3.OkHttpClient client, java.lang.Class<R> responseClass, com.google.gson.FieldNamingPolicy fieldNamingPolicy, long errorTimeOut, java.lang.Integer maxRetries, ExceptionsAllowedToRetry exceptionsAllowedToRetry, RequestMetrics metrics)
      Parameters:
      request - HTTP request to execute.
      client - The client used to execute the request.
      responseClass - Model class to unmarshal JSON body content.
      fieldNamingPolicy - FieldNamingPolicy for unmarshaling JSON.
      errorTimeOut - Number of milliseconds to re-send erroring requests.
      maxRetries - Number of times allowed to re-send erroring requests.
      exceptionsAllowedToRetry - The exceptions to retry.
      metrics - metrics
  • Method Details

    • setCallback

      public void setCallback​(PendingResult.Callback<T> callback)
      Description copied from interface: PendingResult
      Performs the request asynchronously, calling onResult or onFailure after the request has been completed.
      Specified by:
      setCallback in interface PendingResult<T>
      Parameters:
      callback - The callback to call on completion.
    • await

      public T await() throws ApiException, java.io.IOException, java.lang.InterruptedException
      Description copied from interface: PendingResult
      Performs the request synchronously.
      Specified by:
      await in interface PendingResult<T>
      Returns:
      The result.
      Throws:
      ApiException - Thrown if the API Returned result is an error.
      java.io.IOException - Thrown when an I/O exception of some sort has occurred.
      java.lang.InterruptedException - Thrown when a thread is waiting, sleeping, or otherwise occupied, and the thread is interrupted.
    • awaitIgnoreError

      public T awaitIgnoreError()
      Description copied from interface: PendingResult
      Performs the request synchronously, ignoring exceptions while performing the request and errors returned by the server.
      Specified by:
      awaitIgnoreError in interface PendingResult<T>
      Returns:
      The result, or null if there was any error or exception ignored.
    • cancel

      public void cancel()
      Description copied from interface: PendingResult
      Attempts to cancel the request.
      Specified by:
      cancel in interface PendingResult<T>
    • onFailure

      public void onFailure​(okhttp3.Call call, java.io.IOException ioe)
      Specified by:
      onFailure in interface okhttp3.Callback
    • onResponse

      public void onResponse​(okhttp3.Call call, okhttp3.Response response) throws java.io.IOException
      Specified by:
      onResponse in interface okhttp3.Callback
      Throws:
      java.io.IOException