Java Code Examples for com.liulishuo.filedownloader.model.FileDownloadStatus#toLaunchPool()

The following examples show how to use com.liulishuo.filedownloader.model.FileDownloadStatus#toLaunchPool() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileDownloadList.java    From FileDownloader with Apache License 2.0 6 votes vote down vote up
List<BaseDownloadTask.IRunningTask> getReceiveServiceTaskList(final int id) {
    final List<BaseDownloadTask.IRunningTask> list = new ArrayList<>();
    synchronized (this.mList) {
        for (BaseDownloadTask.IRunningTask task : this.mList) {
            if (task.is(id) && !task.isOver()) {

                final byte status = task.getOrigin().getStatus();
                if (status != FileDownloadStatus.INVALID_STATUS
                        && status != FileDownloadStatus.toLaunchPool) {
                    list.add(task);
                }
            }
        }
    }

    return list;
}
 
Example 2
Source File: DownloadTaskHunter.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@Override
public void intoLaunchPool() {
    synchronized (mPauseLock) {
        if (mStatus != FileDownloadStatus.INVALID_STATUS) {
            FileDownloadLog.w(this, "High concurrent cause, this task %d will not input "
                            + "to launch pool, because of the status isn't idle : %d",
                    getId(), mStatus);
            return;
        }

        mStatus = FileDownloadStatus.toLaunchPool;
    }

    final BaseDownloadTask.IRunningTask runningTask = mTask.getRunningTask();
    final BaseDownloadTask origin = runningTask.getOrigin();

    if (FileDownloadMonitor.isValid()) {
        FileDownloadMonitor.getMonitor().onRequestStart(origin);
    }

    if (FileDownloadLog.NEED_LOG) {
        FileDownloadLog.v(this, "call start "
                        + "Url[%s], Path[%s] Listener[%s], Tag[%s]",
                origin.getUrl(), origin.getPath(), origin.getListener(), origin.getTag());
    }

    boolean ready = true;

    try {
        prepare();
    } catch (Throwable e) {
        ready = false;

        FileDownloadList.getImpl().add(runningTask);
        FileDownloadList.getImpl().remove(runningTask, prepareErrorMessage(e));
    }

    if (ready) {
        FileDownloadTaskLauncher.getImpl().launch(this);
    }

    if (FileDownloadLog.NEED_LOG) {
        FileDownloadLog.v(this, "the task[%d] has been into the launch pool.", getId());
    }
}
 
Example 3
Source File: DownloadTaskHunter.java    From FileDownloader with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("checkstyle:emptyblock")
@Override
public void start() {
    if (mStatus != FileDownloadStatus.toLaunchPool) {
        FileDownloadLog.w(this, "High concurrent cause, this task %d will not start,"
                        + " because the of status isn't toLaunchPool: %d",
                getId(), mStatus);
        return;
    }

    final BaseDownloadTask.IRunningTask runningTask = mTask.getRunningTask();
    final BaseDownloadTask origin = runningTask.getOrigin();

    final ILostServiceConnectedHandler lostConnectedHandler = FileDownloader.getImpl().
            getLostConnectedHandler();
    try {

        if (lostConnectedHandler.dispatchTaskStart(runningTask)) {
            return;
        }

        synchronized (mPauseLock) {
            if (mStatus != FileDownloadStatus.toLaunchPool) {
                FileDownloadLog.w(this, "High concurrent cause, this task %d will not start,"
                                + " the status can't assign to toFileDownloadService, because "
                                + "the status isn't toLaunchPool: %d",
                        getId(), mStatus);
                return;
            }

            mStatus = FileDownloadStatus.toFileDownloadService;
        }

        FileDownloadList.getImpl().add(runningTask);
        if (FileDownloadHelper.inspectAndInflowDownloaded(
                origin.getId(), origin.getTargetFilePath(), origin.isForceReDownload(), true)
                ) {
            // Will be removed when the complete message is received in #update
            return;
        }

        final boolean succeed = FileDownloadServiceProxy.getImpl().
                start(
                        origin.getUrl(),
                        origin.getPath(),
                        origin.isPathAsDirectory(),
                        origin.getCallbackProgressTimes(),
                        origin.getCallbackProgressMinInterval(),
                        origin.getAutoRetryTimes(),
                        origin.isForceReDownload(),
                        mTask.getHeader(),
                        origin.isWifiRequired());

        if (mStatus == FileDownloadStatus.paused) {
            FileDownloadLog.w(this, "High concurrent cause, this task %d will be paused,"
                            + "because of the status is paused, so the pause action must be "
                            + "applied",
                    getId());
            if (succeed) {
                FileDownloadServiceProxy.getImpl().pause(getId());
            }
            return;
        }

        if (!succeed) {
            //noinspection StatementWithEmptyBody
            if (!lostConnectedHandler.dispatchTaskStart(runningTask)) {
                final MessageSnapshot snapshot = prepareErrorMessage(
                        new RuntimeException("Occur Unknown Error, when request to start"
                                + " maybe some problem in binder, maybe the process was killed "
                                + "in unexpected."));

                if (FileDownloadList.getImpl().isNotContains(runningTask)) {
                    lostConnectedHandler.taskWorkFine(runningTask);
                    FileDownloadList.getImpl().add(runningTask);
                }

                FileDownloadList.getImpl().remove(runningTask, snapshot);

            } else {
                // the FileDownload Service host process was killed when request stating and it
                // will be restarted by LostServiceConnectedHandler.
            }
        } else {
            lostConnectedHandler.taskWorkFine(runningTask);
        }

    } catch (Throwable e) {
        e.printStackTrace();

        FileDownloadList.getImpl().remove(runningTask, prepareErrorMessage(e));
    }
}