本文整理了Java中okhttp3.Call.cancel()
方法的一些代码示例,展示了Call.cancel()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Call.cancel()
方法的具体详情如下:
包路径:okhttp3.Call
类名称:Call
方法名:cancel
[英]Cancels the request, if possible. Requests that are already complete cannot be canceled.
[中]如果可能,取消请求。无法取消已完成的请求。
代码示例来源:origin: square/retrofit
public void cancel() {
canceled = true;
okhttp3.Call call;
synchronized (this) {
call = rawCall;
}
if (call != null) {
call.cancel();
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected void interruptTask() {
this.call.cancel();
}
}
代码示例来源:origin: square/okhttp
@Override public void cancel() {
call.cancel();
}
代码示例来源:origin: square/okhttp
@Override public void cancel() {
call.cancel();
}
代码示例来源:origin: bumptech/glide
@Override
public void cancel() {
Call local = call;
if (local != null) {
local.cancel();
}
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
@Override
public void cancel() {
canceled = true;
if (rawCall != null) {
rawCall.cancel();
}
}
代码示例来源:origin: JessYanCoding/MVPArms
@Override
public void cancel() {
Call local = call;
if (local != null) {
local.cancel();
}
}
代码示例来源:origin: org.springframework/spring-web
@Override
protected void interruptTask() {
this.call.cancel();
}
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@Override
public void dispose() {
this.call.cancel();
}
代码示例来源:origin: com.squareup.retrofit2/retrofit
public void cancel() {
canceled = true;
okhttp3.Call call;
synchronized (this) {
call = rawCall;
}
if (call != null) {
call.cancel();
}
}
代码示例来源:origin: square/okhttp
@Override public void disconnect() {
// Calling disconnect() before a connection exists should have no effect.
if (call == null) return;
networkInterceptor.proceed(); // Unblock any waiting async thread.
call.cancel();
}
代码示例来源:origin: square/okhttp
public void run() throws Exception {
Request request = new Request.Builder()
.url("http://httpbin.org/delay/2") // This URL is served with a 2 second delay.
.build();
final long startNanos = System.nanoTime();
final Call call = client.newCall(request);
// Schedule a job to cancel the call in 1 second.
executor.schedule(() -> {
System.out.printf("%.2f Canceling call.%n", (System.nanoTime() - startNanos) / 1e9f);
call.cancel();
System.out.printf("%.2f Canceled call.%n", (System.nanoTime() - startNanos) / 1e9f);
}, 1, TimeUnit.SECONDS);
System.out.printf("%.2f Executing call.%n", (System.nanoTime() - startNanos) / 1e9f);
try (Response response = call.execute()) {
System.out.printf("%.2f Call was expected to fail, but completed: %s%n",
(System.nanoTime() - startNanos) / 1e9f, response);
} catch (IOException e) {
System.out.printf("%.2f Call failed as expected: %s%n",
(System.nanoTime() - startNanos) / 1e9f, e);
}
}
代码示例来源:origin: square/retrofit
@Override public Response<T> execute() throws IOException {
okhttp3.Call call;
synchronized (this) {
if (executed) throw new IllegalStateException("Already executed.");
executed = true;
if (creationFailure != null) {
if (creationFailure instanceof IOException) {
throw (IOException) creationFailure;
} else if (creationFailure instanceof RuntimeException) {
throw (RuntimeException) creationFailure;
} else {
throw (Error) creationFailure;
}
}
call = rawCall;
if (call == null) {
try {
call = rawCall = createRawCall();
} catch (IOException | RuntimeException | Error e) {
throwIfFatal(e); // Do not assign a fatal error to creationFailure.
creationFailure = e;
throw e;
}
}
}
if (canceled) {
call.cancel();
}
return parseResponse(call.execute());
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
@Override
public synchronized okhttp3.Call prepareRawCall() throws Throwable {
if (executed) throw HttpException.COMMON("Already executed!");
executed = true;
rawCall = request.getRawCall();
if (canceled) rawCall.cancel();
return rawCall;
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
@Override
public void uploadProgress(Progress innerProgress) {
if (rawCall.isCanceled()) return;
if (progress.status != Progress.LOADING) {
rawCall.cancel();
return;
}
progress.from(innerProgress);
postLoading(progress);
}
});
代码示例来源:origin: jeasonlzy/okhttp-OkGo
/** 取消所有请求请求 */
public static void cancelAll(OkHttpClient client) {
if (client == null) return;
for (Call call : client.dispatcher().queuedCalls()) {
call.cancel();
}
for (Call call : client.dispatcher().runningCalls()) {
call.cancel();
}
}
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@Override
public void unsubscribe() {
if (request.getCall() != null) {
request.getCall().cancel();
}
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
/** 取消所有请求请求 */
public void cancelAll() {
for (Call call : getOkHttpClient().dispatcher().queuedCalls()) {
call.cancel();
}
for (Call call : getOkHttpClient().dispatcher().runningCalls()) {
call.cancel();
}
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
/** 根据Tag取消请求 */
public static void cancelTag(OkHttpClient client, Object tag) {
if (client == null || tag == null) return;
for (Call call : client.dispatcher().queuedCalls()) {
if (tag.equals(call.request().tag())) {
call.cancel();
}
}
for (Call call : client.dispatcher().runningCalls()) {
if (tag.equals(call.request().tag())) {
call.cancel();
}
}
}
代码示例来源:origin: jeasonlzy/okhttp-OkGo
/** 根据Tag取消请求 */
public void cancelTag(Object tag) {
if (tag == null) return;
for (Call call : getOkHttpClient().dispatcher().queuedCalls()) {
if (tag.equals(call.request().tag())) {
call.cancel();
}
}
for (Call call : getOkHttpClient().dispatcher().runningCalls()) {
if (tag.equals(call.request().tag())) {
call.cancel();
}
}
}
内容来源于网络,如有侵权,请联系作者删除!