Class Dispatcher

java.lang.Object
org.miaixz.bus.http.metric.Dispatcher

public class Dispatcher extends Object
关于何时执行异步请求的策略 每个dispatcher使用一个ExecutorService在内部运行调用。 如果您提供自己的执行程序,它应该能够并发地运行配置的最大调用数
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • Dispatcher

      public Dispatcher(ExecutorService executorService)
    • Dispatcher

      public Dispatcher()
  • Method Details

    • executorService

      public ExecutorService 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

      public void setIdleCallback(Runnable idleCallback)
      设置一个回调,以便每次调度程序变为空闲时调用(当运行的调用数量返回零时)
      Parameters:
      idleCallback - 回调
    • enqueue

      public void enqueue(RealCall.AsyncCall call)
    • findExistingCallWithHost

      public RealCall.AsyncCall findExistingCallWithHost(String host)
    • cancelAll

      public void cancelAll()
      取消当前排队或执行的所有调用。包括同步执行的 NewCall.execute()和异步 执行的NewCall.enqueue(org.miaixz.bus.http.Callback)
    • promoteAndExecute

      public boolean promoteAndExecute()
      将符合条件的调用从readyAsyncCalls提升到runningAsyncCalls, 并在executor服务上运行它们。必须不与同步调用,因为执行调用可以调用到用户代码
      Returns:
      如果调度程序当前正在运行调用,则为true
    • executed

      public void executed(RealCall call)
      Used by Call#execute to signal it is in-flight.
    • finished

      public void finished(RealCall.AsyncCall call)
      Used by AsyncCall#run to signal completion.
    • finished

      public void finished(RealCall call)
      Used by Call#execute to signal completion.
    • finished

      public <T> void finished(Deque<T> calls, T call)
    • queuedCalls

      public List<NewCall> queuedCalls()
      Returns a snapshot of the calls currently awaiting execution.
    • runningCalls

      public List<NewCall> runningCalls()
      Returns a snapshot of the calls currently being executed.
    • queuedCallsCount

      public int queuedCallsCount()
    • runningCallsCount

      public int runningCallsCount()