okhttp3.Request.tag()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(978)

本文整理了Java中okhttp3.Request.tag方法的一些代码示例,展示了Request.tag的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.tag方法的具体详情如下:
包路径:okhttp3.Request
类名称:Request
方法名:tag

Request.tag介绍

[英]Returns the tag attached with Object.class as a key, or null if no tag is attached with that key.

Prior to OkHttp 3.11, this method never returned null if no tag was attached. Instead it returned either this request, or the request upon which this request was derived with #newBuilder().
[中]返回附加在对象上的标记。类作为键,如果没有标记附加到该键,则为null。
在OkHttp 3.11之前,如果没有附加标记,该方法永远不会返回null。相反,它返回了这个请求,或者是用#newBuilder()派生这个请求的请求。

代码示例

代码示例来源:origin: square/okhttp

/**
 * Returns the tag attached with {@code Object.class} as a key, or null if no tag is attached with
 * that key.
 *
 * <p>Prior to OkHttp 3.11, this method never returned null if no tag was attached. Instead it
 * returned either this request, or the request upon which this request was derived with {@link
 * #newBuilder()}.
 */
public @Nullable Object tag() {
 return tag(Object.class);
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/**
 * Returns the tag attached with {@code Object.class} as a key, or null if no tag is attached with
 * that key.
 *
 * <p>Prior to OkHttp 3.11, this method never returned null if no tag was attached. Instead it
 * returned either this request, or the request upon which this request was derived with {@link
 * #newBuilder()}.
 */
public @Nullable Object tag() {
 return tag(Object.class);
}

代码示例来源: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();
    }
  }
}

代码示例来源:origin: dongjunkun/GanK

/**
 * 根据tag取消请求
 *
 * @param tag 标签
 */
public static void cancelRequest(Object tag) {
  for (Call call : okHttpClient.dispatcher().queuedCalls()) {
    if (call.request().tag().equals(tag)) {
      call.cancel();
    }
  }
  for (Call call : okHttpClient.dispatcher().runningCalls()) {
    if (call.request().tag().equals(tag)) {
      call.cancel();
    }
  }
}

代码示例来源:origin: huxq17/tractor

Object tag() {
 return originalRequest.tag();
}

代码示例来源:origin: huxq17/tractor

Object tag() {
 return originalRequest.tag();
}

代码示例来源:origin: huxq17/SwipeCardsView

Object tag() {
 return originalRequest.tag();
}

代码示例来源:origin: com.qiniu/qiniu-android-sdk

@Override
  public void onResponse(Call call, okhttp3.Response response) throws IOException {
    ResponseTag tag = (ResponseTag) response.request().tag();
    onRet(response, tag.ip, tag.duration, upToken, totalSize, complete);
  }
});

代码示例来源:origin: qiniu/android-sdk

@Override
  public void onResponse(Call call, okhttp3.Response response) throws IOException {
    ResponseTag tag = (ResponseTag) response.request().tag();
    onRet(response, tag.ip, tag.duration, upToken, totalSize, complete);
  }
});

代码示例来源:origin: apache/servicemix-bundles

/**
 * Returns the tag attached with {@code Object.class} as a key, or null if no tag is attached with
 * that key.
 *
 * <p>Prior to OkHttp 3.11, this method never returned null if no tag was attached. Instead it
 * returned either this request, or the request upon which this request was derived with {@link
 * #newBuilder()}.
 */
public @Nullable Object tag() {
 return tag(Object.class);
}

代码示例来源:origin: com.qiniu/qiniu-pandora-sdk

@Override
  public okhttp3.Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    okhttp3.Response response = chain.proceed(request);
    IpTag tag = (IpTag) request.tag();
    try {
      tag.ip = chain.connection().socket().getRemoteSocketAddress().toString();
    } catch (Exception e) {
      tag.ip = "";
    }
    return response;
  }
});

代码示例来源:origin: qiniu/java-sdk

@Override
  public okhttp3.Response intercept(Chain chain) throws IOException {
    Request request = chain.request();
    okhttp3.Response response = chain.proceed(request);
    IpTag tag = (IpTag) request.tag();
    try {
      tag.ip = chain.connection().socket().getRemoteSocketAddress().toString();
    } catch (Exception e) {
      e.printStackTrace();
      tag.ip = "";
    }
    return response;
  }
});

代码示例来源:origin: io.zipkin.java/zipkin-autoconfigure-storage-elasticsearch

/** create a local span with the same name as the request tag */
 @Override
 public Response intercept(Chain chain) throws IOException {
  // don't start new traces (to prevent amplifying writes to local storage)
  if (currentTraceContext.get() == null) return chain.proceed(chain.request());
  Request request = chain.request();
  brave.Span span = tracer.nextSpan().name(request.tag().toString());
  try (Tracer.SpanInScope ws = tracer.withSpanInScope(span.start())) {
   return chain.proceed(request);
  } finally {
   span.finish();
  }
 }
});

代码示例来源:origin: io.zipkin.java/zipkin-autoconfigure-storage-elasticsearch-http

/** create a local span with the same name as the request tag */
 @Override public Response intercept(Chain chain) throws IOException {
  // don't start new traces (to prevent amplifying writes to local storage)
  if (currentTraceContext.get() == null) return chain.proceed(chain.request());
  Request request = chain.request();
  brave.Span span = tracer.nextSpan().name(request.tag().toString());
  try (Tracer.SpanInScope ws = tracer.withSpanInScope(span.start())) {
   return chain.proceed(request);
  } finally {
   span.finish();
  }
 }
});

代码示例来源:origin: jinguangyue/Android-CustomCamera

public void cancelTag(Object tag) {
  for (Call call : mOkHttpClient.dispatcher().queuedCalls()) {
    if (tag.equals(call.request().tag())) {
      call.cancel();
    }
  }
  for (Call call : mOkHttpClient.dispatcher().runningCalls()) {
    if (tag.equals(call.request().tag())) {
      call.cancel();
    }
  }
}

代码示例来源:origin: noties/Markwon

@Override
public void cancel(@NonNull String raw) {
  final List<Call> calls = client.dispatcher().queuedCalls();
  if (calls != null) {
    for (Call call : calls) {
      if (!call.isCanceled()) {
        if (raw.equals(call.request().tag())) {
          call.cancel();
        }
      }
    }
  }
}

代码示例来源:origin: daquexian/chaoli-forum-for-android-2

public static void cancel(Object tag) {
  for (Call call : okHttpClient.dispatcher().queuedCalls()) {
    if (tag.equals(call.request().tag())) call.cancel();
  }
  for (Call call : okHttpClient.dispatcher().runningCalls()) {
    if (tag.equals(call.request().tag())) call.cancel();
  }
}

代码示例来源:origin: guofudong/EShop

public void cancelByTag(String tag) {
  // A call may transition from queue -> running. Remove queued Calls first.
  for (Call call : mOkHttpClient.dispatcher().queuedCalls()) {
    if (call.request().tag().equals(tag))
      call.cancel();
  }
  for (Call call : mOkHttpClient.dispatcher().runningCalls()) {
    if (call.request().tag().equals(tag))
      call.cancel();
  }
}

代码示例来源:origin: qibin0506/Glin

@Override
public void cancel(Object tag) {
  for (Call call : mClient.dispatcher().queuedCalls()) {
    if (tag.equals(call.request().tag())) {
      call.cancel();
    }
  }
  for (Call call : mClient.dispatcher().runningCalls()) {
    if (tag.equals(call.request().tag())) {
      call.cancel();
    }
  }
}

相关文章