Esempio n. 1
0
    public AggregatedNumbers(SelectionInfo<FilePackage, DownloadLink> selection) {
        totalBytes = 0l;
        disabledTotalBytes = 0l;
        disabledLoadedBytes = 0l;

        loadedBytes = 0l;
        downloadSpeed = 0l;
        running = 0l;
        connections = 0l;
        packageCount = selection.getPackageViews().size();
        linkCount = selection.getChildren().size();
        downloadsFinished = 0l;
        downloadsFailed = 0l;
        downloadsSkipped = 0l;
        disabledDownloadsFinished = 0l;
        disabledDownloadsFailed = 0l;
        disabledDownloadsSkipped = 0l;
        for (DownloadLink dl : selection.getChildren()) {
            if (dl == null) continue;

            if (dl.isEnabled()) {
                FinalLinkState state = dl.getFinalLinkState();
                if (state == null) {
                    if (dl.isSkipped()) {
                        downloadsSkipped++;
                    }
                } else {
                    if (state.isFailed()) {
                        downloadsFailed++;
                    } else if (state.isFinished()) {
                        downloadsFinished++;
                    }
                }
                totalBytes += dl.getView().getBytesTotalEstimated();
                loadedBytes += dl.getView().getBytesLoaded();

            } else {
                FinalLinkState state = dl.getFinalLinkState();
                if (state == null) {
                    if (dl.isSkipped()) {
                        disabledDownloadsSkipped++;
                    }
                } else {
                    if (state.isFailed()) {
                        disabledDownloadsFailed++;
                    } else if (state.isFinished()) {
                        disabledDownloadsFinished++;
                    }
                }
                disabledTotalBytes += dl.getView().getBytesTotalEstimated();
                disabledLoadedBytes += dl.getView().getBytesLoaded();

            }

            downloadSpeed += dl.getView().getSpeedBps();
            SingleDownloadController sdc = dl.getDownloadLinkController();
            if (sdc != null) {
                running++;
                DownloadInterface conInst = sdc.getDownloadInstance();
                if (conInst != null) {
                    ManagedThrottledConnectionHandler handlerP = conInst.getManagedConnetionHandler();
                    if (handlerP != null) {
                        connections += handlerP.size();

                    }

                }
            }

        }

        eta = downloadSpeed == 0 ? 0 : (totalBytes - loadedBytes) / downloadSpeed;

    }