java.lang.Object
org.miaixz.bus.http.metric.Dispatcher
关于何时执行异步请求的策略 每个dispatcher使用一个
ExecutorService在内部运行调用。 如果您提供自己的执行程序,它应该能够并发地运行配置的最大调用数- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid取消当前排队或执行的所有调用。voidenqueue(RealCall.AsyncCall call) voidUsed byCall#executeto signal it is in-flight.<T> voidvoidUsed byCall#executeto signal completion.voidfinished(RealCall.AsyncCall call) Used byAsyncCall#runto signal completion.intintboolean将符合条件的调用从readyAsyncCalls提升到runningAsyncCalls, 并在executor服务上运行它们。Returns a snapshot of the calls currently awaiting execution.intReturns a snapshot of the calls currently being executed.intvoidsetIdleCallback(Runnable idleCallback) 设置一个回调,以便每次调度程序变为空闲时调用(当运行的调用数量返回零时)voidsetMaxRequests(int maxRequests) 设置并发执行的最大请求数。voidsetMaxRequestsPerHost(int maxRequestsPerHost) 设置每个主机并发执行的最大请求数。
-
Constructor Details
-
Dispatcher
-
Dispatcher
public Dispatcher()
-
-
Method Details
-
executorService
-
getMaxRequests
public int getMaxRequests() -
setMaxRequests
public void setMaxRequests(int maxRequests) 设置并发执行的最大请求数。上述请求在内存中排队,等待正在运行的调用完成 如果在调用它时有超过maxRequests的请求在运行,那么这些请求将保持运行状态- Parameters:
maxRequests- 最大请求数
-
getMaxRequestsPerHost
public int getMaxRequestsPerHost() -
setMaxRequestsPerHost
public void setMaxRequestsPerHost(int maxRequestsPerHost) 设置每个主机并发执行的最大请求数。这将根据URL的主机名限制请求。 注意,对单个IP地址的并发请求仍然可能超过这个限制:多个主机名可能共享一个IP地址,或者通过相同的HTTP代理进行路由 如果在调用它时有超过maxRequestsPerHost的请求在运行,那么这些请求将保持运行状态- Parameters:
maxRequestsPerHost- 最大请求数
-
setIdleCallback
设置一个回调,以便每次调度程序变为空闲时调用(当运行的调用数量返回零时)- Parameters:
idleCallback- 回调
-
enqueue
-
findExistingCallWithHost
-
cancelAll
public void cancelAll()取消当前排队或执行的所有调用。包括同步执行的 NewCall.execute()和异步 执行的NewCall.enqueue(org.miaixz.bus.http.Callback)。 -
promoteAndExecute
public boolean promoteAndExecute()将符合条件的调用从readyAsyncCalls提升到runningAsyncCalls, 并在executor服务上运行它们。必须不与同步调用,因为执行调用可以调用到用户代码- Returns:
- 如果调度程序当前正在运行调用,则为true
-
executed
Used byCall#executeto signal it is in-flight. -
finished
Used byAsyncCall#runto signal completion. -
finished
Used byCall#executeto signal completion. -
finished
-
queuedCalls
Returns a snapshot of the calls currently awaiting execution. -
runningCalls
Returns a snapshot of the calls currently being executed. -
queuedCallsCount
public int queuedCallsCount() -
runningCallsCount
public int runningCallsCount()
-