Exemplo n.º 1
0
  /**
   * @param now what time is it now
   * @return whether the in-network downloader is considered hopeless
   */
  private boolean isHopeless(InNetworkDownloader downloader, long now) {
    if (now - downloader.getStartTime()
        < UpdateSettings.UPDATE_GIVEUP_FACTOR.getValue()
            * UpdateSettings.UPDATE_DOWNLOAD_DELAY.getValue()) return false;

    if (downloader.getDownloadAttempts() < UpdateSettings.UPDATE_MIN_ATTEMPTS.getValue())
      return false;

    return true;
  }
Exemplo n.º 2
0
  /** @return whether we killed any hopeless update downloads */
  private void killHopelessUpdates(List<? extends DownloadInformation> updates) {
    if (updates == null) return;

    if (!downloadManager.get().hasInNetworkDownload()) return;

    long now = clock.now();
    for (DownloadInformation info : updates) {
      Downloader downloader = downloadManager.get().getDownloaderForURN(info.getUpdateURN());
      if (downloader != null && downloader instanceof InNetworkDownloader) {
        InNetworkDownloader iDownloader = (InNetworkDownloader) downloader;
        if (isHopeless(iDownloader, now)) iDownloader.stop(false);
      }
    }
  }