public final class Dispatcher extends Object
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.
| 构造器和说明 |
|---|
Dispatcher() |
Dispatcher(ExecutorService executorService) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
cancelAll()
Cancel all calls currently enqueued or executing.
|
ExecutorService |
executorService() |
int |
getMaxRequests() |
int |
getMaxRequestsPerHost() |
List<Call> |
queuedCalls()
Returns a snapshot of the calls currently awaiting execution.
|
int |
queuedCallsCount() |
List<Call> |
runningCalls()
Returns a snapshot of the calls currently being executed.
|
int |
runningCallsCount() |
void |
setIdleCallback(Runnable idleCallback)
Set a callback to be invoked each time the dispatcher becomes idle (when the number of running
calls returns to zero).
|
void |
setMaxRequests(int maxRequests)
Set the maximum number of requests to execute concurrently.
|
void |
setMaxRequestsPerHost(int maxRequestsPerHost)
Set the maximum number of requests for each host to execute concurrently.
|
public Dispatcher(ExecutorService executorService)
public Dispatcher()
public ExecutorService executorService()
public int getMaxRequests()
public void setMaxRequests(int maxRequests)
If more than maxRequests requests are in flight when this is invoked, those
requests will remain in flight.
public int getMaxRequestsPerHost()
public void setMaxRequestsPerHost(int maxRequestsPerHost)
If more than maxRequestsPerHost requests are in flight when this is invoked, those
requests will remain in flight.
WebSocket connections to hosts do not count against this limit.
public void setIdleCallback(@Nullable Runnable idleCallback)
Note: The time at which a call is considered idle is different depending
on whether it was run asynchronously or synchronously. Asynchronous calls become idle after the onResponse or onFailure callback has returned.
Synchronous calls become idle once execute() returns. This means that if
you are doing synchronous calls the network layer will not truly be idle until every returned
Response has been closed.
public void cancelAll()
public List<Call> queuedCalls()
public List<Call> runningCalls()
public int queuedCallsCount()
public int runningCallsCount()
Copyright © 2022. All rights reserved.