Search in sources :

Example 76 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class TagDownloadWithState method checkAggregateShareRatio.

private void checkAggregateShareRatio() {
    if (max_aggregate_share_ratio > 0) {
        if (TorrentUtils.isTorrentDeleting() || TorrentUtils.getMillisecondsSinceLastTorrentDelete() < 10 * 1000) {
            return;
        }
        updateStuff();
        if (aggregate_sr >= max_aggregate_share_ratio) {
            Set<DownloadManager> dms = new HashSet<>(getTaggedDownloads());
            Iterator<DownloadManager> it = dms.iterator();
            while (it.hasNext()) {
                DownloadManager dm = it.next();
                if (dm.isForceStart() || !dm.isDownloadComplete(false)) {
                    it.remove();
                } else {
                    if ((!max_aggregate_share_ratio_priority) && max_share_ratio > 0) {
                        int sr = dm.getStats().getShareRatio();
                        if (sr < max_share_ratio) {
                            // individual has priority over aggregate and this download hasn't met
                            // its ratio yet
                            it.remove();
                            continue;
                        }
                    }
                    List<Tag> all_tags = getTagType().getTagManager().getTagsForTaggable(dm);
                    for (Tag tag : all_tags) {
                        if (tag != this && tag instanceof TagDownloadWithState) {
                            TagDownloadWithState other_tag = (TagDownloadWithState) tag;
                            if (!other_tag.isAggregateShareRatioMet()) {
                                it.remove();
                                break;
                            }
                        }
                    }
                }
            }
            performOperation(max_aggregate_share_ratio_action == TagFeatureRateLimit.SR_ACTION_PAUSE ? TagFeatureRunState.RSC_PAUSE : TagFeatureRunState.RSC_STOP, dms);
        } else {
            performOperation(max_aggregate_share_ratio_action == TagFeatureRateLimit.SR_ACTION_PAUSE ? TagFeatureRunState.RSC_RESUME : TagFeatureRunState.RSC_START);
        }
    }
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Example 77 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class TagDownloadWithState method updateStuff.

private void updateStuff() {
    long now = SystemTime.getCurrentTime();
    if (now - last_rate_update > 2500) {
        int new_up = 0;
        int new_down = 0;
        long new_agg_up = 0;
        long new_agg_down = 0;
        Set<DownloadManager> dms = getTaggedDownloads();
        if (dms.size() == 0) {
            new_up = -1;
            new_down = -1;
        } else {
            new_up = 0;
            new_down = 0;
            for (DownloadManager dm : dms) {
                DownloadManagerStats stats = dm.getStats();
                new_up += stats.getDataSendRate() + stats.getProtocolSendRate();
                new_down += stats.getDataReceiveRate() + stats.getProtocolReceiveRate();
                long downloaded = stats.getTotalGoodDataBytesReceived();
                long uploaded = stats.getTotalDataBytesSent();
                if (downloaded > 0) {
                    new_agg_down += downloaded;
                }
                if (uploaded > 0) {
                    new_agg_up += uploaded;
                }
            }
        }
        upload_rate = new_up;
        download_rate = new_down;
        aggregate_sr = new_agg_down <= 0 ? 0 : (int) ((1000 * new_agg_up) / new_agg_down);
        last_rate_update = now;
    }
}
Also used : DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 78 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class TagDownloadWithState method setTagUploadPriority.

@Override
public void setTagUploadPriority(int priority) {
    if (priority < 0) {
        priority = 0;
    }
    if (priority == upload_priority) {
        return;
    }
    int old_up = upload_priority;
    upload_priority = priority;
    writeLongAttribute(AT_RATELIMIT_UP_PRI, priority);
    if (old_up == 0 || priority == 0) {
        Set<DownloadManager> dms = getTaggedDownloads();
        for (DownloadManager dm : dms) {
            dm.updateAutoUploadPriority(UPLOAD_PRIORITY_ADDED_KEY, priority > 0);
        }
    }
    getTagType().fireChanged(this);
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Example 79 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class TagDownloadWithState method checkIndividualShareRatio.

private void checkIndividualShareRatio() {
    if (max_share_ratio <= 0) {
        return;
    }
    if (max_share_ratio_action == TagFeatureRateLimit.SR_ACTION_QUEUE) {
        return;
    }
    if (max_aggregate_share_ratio_priority && max_aggregate_share_ratio > 0) {
        updateStuff();
        if (aggregate_sr < max_aggregate_share_ratio) {
            return;
        }
    }
    Set<DownloadManager> dms = getTaggedDownloads();
    Set<DownloadManager> to_action = new HashSet<>();
    for (DownloadManager dm : dms) {
        if (dm.isDownloadComplete(false) && !dm.isForceStart()) {
            int state = dm.getState();
            if (state == DownloadManager.STATE_QUEUED || state == DownloadManager.STATE_SEEDING) {
                int sr = dm.getStats().getShareRatio();
                if (sr >= max_share_ratio) {
                    to_action.add(dm);
                }
            }
        }
    }
    if (to_action.size() > 0) {
        performOperation(max_share_ratio_action == TagFeatureRateLimit.SR_ACTION_PAUSE ? TagFeatureRunState.RSC_PAUSE : TagFeatureRunState.RSC_STOP, to_action);
    }
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Example 80 with DownloadManager

use of com.biglybt.core.download.DownloadManager in project BiglyBT by BiglySoftware.

the class TagDownloadWithState method addTaggable.

@Override
public void addTaggable(Taggable t) {
    if (t instanceof DownloadManager) {
        final DownloadManager dm = (DownloadManager) t;
        if (dm.isDestroyed()) {
        // There's a race condition when stopping and removing a torrent that isn't easy to avoid in terms
        // of a download being added to the 'stopped' tag and concurrently removed.
        // There will be a subseqent 'downloadRemoved' action triggered that should tidy up any
        // inconsistency left due to this
        // Debug.out( "Invalid Taggable added - download is destroyed: " + dm.getDisplayName());
        } else {
            super.addTaggable(t);
            int actions = getSupportedActions();
            if (actions != TagFeatureExecOnAssign.ACTION_NONE) {
                if (isActionEnabled(TagFeatureExecOnAssign.ACTION_START) || isActionEnabled(TagFeatureExecOnAssign.ACTION_RESUME)) {
                    int dm_state = dm.getState();
                    if (dm_state == DownloadManager.STATE_STOPPED || dm_state == DownloadManager.STATE_ERROR) {
                        rs_async.dispatch(new AERunnable() {

                            @Override
                            public void runSupport() {
                                if (isActionEnabled(TagFeatureExecOnAssign.ACTION_START)) {
                                    dm.setStateQueued();
                                } else {
                                    dm.resume();
                                }
                            }
                        });
                    }
                } else if (isActionEnabled(TagFeatureExecOnAssign.ACTION_STOP) || isActionEnabled(TagFeatureExecOnAssign.ACTION_PAUSE)) {
                    int dm_state = dm.getState();
                    if (dm_state != DownloadManager.STATE_STOPPED && dm_state != DownloadManager.STATE_STOPPING && dm_state != DownloadManager.STATE_ERROR) {
                        rs_async.dispatch(new AERunnable() {

                            @Override
                            public void runSupport() {
                                if (isActionEnabled(TagFeatureExecOnAssign.ACTION_STOP)) {
                                    dm.stopIt(DownloadManager.STATE_STOPPED, false, false);
                                } else {
                                    dm.pause();
                                }
                                // recheck here in case it is an 'archive' action that requires
                                // download to be stopped
                                checkMaximumTaggables();
                            }
                        });
                    }
                }
                if (isActionEnabled(TagFeatureExecOnAssign.ACTION_FORCE_START)) {
                    rs_async.dispatch(new AERunnable() {

                        @Override
                        public void runSupport() {
                            dm.setForceStart(true);
                        }
                    });
                } else if (isActionEnabled(TagFeatureExecOnAssign.ACTION_NOT_FORCE_START)) {
                    rs_async.dispatch(new AERunnable() {

                        @Override
                        public void runSupport() {
                            dm.setForceStart(false);
                        }
                    });
                }
                if (isActionEnabled(TagFeatureExecOnAssign.ACTION_SCRIPT)) {
                    final String script = getActionScript();
                    if (script.length() > 0) {
                        rs_async.dispatch(new AERunnable() {

                            @Override
                            public void runSupport() {
                                TagManagerImpl.getSingleton().evalScript(TagDownloadWithState.this, script, dm, "execAssign");
                            }
                        });
                    }
                }
            }
            if (isActionEnabled(TagFeatureExecOnAssign.ACTION_APPLY_OPTIONS_TEMPLATE)) {
                OptionsTemplateHandler handler = getOptionsTemplateHandler();
                if (handler.isActive()) {
                    rs_async.dispatch(new AERunnable() {

                        @Override
                        public void runSupport() {
                            handler.applyTo(dm);
                        }
                    });
                }
            }
        }
    } else {
        Debug.out("Invalid Taggable added: " + t);
    }
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

DownloadManager (com.biglybt.core.download.DownloadManager)307 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)54 TOTorrent (com.biglybt.core.torrent.TOTorrent)35 GlobalManager (com.biglybt.core.global.GlobalManager)33 PEPeerManager (com.biglybt.core.peer.PEPeerManager)29 File (java.io.File)29 List (java.util.List)21 Core (com.biglybt.core.Core)17 Download (com.biglybt.pif.download.Download)17 Point (org.eclipse.swt.graphics.Point)17 UIFunctions (com.biglybt.ui.UIFunctions)16 Tag (com.biglybt.core.tag.Tag)15 UIInputReceiverListener (com.biglybt.pif.ui.UIInputReceiverListener)14 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)13 ArrayList (java.util.ArrayList)13 DiskManager (com.biglybt.core.disk.DiskManager)12 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)12 CoreRunningListener (com.biglybt.core.CoreRunningListener)11 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)11 PEPeer (com.biglybt.core.peer.PEPeer)11