1.RealCall.execute
final class RealCall implements Call {
@Override
public Response execute() throws IOException {
synchronized (this) {
i if (executed) throw new IllegalStateException("Already Executed");
executed = true;
}
transmitter.timeoutEnter();
transmitter.callStart();
try {
client.dispatcher().executed(this); //1.调用Dispatcher的executed
return getResponseWithInterceptorChain();//2调用getResponseWithInterceptorChain
} finally {
client.dispatcher().finished(this); //3.结束
}
}
}
1.1.Dispatcher.executed
public final class Dispatcher {
private final Deque<RealCall> runningSyncCalls = new ArrayDeque<>();
synchronized void executed(RealCall call) {
runningSyncCalls.add(call);
}
}
1.2.RealCall.getResponseWithInterceptorChain
final class RealCall implements Call {
Response getResponseWithInterceptorChain() throws IOException {
Interceptor.Chain chain = new RealInterceptorChain(interceptors, transmitter,
null, 0, originalRequest, this, client.connectTimeoutMillis(),
client.readTimeoutMillis(), client.writeTimeoutMillis());
Response response = chain.proceed(originalRequest); //执行拦截器
return response; //返回结果
}
}
1.3.Dispatcher.finished
执行下一个call;
public final class Dispatcher {
void finished(RealCall call) {
finished(runningSyncCalls, call);
}
private <T> void finished(Deque<T> calls, T call) {
Runnable idleCallback;
synchronized (this) {
//将call从calls移除
if (!calls.remove(call)) throw new AssertionError("Call wasn't in-flight!");
idleCallback = this.idleCallback;
}
boolean isRunning = promoteAndExecute(); //执行下一个call
if (!isRunning && idleCallback != null) {//如果没有要执行的call,调用idleCallback
idleCallback.run();
}
}
}
原文地址:https://blog.csdn.net/lostfish123/article/details/134678524
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.7code.cn/show_4461.html
如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。