Package ai.nextbillion.maps.internal
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 Tawait()Performs the request synchronously.TawaitIgnoreError()Performs the request synchronously, ignoring exceptions while performing the request and errors returned by the server.voidcancel()Attempts to cancel the request.voidonFailure(okhttp3.Call call, java.io.IOException ioe)voidonResponse(okhttp3.Call call, okhttp3.Response response)voidsetCallback(PendingResult.Callback<T> callback)
-
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
Description copied from interface:PendingResultPerforms the request asynchronously, callingonResultoronFailureafter the request has been completed.- Specified by:
setCallbackin interfacePendingResult<T>- Parameters:
callback- The callback to call on completion.
-
await
Description copied from interface:PendingResultPerforms the request synchronously.- Specified by:
awaitin interfacePendingResult<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
Description copied from interface:PendingResultPerforms the request synchronously, ignoring exceptions while performing the request and errors returned by the server.- Specified by:
awaitIgnoreErrorin interfacePendingResult<T>- Returns:
- The result, or null if there was any error or exception ignored.
-
cancel
public void cancel()Description copied from interface:PendingResultAttempts to cancel the request.- Specified by:
cancelin interfacePendingResult<T>
-
onFailure
public void onFailure(okhttp3.Call call, java.io.IOException ioe)- Specified by:
onFailurein interfaceokhttp3.Callback
-
onResponse
public void onResponse(okhttp3.Call call, okhttp3.Response response) throws java.io.IOException- Specified by:
onResponsein interfaceokhttp3.Callback- Throws:
java.io.IOException
-