@Override public void nextTask() { synchronized (mNextTaskLockObj) { if (!mNextTaskLock) { mNextTaskLock = true; // TODO mDownloadingTasks 同步状态(临时解决方案) synchronized (mIteratorLock) { Iterator<DownloadInfo> downloadingIt = mDownloadingTasks.iterator(); while (downloadingIt.hasNext()) { DownloadInfo b = downloadingIt.next(); if (b.getState() == DownloadInfo.PAUSE) { mPausingTasks.add(b); try { downloadingIt.remove(); } catch (Exception e) { Logger.e(e); } } else if (b.getState() == DownloadInfo.COMPLETE) { mCompleteTasks.add(b); try { downloadingIt.remove(); } catch (Exception e) { Logger.e(e); } } } } synchronized (mIteratorLock) { Iterator<Map.Entry<String, DownloadHttpTask>> downloadinMapIt = mDownloadingTaskMap.entrySet().iterator(); while (downloadinMapIt.hasNext()) { Map.Entry<String, DownloadHttpTask> entry = downloadinMapIt.next(); DownloadHttpTask task = entry.getValue(); if (task != null && task.isInterrupt()) { try { downloadinMapIt.remove(); } catch (Exception e) { Logger.e(e); } } } } executeNextTask(); mNextTaskLock = false; } } }
@Override public void onSuccess(ResponseInfo<File> responseInfo) { HttpHandler<File> handler = downloadInfo.getHandler(); if (handler != null) { downloadInfo.setState(handler.getState()); } Log.e("TAG", "*******downloadInfo.state=" + downloadInfo.getState()); infoImpl.saveOrUpdate( downloadInfo, "downloadUrl=?", new String[] {downloadInfo.getDownloadUrl()}); if (baseCallBack != null) { baseCallBack.onSuccess(responseInfo); } }