List of usage examples for android.os SystemClock sleep
public static void sleep(long ms)
From source file:com.xc.framework.https.client.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int retriedTimes, HttpContext context) { boolean retry = true; if (exception == null || context == null) { return false; }/*from ww w . ja v a 2s.c o m*/ Object isReqSent = context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = isReqSent == null ? false : (Boolean) isReqSent; if (retriedTimes > maxRetries) { retry = false; } else if (exceptionBlackList.contains(exception.getClass())) { retry = false; } else if (exceptionWhiteList.contains(exception.getClass())) { retry = true; } else if (!sent) { retry = true; } if (retry) { try { Object currRequest = context.getAttribute(ExecutionContext.HTTP_REQUEST); if (currRequest != null) { if (currRequest instanceof HttpRequestBase) { HttpRequestBase requestBase = (HttpRequestBase) currRequest; retry = "GET".equals(requestBase.getMethod()); } else if (currRequest instanceof RequestWrapper) { RequestWrapper requestWrapper = (RequestWrapper) currRequest; retry = "GET".equals(requestWrapper.getMethod()); } } else { retry = false; Log.e("RetryHandler", "retry error, curr request is null"); } } catch (Throwable e) { retry = false; Log.e("retry error", "" + e); } } if (retry) { SystemClock.sleep(RETRY_SLEEP_INTERVAL); // sleep a while and retry // http request again. } return retry; }
From source file:cn.isif.util_plus.http.client.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int retriedTimes, HttpContext context) { boolean retry = true; if (exception == null || context == null) { return false; }// w w w .j ava2 s.c o m Object isReqSent = context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = isReqSent == null ? false : (Boolean) isReqSent; if (retriedTimes > maxRetries) { retry = false; } else if (exceptionBlackList.contains(exception.getClass())) { retry = false; } else if (exceptionWhiteList.contains(exception.getClass())) { retry = true; } else if (!sent) { retry = true; } if (retry) { try { Object currRequest = context.getAttribute(ExecutionContext.HTTP_REQUEST); if (currRequest != null) { if (currRequest instanceof HttpRequestBase) { HttpRequestBase requestBase = (HttpRequestBase) currRequest; retry = "GET".equals(requestBase.getMethod()); } else if (currRequest instanceof RequestWrapper) { RequestWrapper requestWrapper = (RequestWrapper) currRequest; retry = "GET".equals(requestWrapper.getMethod()); } } else { retry = false; LogUtils.e("retry error, curr request is null"); } } catch (Throwable e) { retry = false; LogUtils.e("retry error", e); } } if (retry) { SystemClock.sleep(RETRY_SLEEP_INTERVAL); // sleep a while and retry http request again. } return retry; }
From source file:com.uwindsor.elgg.project.http.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // Do not retry if over max retry count retry = false;/*from w w w . j a va2s .com*/ } else if (exceptionBlacklist.contains(exception.getClass())) { // immediately cancel retry if the error is blacklisted retry = false; } else if (exceptionWhitelist.contains(exception.getClass())) { // immediately retry if error is whitelisted retry = true; } else if (!sent) { // for most other errors, retry only if request hasn't been fully sent yet retry = true; } else { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); String requestType = currentReq.getMethod(); if (!requestType.equals("POST")) { retry = true; } else { // otherwise do not retry retry = false; } } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:com.drive.student.xutils.http.client.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int retriedTimes, HttpContext context) { boolean retry = true; if (exception == null || context == null) { return false; }//from www . j a v a 2 s.c o m Object isReqSent = context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = isReqSent == null ? false : (Boolean) isReqSent; if (retriedTimes > maxRetries) { retry = false; } else if (exceptionBlackList.contains(exception.getClass())) { retry = false; } else if (exceptionWhiteList.contains(exception.getClass())) { retry = true; } else if (!sent) { retry = true; } if (retry) { try { Object currRequest = context.getAttribute(ExecutionContext.HTTP_REQUEST); if (currRequest != null) { if (currRequest instanceof HttpRequestBase) { HttpRequestBase requestBase = (HttpRequestBase) currRequest; retry = "GET".equals(requestBase.getMethod()); } else if (currRequest instanceof RequestWrapper) { RequestWrapper requestWrapper = (RequestWrapper) currRequest; retry = "GET".equals(requestWrapper.getMethod()); } } else { retry = false; LogUtils.e("retry error, curr request is null"); } } catch (Throwable e) { retry = false; LogUtils.e("retry error", e); } } if (retry) { SystemClock.sleep(RETRY_SLEEP_INTERVAL); // sleep a while and retry // http request again. } return retry; }
From source file:com.DGSD.DGUtils.Http.BetterHttpRequestRetryHandler.java
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry; this.timesRetried = executionCount; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // Do not retry if over max retry count retry = false;/*from w w w . ja v a 2s . co m*/ } else if (exceptionBlacklist.contains(exception.getClass())) { // immediately cancel retry if the error is blacklisted retry = false; } else if (exceptionWhitelist.contains(exception.getClass())) { // immediately retry if error is whitelisted retry = true; } else if (!sent) { // for all other errors, retry only if request hasn't been fully sent yet // TODO: refine to resend all idempotent requests retry = true; } else { // otherwise do not retry retry = false; } if (retry) { Log.e(BetterHttp.LOG_TAG, "request failed (" + exception.getClass().getCanonicalName() + ": " + exception.getMessage() + " / attempt " + executionCount + "), will retry in " + RETRY_SLEEP_TIME_MILLIS / 1000.0 + " seconds"); SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { Log.e(BetterHttp.LOG_TAG, "request failed after " + executionCount + " attempts"); exception.printStackTrace(); } return retry; }
From source file:com.flyn.net.asynchttp.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry = true; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b); if (executionCount > maxRetries) { // Do not retry if over max retry count retry = false;//from www . j a v a 2s.c om } else if (isInList(exceptionBlacklist, exception)) { // immediately cancel retry if the error is blacklisted retry = false; } else if (isInList(exceptionWhitelist, exception)) { // immediately retry if error is whitelisted retry = true; } else if (!sent) { // for most other errors, retry only if request hasn't been fully // sent yet retry = true; } if (retry) { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); if (currentReq == null) { return false; } } if (retry) { SystemClock.sleep(retrySleepTimeMS); } else { exception.printStackTrace(); } return retry; }
From source file:com.vdisk.net.session.RetryHandler.java
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { boolean retry = true; Log.d("Test", "retry count->" + executionCount); Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (executionCount > maxRetries) { // Do not retry if over max retry count retry = false;//from www . j a v a2 s .co m } else if (exceptionBlacklist.contains(exception.getClass())) { // immediately cancel retry if the error is blacklisted retry = false; } else if (exceptionWhitelist.contains(exception.getClass())) { // immediately retry if error is whitelisted retry = true; } else if (!sent) { // for most other errors, retry only if request hasn't been fully sent yet retry = true; } if (retry) { // resend all idempotent requests HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST); Log.d("Test", "HttpUriRequest:" + currentReq); if (currentReq != null) { String requestType = currentReq.getMethod(); retry = !requestType.equals("POST") && !requestType.equals("PUT"); } } if (retry) { SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); } else { exception.printStackTrace(); } return retry; }
From source file:edu.umich.flowfence.testapp.TestQM.java
public static String sleep(long millis) { long startNanos = SystemClock.elapsedRealtimeNanos(); SystemClock.sleep(millis); long endNanos = SystemClock.elapsedRealtimeNanos(); return endNanos - startNanos + " ns"; }
From source file:com.example.carrc.seniorproject.MenuActivity.java
public void test() { getRecipes();//from ww w . j a va 2s. co m for (int i = 0; i < recipeIDs.length; i++) { ParseQuery<ParseObject> query = ParseQuery.getQuery("Recipes"); query.whereEqualTo("FoodID", recipeIDs[i]); try { List<ParseObject> queryList = query.find(); if (queryList.size() == 0) { System.out.println(recipeIDs[i]); System.out.println("waiting .5 second..."); SystemClock.sleep(500); response = Unirest .get("https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/" + recipeIDs[i] + "/information?includeNutrition=false") .header("X-Mashape-Key", "cfCeth6V86mshu6OGAO9QCgv8vy7p1MHJYZjsnhCMiRIAdAEmm") .header("Accept", "application/json").asJsonAsync(new Callback<JsonNode>() { @Override public void completed(HttpResponse<JsonNode> response) { ParseObject recipe = new ParseObject("Recipes"); String responseString = response.getBody().toString(); JSONObject jObj = null; try { jObj = new JSONObject(responseString); String formatCourseType = courseType.replace("+", ""); recipe.put("mealType", mealType); recipe.put("course", formatCourseType); recipe.put("ItemTitle", jObj.getString("title")); recipe.put("FoodID", jObj.getString("id")); recipe.put("Image", jObj.getString("image")); recipe.put("PricePerServing", jObj.getString("pricePerServing")); recipe.put("vegetarian", jObj.getString("vegetarian")); recipe.put("vegan", jObj.getString("vegan")); recipe.put("glutenFree", jObj.getString("glutenFree")); recipe.put("dairyFree", jObj.getString("dairyFree")); String[] intolerancesArray = intolerances.split("%2C"); for (String intolerance : intolerancesArray) { switch (intolerance) { case "egg": recipe.put("eggFree", "true"); break; case "peanut": recipe.put("peanutFree", "true"); break; case "sesame": recipe.put("sesameFree", "true"); break; case "seafood": recipe.put("seafoodFree", "true"); break; case "shellfish": recipe.put("shellfishFree", "true"); break; case "soy": recipe.put("soyFree", "true"); break; case "wheat": recipe.put("wheatFree", "true"); break; default: break; } } JSONArray ingredientArray = jObj.getJSONArray("extendedIngredients"); int len = ingredientArray.length(); for (int j = 0; j < len; j++) { JSONObject json = ingredientArray.getJSONObject(j); recipe.put("IngredientName" + j, json.getString("name")); recipe.put("IngredientID" + j, json.getString("id")); recipe.put("IngredientAmount" + j, json.getString("amount")); recipe.put("IngredientUnit" + j, "oz"); ParseQuery<ParseObject> query = ParseQuery.getQuery("Ingredients"); query.whereEqualTo("ID", json.getString("id")); if (query.find().size() == 0) { ParseObject ingredientsObj = new ParseObject("Ingredients"); ingredientsObj.put("ID", json.getString("id")); ingredientsObj.put("Name", json.getString("name")); ingredientsObj.put("Unit", "oz"); ingredientsObj.put("Quantity", "100"); ingredientsObj.saveInBackground(); } } downloadTask2 task = new downloadTask2(); task.execute(recipe); } catch (JSONException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } } @Override public void failed(UnirestException e) { } @Override public void cancelled() { } }); } else { Log.i("Recipe", "Recipe Exists"); } } catch (ParseException e) { e.printStackTrace(); } } }
From source file:com.android.idtt.http.RetryHandler.java
@Override public boolean retryRequest(IOException exception, int retriedTimes, HttpContext context) { boolean retry = true; Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); boolean sent = (b != null && b.booleanValue()); if (retriedTimes > maxRetries) { // ?5//ww w . jav a 2 s. c o m retry = false; } else if (exceptionBlackList.contains(exception.getClass())) { // ?? retry = false; } else if (exceptionWhiteList.contains(exception.getClass())) { retry = true; } else if (!sent) { retry = true; } if (retry) { try { Object currRequest = context.getAttribute(ExecutionContext.HTTP_REQUEST); if (currRequest != null) { if (currRequest instanceof HttpRequestBase) { HttpRequestBase requestBase = (HttpRequestBase) currRequest; retry = requestBase != null && "GET".equals(requestBase.getMethod()); } else if (currRequest instanceof RequestWrapper) { RequestWrapper requestWrapper = (RequestWrapper) currRequest; retry = requestWrapper != null && "GET".equals(requestWrapper.getMethod()); } } else { LogUtils.e("retry error, curr request is null"); } } catch (Exception e) { retry = false; LogUtils.e("retry error", e); } } if (retry) { //1??? SystemClock.sleep(RETRY_SLEEP_INTERVAL); } else { LogUtils.e(exception.getMessage(), exception); } return retry; }