Class 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.
    • 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 given executorService to execute HTTP calls.
      HttpCallDispatcher​(java.util.concurrent.ExecutorService executorService, java.util.concurrent.ScheduledExecutorService scheduledExecutorService)
      Creates an HttpCallDispatcher that uses the given executorService to execute HTTP calls and uses the the given scheduledExecutorService to schedule HTTP calls to execute on executorService 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 given executorService 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 given executorService to execute HTTP calls and uses the the given scheduledExecutorService to schedule HTTP calls to execute on executorService 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 of maxCalls 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 to httpCallFunction 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 to httpCallFunction to notify the result of the HTTP call.