/** * Attempts to prepare the request for a retry. If there are no more attempts remaining in the * request's retry policy, a timeout exception is thrown. * @param request The request to use. */ protected static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { RetryPolicy retryPolicy = request.getRetryPolicy(); int oldTimeout = request.getTimeoutMs(); try { retryPolicy.retry(exception); } catch (VolleyError e) { request.addMarker(String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); throw e; } request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); //reentry the requestQueue RequestQueue requestQueue = getRequestQueue(request); if (requestQueue != null) { requestQueue.add(request); } throw new RetryError(); }
/** * Attempts to prepare the request for a retry. If there are no more * attempts remaining in the request's retry policy, a timeout exception is * thrown. * * @param request * The request to use. */ private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { RetryPolicy retryPolicy = request.getRetryPolicy(); int oldTimeout = request.getTimeoutMs(); try { retryPolicy.retry(exception); } catch (VolleyError e) { request.addMarker(String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); throw e; } request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); }
private static void attemptRetryOnException(String paramString, Request<?> paramRequest, VolleyError paramVolleyError) throws VolleyError { RetryPolicy localRetryPolicy = paramRequest.mRetryPolicy; int i = paramRequest.getTimeoutMs(); try { localRetryPolicy.retry(paramVolleyError); Object[] arrayOfObject2 = new Object[2]; arrayOfObject2[0] = paramString; arrayOfObject2[1] = Integer.valueOf(i); paramRequest.addMarker(String.format("%s-retry [timeout=%s]", arrayOfObject2)); return; } catch (VolleyError localVolleyError) { Object[] arrayOfObject1 = new Object[2]; arrayOfObject1[0] = paramString; arrayOfObject1[1] = Integer.valueOf(i); paramRequest.addMarker(String.format("%s-timeout-giveup [timeout=%s]", arrayOfObject1)); throw localVolleyError; } }
/** * Attempts to prepare the request for a retry. If there are no more * attempts remaining in the * request's retry policy, a timeout exception is thrown. * * @param request * The request to use. */ private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { RetryPolicy retryPolicy = request.getRetryPolicy(); int oldTimeout = request.getTimeoutMs(); try { retryPolicy.retry(exception); } catch (VolleyError e) { request.addMarker(String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); throw e; } request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); }
public ProjectileRequest(int method, String url, Map<String, String> headers, Map<String, String> params, final ResponseListener<T> responseListener, Priority p, RetryPolicy retryPolicy, Object tag, boolean shouldCache) { super(method, url, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { if(responseListener != null) responseListener.onError(volleyError); } }); mListener = responseListener; mHeaders = headers; mParams = params; mPriority = p; setRetryPolicy(retryPolicy); setTag(tag); setShouldCache(shouldCache); }
/** * Attempts to prepare the request for a retry. If there are no more attempts remaining in the * request's retry policy, a timeout exception is thrown. * * @param request The request to use. */ private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { RetryPolicy retryPolicy = request.getRetryPolicy(); int oldTimeout = retryPolicy.getCurrentTimeout(); try { retryPolicy.retry(exception); } catch (VolleyError e) { // request.addMarker( // String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); Log.d("network", String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); throw e; } Log.d("network", String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); //request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); }
/** * Attempts to prepare the request for a retry. If there are no more attempts remaining in the * request's retry policy, a timeout exception is thrown. * @param request The request to use. */ private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { RetryPolicy retryPolicy = request.getRetryPolicy(); int oldTimeout = request.getTimeoutMs(); try { retryPolicy.retry(exception); } catch (VolleyError e) { request.addMarker( String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); throw e; } request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); }
private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { RetryPolicy retryPolicy = request.getRetryPolicy(); int oldTimeout = request.getTimeoutMs(); try { retryPolicy.retry(exception); } catch (VolleyError var6) { request.addMarker(String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); throw var6; } request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); }
/** * Attempts to prepare the request for a retry. If there are no more attempts remaining in the * request's retry policy, a timeout exception is thrown. * * @param request The request to use. */ private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { RetryPolicy retryPolicy = request.getRetryPolicy(); int oldTimeout = request.getTimeoutMs(); try { retryPolicy.retry(exception); } catch (VolleyError e) { request.addMarker(String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); throw e; } request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); }
private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { RetryPolicy retryPolicy = request.getRetryPolicy(); int oldTimeout = request.getTimeoutMs(); try { retryPolicy.retry(exception); request.addMarker(String.format("%s-retry [timeout=%s]", new Object[]{logPrefix, Integer.valueOf(oldTimeout)})); } catch (VolleyError e) { request.addMarker(String.format("%s-timeout-giveup [timeout=%s]", new Object[]{logPrefix, Integer.valueOf(oldTimeout)})); throw e; } }
/** * Generate a default retry policy (30 seconds for the timeout, 1 retry maximum, 1 backoff multiplier) * @return a default retry policy, not null */ @NonNull private static RetryPolicy generateRetryPolicy() { return new DefaultRetryPolicy(requestTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT); }
/** * 如果传入的tag有效,则可以通过该tag取消请求的发送 * * @param request req * @param requestTag tag */ private void makeRequest(VolleyRequest request, String requestTag) { if (!TextUtils.isEmpty(requestTag)) { request.setTag(requestTag); } // step4:放入请求队列 RequestQueue requestQueue = VolleyManager.getInstance(mContext).getRequestQueue(); int socketTimeout = 5000;//30 seconds - change to what you want RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT); request.setRetryPolicy(policy); requestQueue.add(request); }
/** * set the retry policy, default is {@link DefaultRetryPolicy()}. * @param retryPolicy see {@link DefaultRetryPolicy} * @return {@link RestVolleyRequest} * @see Request#setRetryPolicy(RetryPolicy) */ public R setRetryPolicy(RetryPolicy retryPolicy) { if (mRetryPolicy != null) { mRetryPolicy = retryPolicy; } return (R)this; }
/** * Attempts to prepare the request for a retry. If there are no more attempts remaining in the * request's retry policy, a timeout exception is thrown. * * @param request The request to use. */ /* * 尝试 重试策略 处理 */ private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { // 拿到 该请求 Request 内对应的 重试策略 类 RetryPolicy retryPolicy = request.getRetryPolicy(); // 获取请求此次的超时时间 int oldTimeout = request.getTimeoutMs(); try { /* * 进行 重试: * 根据 请求此次的超时时间 * 退避乘数 = 此次的实际超时时间 * 将 实际超时时间 累加到 重试策略类 中的 超时总时长 内 */ retryPolicy.retry(exception); } catch (VolleyError e) { // 打印 log request.addMarker( String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); throw e; } // 打印 log request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); }
@Test public void publicMethods() throws Exception { // Catch-all test to find API-breaking changes. assertNotNull(Request.class.getConstructor(int.class, String.class, Response.ErrorListener.class)); assertNotNull(Request.class.getMethod("getMethod")); assertNotNull(Request.class.getMethod("setTag", Object.class)); assertNotNull(Request.class.getMethod("getTag")); assertNotNull(Request.class.getMethod("getErrorListener")); assertNotNull(Request.class.getMethod("getTrafficStatsTag")); assertNotNull(Request.class.getMethod("setRetryPolicy", RetryPolicy.class)); assertNotNull(Request.class.getMethod("addMarker", String.class)); assertNotNull(Request.class.getDeclaredMethod("finish", String.class)); assertNotNull(Request.class.getMethod("setRequestQueue", RequestQueue.class)); assertNotNull(Request.class.getMethod("setSequence", int.class)); assertNotNull(Request.class.getMethod("getSequence")); assertNotNull(Request.class.getMethod("getUrl")); assertNotNull(Request.class.getMethod("getCacheKey")); assertNotNull(Request.class.getMethod("setCacheEntry", Cache.Entry.class)); assertNotNull(Request.class.getMethod("getCacheEntry")); assertNotNull(Request.class.getMethod("cancel")); assertNotNull(Request.class.getMethod("isCanceled")); assertNotNull(Request.class.getMethod("getHeaders")); assertNotNull(Request.class.getDeclaredMethod("getParams")); assertNotNull(Request.class.getDeclaredMethod("getParamsEncoding")); assertNotNull(Request.class.getMethod("getBodyContentType")); assertNotNull(Request.class.getMethod("getBody")); assertNotNull(Request.class.getMethod("setShouldCache", boolean.class)); assertNotNull(Request.class.getMethod("shouldCache")); assertNotNull(Request.class.getMethod("getPriority")); assertNotNull(Request.class.getMethod("getTimeoutMs")); assertNotNull(Request.class.getMethod("getRetryPolicy")); assertNotNull(Request.class.getMethod("markDelivered")); assertNotNull(Request.class.getMethod("hasHadResponseDelivered")); assertNotNull( Request.class.getDeclaredMethod("parseNetworkResponse", NetworkResponse.class)); assertNotNull(Request.class.getDeclaredMethod("parseNetworkError", VolleyError.class)); assertNotNull(Request.class.getDeclaredMethod("deliverResponse", Object.class)); assertNotNull(Request.class.getMethod("deliverError", VolleyError.class)); }
/** * Attempts to prepare the request for a retry. If there are no more attempts remaining in the * request's retry policy, a timeout exception is thrown. * * @param request The request to use. */ private static void attemptRetryOnException(String logPrefix, Request<?> request, VolleyError exception) throws VolleyError { RetryPolicy retryPolicy = request.getRetryPolicy(); int oldTimeout = request.getTimeoutMs(); try { retryPolicy.retry(exception); } catch (VolleyError e) { request.addMarker( String.format("%s-timeout-giveup [timeout=%s]", logPrefix, oldTimeout)); throw e; } request.addMarker(String.format("%s-retry [timeout=%s]", logPrefix, oldTimeout)); }
public final Map<String, String> getHeaders() throws AuthFailureError { Map localMap = this.mApiContext.getHeaders(); if (this.mExtraHeaders != null) { localMap.putAll(this.mExtraHeaders); } if (this.mResponseVerifier != null) {} try { localMap.put("X-DFE-Signature-Request", this.mResponseVerifier.getSignatureRequest()); RetryPolicy localRetryPolicy = this.mRetryPolicy; String str = "timeoutMs=" + localRetryPolicy.getCurrentTimeout(); int i = localRetryPolicy.getCurrentRetryCount(); if (i > 0) { str = str + "; retryAttempt=" + i; } localMap.put("X-DFE-Request-Params", str); return localMap; } catch (DfeResponseVerifier.DfeResponseVerifierException localDfeResponseVerifierException) { for (;;) { PlayCommonLog.d("Couldn't create signature request: %s", new Object[] { localDfeResponseVerifierException }); cancel(); } } }