public void enqueueTask() { Response response = null; int maxRetry = lite.settings.getMaxRetryCount(); while (retryCount <= maxRetry && !isCanceled()) { try { if (retryCount > 0) { callback.onRetry(retryCount, maxRetry); } retryCount++; response = execute(); if (response != null) { break; } } catch (Exception e) { e.printStackTrace(); if (retryCount > maxRetry || e instanceof CanceledException) { callback.onFailed(e); return; } } } if (!isCanceled()) { onResponse(response); } else { callback.onFailed(new CanceledException("URLTask has been canceled")); } }
public void onResponse(Response response) { callback.onResponse(response); }
public void cancel() { isCanceled = true; callback.onCancel(); }