Package com.azure.android.core.http
Class HttpCallDispatcher
- java.lang.Object
-
- com.azure.android.core.http.HttpCallDispatcher
-
public final class HttpCallDispatcher extends java.lang.Object
The dispatcher to dispatch async HTTP calls send through the pipeline. Additionally, an HttpClient that does not have native async support can also use the dispatcher to enable async HTTP calls.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
HttpCallDispatcher.HttpCallFunction
Contract representing an HTTP call to execute.
-
Constructor Summary
Constructors Constructor Description HttpCallDispatcher()
Creates an HttpCallDispatcher with an ExecutorService with default settings to execute HTTP calls.HttpCallDispatcher(java.util.concurrent.ExecutorService executorService)
Creates an HttpCallDispatcher that uses the givenexecutorService
to execute HTTP calls.HttpCallDispatcher(java.util.concurrent.ExecutorService executorService, java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
Creates an HttpCallDispatcher that uses the givenexecutorService
to execute HTTP calls and uses the the givenscheduledExecutorService
to schedule HTTP calls to execute onexecutorService
after a specific delay.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
enqueue(HttpCallDispatcher.HttpCallFunction httpCallFunction, HttpRequest httpRequest, com.azure.android.core.util.CancellationToken cancellationToken, HttpCallback httpCallback)
Enqueue a function to perform the HTTP call on the dispatcher thread.int
getMaxRunningCalls()
Gets the maximum number of HTTP calls that can run concurrently in the dispatcher threads.void
setMaxRunningCalls(int maxCalls)
Sets the maximum number of HTTP calls to run concurrently.
-
-
-
Constructor Detail
-
HttpCallDispatcher
public HttpCallDispatcher()
Creates an HttpCallDispatcher with an ExecutorService with default settings to execute HTTP calls.
-
HttpCallDispatcher
public HttpCallDispatcher(java.util.concurrent.ExecutorService executorService)
Creates an HttpCallDispatcher that uses the givenexecutorService
to execute HTTP calls.- Parameters:
executorService
- The executor service.
-
HttpCallDispatcher
public HttpCallDispatcher(java.util.concurrent.ExecutorService executorService, java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
Creates an HttpCallDispatcher that uses the givenexecutorService
to execute HTTP calls and uses the the givenscheduledExecutorService
to schedule HTTP calls to execute onexecutorService
after a specific delay.- Parameters:
executorService
- The executor service.scheduledExecutorService
- The scheduled executor service.
-
-
Method Detail
-
setMaxRunningCalls
public void setMaxRunningCalls(int maxCalls)
Sets the maximum number of HTTP calls to run concurrently.Calls beyond this value will be stored in-memory queue waiting for running calls to complete.
- Parameters:
maxCalls
- The maximum number of HTTP calls to run concurrently.- Throws:
java.lang.IllegalArgumentException
- if value ofmaxCalls
parameter is less than 1.
-
getMaxRunningCalls
public int getMaxRunningCalls()
Gets the maximum number of HTTP calls that can run concurrently in the dispatcher threads.- Returns:
- The maximum number of HTTP calls that can run concurrently.
-
enqueue
public void enqueue(HttpCallDispatcher.HttpCallFunction httpCallFunction, HttpRequest httpRequest, com.azure.android.core.util.CancellationToken cancellationToken, HttpCallback httpCallback)
Enqueue a function to perform the HTTP call on the dispatcher thread.- Parameters:
httpCallFunction
- The function that perform the HTTP call when invoked.httpRequest
- The HTTP request to be given tohttpCallFunction
when the function is invoked.cancellationToken
- The cancellation token for dispatcher to check whether the function is cancelled.httpCallback
- The HTTP callback to be given tohttpCallFunction
to notify the result of the HTTP call.
-
-