/** * Why pause? not stop? because invoke this method(pause) will clear all data about this task in * memory, and stop the total processing about this task. but when you start the paused task, it * would be continue downloading from the breakpoint as default. * * @return If true, successful pause this task by status of pause, otherwise this task has already * in over status before invoke this method(Maybe occur high concurrent situation). * @see FileDownloader#pause(int) * @see FileDownloader#pause(FileDownloadListener) * @see FileDownloader#pauseAll() */ public boolean pause() { if (FileDownloadStatus.isOver(getStatus())) { if (FileDownloadLog.NEED_LOG) { /** * The over-status call-backed and set the over-status to this task between here area and * remove from the {@link FileDownloadList}. * * <p>High concurrent cause. */ FileDownloadLog.d( this, "High concurrent cause, Already is over, can't pause " + "again, %d %d", getStatus(), getId()); } return false; } setStatus(FileDownloadStatus.paused); _pauseExecute(); calcAverageSpeed(this.soFarBytes); // For make sure already added event listener for receive paused event FileDownloadList.getImpl().add(this); FileDownloadList.getImpl().remove(this, MessageSnapshotTaker.catchPause(this)); return true; }
MessageSnapshot catchException(Throwable ex) { setStatus(FileDownloadStatus.error); this.ex = ex; return MessageSnapshotTaker.catchException(this); }