/** fill given DownloadInformations with current details of this DownloadController */ protected void getDownloadStatus(final DownloadInformations ds) { ds.reset(); ds.addRunningDownloads(DownloadWatchDog.getInstance().getActiveDownloads()); final boolean readL = readLock(); try { LinkStatus linkStatus; boolean isEnabled; for (final FilePackage fp : packages) { synchronized (fp) { ds.addPackages(1); ds.addDownloadLinks(fp.size()); for (final DownloadLink l : fp.getChildren()) { linkStatus = l.getLinkStatus(); isEnabled = l.isEnabled(); if (!linkStatus.hasStatus(LinkStatus.ERROR_ALREADYEXISTS) && isEnabled) { ds.addTotalDownloadSize(l.getDownloadSize()); ds.addCurrentDownloadSize(l.getDownloadCurrent()); } if (linkStatus.hasStatus(LinkStatus.ERROR_ALREADYEXISTS)) { ds.addDuplicateDownloads(1); } else if (!isEnabled) { ds.addDisabledDownloads(1); } else if (linkStatus.hasStatus(LinkStatus.FINISHED)) { ds.addFinishedDownloads(1); } } } } } finally { readUnlock(readL); } }
public FilePackageStorable(FilePackage filePackage) { this.filePackage = filePackage; links = new ArrayList<DownloadLinkStorable>(filePackage.size()); boolean readL = filePackage.getModifyLock().readLock(); try { for (DownloadLink link : filePackage.getChildren()) { links.add(new DownloadLinkStorable(link)); } } finally { filePackage.getModifyLock().readUnlock(readL); } }