-
public final class DispatcherPolicy on when async requests are executed.
Each dispatcher uses an ExecutorService to run calls internally. If you supply your own executor, it should be able to run the configured maximum number of calls concurrently.
-
-
Field Summary
Fields Modifier and Type Field Description private intmaxRequestsprivate intmaxRequestsPerHostprivate RunnableidleCallback
-
Constructor Summary
Constructors Constructor Description Dispatcher(ExecutorService executorService)Dispatcher()
-
Method Summary
Modifier and Type Method Description synchronized intgetMaxRequests()synchronized voidsetMaxRequests(int maxRequests)Set the maximum number of requests to execute concurrently. synchronized intgetMaxRequestsPerHost()synchronized voidsetMaxRequestsPerHost(int maxRequestsPerHost)Set the maximum number of requests for each host to execute concurrently. synchronized voidsetIdleCallback(@Nullable() Runnable idleCallback)Set a callback to be invoked each time the dispatcher becomes idle (when the number of runningcalls returns to zero). synchronized ExecutorServiceexecutorService()synchronized voidcancelAll()Cancel all calls currently enqueued or executing. synchronized List<Call>queuedCalls()Returns a snapshot of the calls currently awaiting execution. synchronized List<Call>runningCalls()Returns a snapshot of the calls currently being executed. synchronized intqueuedCallsCount()synchronized intrunningCallsCount()-
-
Constructor Detail
-
Dispatcher
Dispatcher(ExecutorService executorService)
-
Dispatcher
Dispatcher()
-
-
Method Detail
-
getMaxRequests
synchronized int getMaxRequests()
-
setMaxRequests
synchronized void setMaxRequests(int maxRequests)
Set the maximum number of requests to execute concurrently. Above this requests queue inmemory, waiting for the running calls to complete.
If more than
{@code maxRequests}requests are in flight when this is invoked, those requestswill remain in flight.
-
getMaxRequestsPerHost
synchronized int getMaxRequestsPerHost()
-
setMaxRequestsPerHost
synchronized void setMaxRequestsPerHost(int maxRequestsPerHost)
Set the maximum number of requests for each host to execute concurrently. This limits requestsby the URL's host name. Note that concurrent requests to a single IP address may still exceedthis limit: multiple hostnames may share an IP address or be routed through the same HTTPproxy.
If more than
{@code maxRequestsPerHost}requests are in flight when this is invoked, thoserequests will remain in flight.WebSocket connections to hosts do not count against this limit.
-
setIdleCallback
synchronized void setIdleCallback(@Nullable() Runnable idleCallback)
Set a callback to be invoked each time the dispatcher becomes idle (when the number of runningcalls returns to zero).
Note: The time at which a call is considered idle is different dependingon whether it was run asynchronously or synchronously. Asynchronous calls become idle after the onResponse or onFailure callback hasreturned. Synchronous calls become idle once execute() returns. Thismeans that if you are doing synchronous calls the network layer will not truly be idle untilevery returned MobonResponse has been closed.
-
executorService
synchronized ExecutorService executorService()
-
cancelAll
synchronized void cancelAll()
Cancel all calls currently enqueued or executing. Includes calls executed both synchronously and asynchronously.
-
queuedCalls
synchronized List<Call> queuedCalls()
Returns a snapshot of the calls currently awaiting execution.
-
runningCalls
synchronized List<Call> runningCalls()
Returns a snapshot of the calls currently being executed.
-
queuedCallsCount
synchronized int queuedCallsCount()
-
runningCallsCount
synchronized int runningCallsCount()
-
-
-
-