当前位置: 首页 > news >正文

惠州做网站建设价格wordpress yeti2.0

惠州做网站建设价格,wordpress yeti2.0,怀化汽车网站,免费html5中文网站素材newCall 实际上是创建了一个 RealCall 有三个参数#xff1a;OkHttpClient#xff08;通用配置#xff0c;超时时间等#xff09; Request(Http请求所用到的条件#xff0c;url等) 布尔变量forWebSocket#xff08;webSocket是一种应用层的交互方式#xff0c;可双向交互… newCall 实际上是创建了一个 RealCall 有三个参数OkHttpClient通用配置超时时间等 Request(Http请求所用到的条件url等) 布尔变量forWebSocketwebSocket是一种应用层的交互方式可双向交互一般用不到除非需要频繁刷新数据股票等。 private RealCall(OkHttpClient client, Request originalRequest, boolean forWebSocket) {this.client client;this.originalRequest originalRequest;this.forWebSocket forWebSocket;}Request会被进行多次封装(所以构造函数里对象被命名为originRequest) 在进行newCall().enqueue(),实际就是RealCall的enqueue() Override public void enqueue(Callback responseCallback) {synchronized (this) {if (executed) throw new IllegalStateException(Already Executed);executed true;}//1transmitter.callStart();//2 关键client.dispatcher().enqueue(new AsyncCall(responseCallback));}分别看1和2主要看2 public void callStart() {//跟踪程序错误this.callStackTrace Platform.get().getStackTraceForCloseable(response.body().close());//eventListener是一个监听器连接的接入和关闭对程序进行监听eventListener.callStart(call);}client.dispatcher()返回一个Dispatcher类对象即线程调度器然后用这个去进行异步操作代入参数为一个AsyncCall void enqueue(AsyncCall call) {synchronized (this) {//1readyAsyncCalls.add(call);// Mutate the AsyncCall so that it shares the AtomicInteger of an existing running call to// the same host.//2if (!call.get().forWebSocket) {AsyncCall existingCall findExistingCallWithHost(call.host());if (existingCall ! null) call.reuseCallsPerHostFrom(existingCall);}}//3promoteAndExecute();}1的readyAsyncCalls 是一个 ArrayDequeAsyncCall 存放 准备要执行但还没有执行然后会在3的promoteAndExecute()中执行 private boolean promoteAndExecute() {assert (!Thread.holdsLock(this));ListAsyncCall executableCalls new ArrayList();boolean isRunning;synchronized (this) {for (IteratorAsyncCall i readyAsyncCalls.iterator(); i.hasNext(); ) {AsyncCall asyncCall i.next();if (runningAsyncCalls.size() maxRequests) break; // Max capacity.if (asyncCall.callsPerHost().get() maxRequestsPerHost) continue; // Host max capacity.i.remove();asyncCall.callsPerHost().incrementAndGet();executableCalls.add(asyncCall);runningAsyncCalls.add(asyncCall);}isRunning runningCallsCount() 0;}for (int i 0, size executableCalls.size(); i size; i) {AsyncCall asyncCall executableCalls.get(i);asyncCall.executeOn(executorService());}return isRunning;}promoteAndExecute会挑选那些不会导致超负载的call(不超过AsyncCall对应的maxRequest)放进executableCalls和runningAsyncCalls然后去执行就是去遍历executableCalls然后执行。 分别执行就是把调用每一个asyncCall 的 executeOn(): void executeOn(ExecutorService executorService) {assert (!Thread.holdsLock(client.dispatcher()));boolean success false;try {executorService.execute(this);success true;} catch (RejectedExecutionException e) {InterruptedIOException ioException new InterruptedIOException(executor rejected);ioException.initCause(e);transmitter.noMoreExchanges(ioException);responseCallback.onFailure(RealCall.this, ioException);} finally {if (!success) {client.dispatcher().finished(this); // This call is no longer running!}}}核心只有一行 executorService.execute(this);这里就已经切换线程了执行的都是传入的 executorService.对象 的execute()方法都会在后台执行 Override protected void execute() {boolean signalledCallback false; // 标记回调是否已触发transmitter.timeoutEnter(); // 进入超时处理逻辑try {Response response getResponseWithInterceptorChain(); // 调用拦截器链获取responsesignalledCallback true; // 标记回调已触发responseCallback.onResponse(RealCall.this, response); // 调用response的回调函数} catch (IOException e) {if (signalledCallback) {// 不要重复触发回调Platform.get().log(INFO, Callback failure for toLoggableString(), e);} else {responseCallback.onFailure(RealCall.this, e);}} catch (Throwable t) {cancel(); // 取消请求if (!signalledCallback) {IOException canceledException new IOException(canceled due to t);canceledException.addSuppressed(t);responseCallback.onFailure(RealCall.this, canceledException); // 调用失败回调函数}throw t;} finally {client.dispatcher().finished(this); // 请求结束将请求移出调度队列}}其中回调函数就是当初我们在应用层所定义的Callback里边定义的onFailure() 和 onResponse(),然后如果出现异常会进行调用相应的方法。
http://www.w-s-a.com/news/295550/

相关文章:

  • 北京网站建设求职简历十堰seo优化教程
  • 网站顶部可关闭广告微信小程序多少钱
  • 网站背景怎么弄斜杠青年seo工作室
  • ps个人网站首页怎么制作如何做网站的版块规划
  • 做网站的市场开源建站工具
  • 邹平做网站哪家好自动点击器app
  • 南阳seo网站排名优化wordpress文章对游客不显示
  • 网站301什么意思湛江市seo网站设计报价
  • 免费建造网站化妆品网络营销方案
  • 建公司网站wordpress the content
  • 网站的站点的管理系统建设银行网站注册企业
  • 长春火车站是哪个站做微商哪个网站有客源
  • 亚马逊培训费用一般多少seo专业培训课程
  • 做推文封面图网站南宁高端网站建设
  • 天津网站搜索排名做电影免费ppt模板下载网站
  • 襄樊最好网站建设价格网站建设与设计 毕业设计
  • 网站推广广告词大全集网站建设相对路径
  • 甘肃省铁路投资建设集团有限公司网站域名怎么实名认证
  • 企业网站建设的层次返利网站建设
  • 竞价单页网站制作中小企业网站建设问题
  • 响应式网站源码学校网站制作多少钱
  • 营销型网站建设需要懂什么网站建站四件套是什么
  • 廊坊哪里有制作手机网站的区块链开发语言
  • 找建设项目的网站装企工长网站开发
  • 戴尔网站建设成功方正网站制作
  • 怎么买网站域名wordpress 视频站模版
  • 厦门官网建设公司杨和关键词优化
  • 怎么做网约车seo自动优化软件下载
  • 遵义市住房和城乡建设局官方网站网站备案 自己的服务器
  • 分销系统价格多少北京网站优化平台