Example usage for android.os SystemClock sleep

List of usage examples for android.os SystemClock sleep

Introduction

In this page you can find the example usage for android.os SystemClock sleep.

Prototype

public static void sleep(long ms) 

Source Link

Document

Waits a given number of milliseconds (of uptimeMillis) before returning.

Usage

From source file:com.my.cloudcontact.http.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.booleanValue());

    if (executionCount > maxRetries) {
        // ?5//from  w w  w  .  j  ava2s . 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) {
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);
        retry = currentReq != null && !"POST".equals(currentReq.getMethod());
    }

    if (retry) {
        // 1???
        SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}

From source file:com.example.levelup.core.app.net.RequestLoader.java

@Override
public RequestResult<T> loadInBackground() {
    T result = null;/*from  w ww . j a va2 s . co m*/

    LevelUpConnection connection = LevelUpConnection.newInstance(getContext());

    LogManager.v("Sending request %s...", mRequest);
    LevelUpResponse response = connection.send(mRequest);

    // A helpful delay for debugging. See Constants.
    if (Constants.ASYNC_BACKGROUND_TASK_DELAY_ENABLED) {
        SystemClock.sleep(Constants.ASYNC_BACKGROUND_TASK_DELAY_MS);
    }

    LogManager.v("Got response %s", response);

    String data = response.getData();
    List<Error> errors = null;

    try {
        if (response.getStatus().equals(LevelUpStatus.OK)) {
            LogManager.v("Parsing response...");
            result = mModelFactory.from(new JSONObject(data));
        } else {
            /*
             * The LevelUp web service returns JSON arrays of errors in its responses. In a
             * real-world application, this should probably check the Content-Type returned
             * before attempting to parse it as JSON.
             */
            if (!TextUtils.isEmpty(data.trim())) {
                errors = new ErrorJsonFactory().fromList(new JSONArray(data));
            }
        }
    } catch (JSONException e) {
        // Don't mask other errors with a parsing error.
        if (response.getStatus().equals(LevelUpStatus.OK)) {
            LogManager.e("JSONException while parsing model", e);
            response = new LevelUpResponse(data, LevelUpStatus.ERROR_PARSING);
        }
    }

    return new RequestResult<T>(response, result, errors);
}

From source file:com.evernote.android.job.JobRescheduleService.java

@Override
protected void onHandleWork(@NonNull Intent intent) {
    /*//from w  w  w . ja  v a 2  s . c  o m
     * Delay this slightly. This avoids a race condition if the app was launched by the
     * AlarmManager. Then the alarm was already removed, but the JobRequest might still
     * be available in the storage. We still catch this case, because we never execute
     * a job with the same ID twice. Nonetheless, add the delay to save resources.
     */
    try {
        CAT.d("Reschedule service started");
        SystemClock.sleep(JobConfig.getJobReschedulePause());

        JobManager manager;
        try {
            manager = JobManager.create(this);
        } catch (Exception e) {
            return;
        }

        Set<JobRequest> requests = manager.getAllJobRequests(null, true, true);

        int rescheduledCount = rescheduleJobs(manager, requests);

        CAT.d("Reschedule %d jobs of %d jobs", rescheduledCount, requests.size());
    } finally {
        if (latch != null) {
            // latch can be null, if the service was restarted after a process death
            latch.countDown();
        }
    }
}

From source file:com.cndatacom.ordersystem.manager.RetryHandler.java

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.booleanValue());

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;//from   w w w  .ja va  2  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);
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }

    if (retry) {
        SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}

From source file:org.cook_e.cook_e.ui.HomeActivityTest.java

/**
 * Tests the display of tabs on the home page and the selection of tabs by clicking on them
 *//*w w w  .j  a  va 2 s .  c o  m*/
public void testTabs() {
    final Matcher<View> mealsTab = withText(R.string.meals);
    final Matcher<View> recipesTab = withText(R.string.recipes);
    final Matcher<View> mealList = withTagKey(R.id.test_tag_meal_list, Is.<Object>is("Meal List"));
    final Matcher<View> recipeList = withTagKey(R.id.test_tag_recipe_list, Is.<Object>is("Recipe List"));

    onView(recipesTab).perform(click());
    SystemClock.sleep(SWITCH_DELAY_MS);
    onView(recipesTab).check(matches(isSelected()));
    onView(mealsTab).perform(click());
    SystemClock.sleep(SWITCH_DELAY_MS);
    onView(mealsTab).check(matches(isSelected()));
}

From source file:com.android.pchelper.http.RetryHandler.java

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.booleanValue());

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;/*from w  ww .  j av  a 2s . c  o m*/
    } 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);
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }

    if (retry) {
        SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}

From source file:cn.com.loopj.android.http.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  w  w  w  . ja  va2s .  c  o  m
    } else if (isInList(exceptionWhitelist, exception)) {
        // immediately retry if error is whitelisted
        retry = true;
    } else if (isInList(exceptionBlacklist, exception)) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } 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.aoeng.degu.utils.net.asyncthhpclient.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   w  ww.  ja v a 2 s. co  m
    } 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:cn.openwatch.internal.http.loopj.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;/*ww w  .j  a  v a 2 s .  c o m*/
    } else if (isInList(exceptionWhitelist, exception)) {
        // immediately retry if error is whitelisted
        retry = true;
    } else if (isInList(exceptionBlacklist, exception)) {
        // immediately cancel retry if the error is blacklisted
        retry = false;
    } 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 {
    }

    return retry;
}

From source file:com.elephant.http.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.booleanValue());

    if (executionCount > maxRetries) {
        // Do not retry if over max retry count
        retry = false;//w w  w.j  a  va  2 s . c o  m
    } 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);
        String requestType = currentReq.getMethod();
        retry = !requestType.equals("POST");
    }

    if (retry) {
        SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS);
    } else {
        exception.printStackTrace();
    }

    return retry;
}