Search in sources :

Example 1 with TagFeatureProperties

use of com.biglybt.core.tag.TagFeatureProperties in project BiglyBT by BiglySoftware.

the class StartStopRulesDefaultPlugin method reloadConfigParams.

private void reloadConfigParams() {
    try {
        this_mon.enter();
        int iNewRankType = plugin_config.getUnsafeIntParameter("StartStopManager_iRankType");
        minSpeedForActiveSeeding = plugin_config.getUnsafeIntParameter("StartStopManager_iMinSpeedForActiveSeeding");
        maxStalledSeeding = plugin_config.getUnsafeIntParameter("StartStopManager_iMaxStalledSeeding");
        if (maxStalledSeeding <= 0) {
            // insanity :)
            maxStalledSeeding = 999;
        }
        stalledSeedingIgnoreZP = plugin_config.getUnsafeBooleanParameter("StartStopManager_bMaxStalledSeedingIgnoreZP");
        _maxActive = plugin_config.getUnsafeIntParameter("max active torrents");
        _maxActiveWhenSeedingEnabled = plugin_config.getUnsafeBooleanParameter("StartStopManager_bMaxActiveTorrentsWhenSeedingEnabled");
        _maxActiveWhenSeeding = plugin_config.getUnsafeIntParameter("StartStopManager_iMaxActiveTorrentsWhenSeeding");
        maxConfiguredDownloads = plugin_config.getUnsafeIntParameter("max downloads");
        boolean min_eq_max = plugin_config.getUnsafeBooleanParameter("StartStopManager_bMaxMinDLLinked");
        if (min_eq_max) {
            minDownloads = maxConfiguredDownloads;
        } else {
            minDownloads = plugin_config.getUnsafeIntParameter("min downloads");
        }
        bMaxDownloadIgnoreChecking = plugin_config.getUnsafeBooleanParameter("StartStopManager_bMaxDownloadIgnoreChecking");
        numPeersAsFullCopy = plugin_config.getUnsafeIntParameter("StartStopManager_iNumPeersAsFullCopy");
        iFakeFullCopySeedStart = plugin_config.getUnsafeIntParameter("StartStopManager_iFakeFullCopySeedStart");
        bAutoReposition = plugin_config.getUnsafeBooleanParameter("StartStopManager_bAutoReposition");
        minTimeAlive = plugin_config.getUnsafeIntParameter("StartStopManager_iMinSeedingTime") * 1000;
        bDebugLog = plugin_config.getUnsafeBooleanParameter("StartStopManager_bDebugLog");
        bAutoStart0Peers = plugin_config.getUnsafeBooleanParameter("StartStopManager_bAutoStart0Peers");
        globalDownloadLimit = plugin_config.getUnsafeIntParameter("Max Download Speed KBs", 0);
        globalUploadLimit = plugin_config.getUnsafeIntParameter("Max Upload Speed KBs", 0);
        globalUploadWhenSeedingLimit = plugin_config.getUnsafeBooleanParameter("enable.seedingonly.upload.rate") ? plugin_config.getUnsafeIntParameter("Max Upload Speed Seeding KBs", 0) : globalUploadLimit;
        bStopOnceBandwidthMet = plugin_config.getUnsafeBooleanParameter("StartStopManager_bStopOnceBandwidthMet");
        bStartNoMoreSeedsWhenUpLimitMet = plugin_config.getUnsafeBooleanParameter("StartStopManager_bStartNoMoreSeedsWhenUpLimitMet");
        bStartNoMoreSeedsWhenUpLimitMetPercent = plugin_config.getUnsafeBooleanParameter("StartStopManager_bStartNoMoreSeedsWhenUpLimitMetPercent");
        bStartNoMoreSeedsWhenUpLimitMetSlack = plugin_config.getUnsafeIntParameter("StartStopManager_bStartNoMoreSeedsWhenUpLimitMetSlack");
        boolean move_top = plugin_config.getUnsafeBooleanParameter("StartStopManager_bNewSeedsMoveTop");
        plugin_config.setCoreBooleanParameter(PluginConfig.CORE_PARAM_BOOLEAN_NEW_SEEDS_START_AT_TOP, move_top);
        if (iNewRankType != iRankType) {
            iRankType = iNewRankType;
            // shorten recalc for timed rank type, since the calculation is fast and we want to stop on the second
            if (iRankType == RANK_TIMED) {
                if (recalcSeedingRanksTask == null) {
                    recalcAllSeedingRanks(false);
                    recalcSeedingRanksTask = new RecalcSeedingRanksTask();
                    SimpleTimer.addPeriodicEvent("StartStop:recalcSR", 1000, recalcSeedingRanksTask);
                }
            } else if (recalcSeedingRanksTask != null) {
                recalcSeedingRanksTask.cancel();
                recalcSeedingRanksTask = null;
            }
        }
        iDownloadSortType = plugin_config.getUnsafeIntParameter("StartStopManager_Downloading_iSortType", -1);
        // migrate from old boolean setting
        if (iDownloadSortType == -1) {
            boolean bDownloadAutoReposition = plugin_config.getUnsafeBooleanParameter("StartStopManager_Downloading_bAutoReposition");
            iDownloadSortType = bDownloadAutoReposition ? DefaultRankCalculator.DOWNLOAD_ORDER_SPEED : DefaultRankCalculator.DOWNLOAD_ORDER_INDEX;
            plugin_config.setCoreIntParameter("StartStopManager_Downloading_iSortType", iDownloadSortType);
        }
        iDownloadTestTimeMillis = plugin_config.getUnsafeIntParameter("StartStopManager_Downloading_iTestTimeSecs") * 1000;
        iDownloadReTestMillis = plugin_config.getUnsafeIntParameter("StartStopManager_Downloading_iRetestTimeMins") * 60 * 1000;
        bTagFirstPriority = plugin_config.getUnsafeBooleanParameter("StartStopManager_bTagFirstPriority");
        if (bTagFirstPriority) {
            TagManager tag_manager = TagManagerFactory.getTagManager();
            if (tag_manager != null && tag_manager.isEnabled()) {
                TagType tt = tag_manager.getTagType(TagType.TT_DOWNLOAD_MANUAL);
                if (fp_tag == null) {
                    fp_tag = tt.getTag("First Priority", true);
                    if (fp_tag == null) {
                        try {
                            fp_tag = tt.createTag("First Priority", true);
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                }
                Tag not_fp_tag = tt.getTag("Not First Priority", true);
                if (not_fp_tag == null) {
                    try {
                        not_fp_tag = tt.createTag("Not First Priority", true);
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
                if (not_fp_tag != null) {
                    TagProperty constraint = ((TagFeatureProperties) not_fp_tag).getProperty(TagFeatureProperties.PR_CONSTRAINT);
                    constraint.setStringList(new String[] { "isComplete() && !hasTag( \"First Priority\" )" });
                }
            }
        }
        /*
			 // limit _maxActive and maxDownloads based on TheColonel's specs

			 // maxActive = max_upload_speed / (slots_per_torrent * min_speed_per_peer)
			 if (_maxActive > 0) {
			 int iSlotsPerTorrent = plugin_config.getUnsafeIntParameter("Max Uploads");
			 // TODO: Track upload speed, storing the max upload speed over a minute
			 //        and use that for "unlimited" setting, or huge settings (like 200)
			 if (iSlotsPerTorrent > 0) {
			 int iMinSpeedPerPeer = 3; // for now.  TODO: config value
			 int _maxActiveLimit = iMaxUploadSpeed / (iSlotsPerTorrent * iMinSpeedPerPeer);
			 if (_maxActive > _maxActiveLimit) {
			 _maxActive = _maxActiveLimit;
			 plugin_config.setCoreIntParameter(PluginConfig.CORE_PARAM_INT_MAX_ACTIVE, _maxActive);
			 }
			 }

			 if (maxDownloads > _maxActive) {
			 maxDownloads = _maxActive;
			 plugin_config.setCoreIntParameter(PluginConfig.CORE_PARAM_INT_MAX_DOWNLOADS, maxDownloads);
			 }
			 }
			 */
        // force a recalc on all downloads by setting SR to 0, scheduling
        // a recalc on next process, and requsting a process cycle
        Collection<DefaultRankCalculator> allDownloads = downloadDataMap.values();
        DefaultRankCalculator[] dlDataArray = allDownloads.toArray(new DefaultRankCalculator[0]);
        for (int i = 0; i < dlDataArray.length; i++) {
            dlDataArray[i].getDownloadObject().setSeedingRank(0);
        }
        try {
            ranksToRecalc_mon.enter();
            synchronized (downloadDataMap) {
                ranksToRecalc.addAll(allDownloads);
            }
        } finally {
            ranksToRecalc_mon.exit();
        }
        requestProcessCycle(null);
        if (bDebugLog) {
            log.log(LoggerChannel.LT_INFORMATION, "somethingChanged: config reload");
            try {
                if (debugMenuItem == null) {
                    final String DEBUG_MENU_ID = "StartStopRules.menu.viewDebug";
                    MenuItemListener menuListener = new MenuItemListener() {

                        @Override
                        public void selected(MenuItem menu, Object target) {
                            if (!(target instanceof TableRow))
                                return;
                            TableRow tr = (TableRow) target;
                            Object ds = tr.getDataSource();
                            if (!(ds instanceof Download))
                                return;
                            DefaultRankCalculator dlData = downloadDataMap.get(ds);
                            if (dlData != null) {
                                if (swt_ui != null)
                                    swt_ui.openDebugWindow(dlData);
                                else
                                    pi.getUIManager().showTextMessage(null, null, "FP:\n" + dlData.sExplainFP + "\n" + "SR:" + dlData.sExplainSR + "\n" + "TRACE:\n" + dlData.sTrace);
                            }
                        }
                    };
                    TableManager tm = pi.getUIManager().getTableManager();
                    debugMenuItem = tm.addContextMenuItem(TableManager.TABLE_MYTORRENTS_COMPLETE, DEBUG_MENU_ID);
                    debugMenuItem.setHeaderCategory(MenuItem.HEADER_CONTROL);
                    debugMenuItem.addListener(menuListener);
                    debugMenuItem = tm.addContextMenuItem(TableManager.TABLE_MYTORRENTS_INCOMPLETE, DEBUG_MENU_ID);
                    debugMenuItem.setHeaderCategory(MenuItem.HEADER_CONTROL);
                    debugMenuItem.addListener(menuListener);
                }
            } catch (Throwable t) {
                Debug.printStackTrace(t);
            }
        }
    } finally {
        this_mon.exit();
    }
}
Also used : TagProperty(com.biglybt.core.tag.TagFeatureProperties.TagProperty) MenuItem(com.biglybt.pif.ui.menus.MenuItem) TagType(com.biglybt.core.tag.TagType) TagManager(com.biglybt.core.tag.TagManager) MenuItemListener(com.biglybt.pif.ui.menus.MenuItemListener) Tag(com.biglybt.core.tag.Tag) TagFeatureProperties(com.biglybt.core.tag.TagFeatureProperties)

Example 2 with TagFeatureProperties

use of com.biglybt.core.tag.TagFeatureProperties in project BiglyBT by BiglySoftware.

the class ColumnTagProperties method refresh.

@Override
public void refresh(TableCell cell) {
    Tag tag = (Tag) cell.getDataSource();
    String text = "";
    if (tag instanceof TagFeatureProperties) {
        TagFeatureProperties tp = (TagFeatureProperties) tag;
        TagFeatureProperties.TagProperty[] props = tp.getSupportedProperties();
        if (props.length > 0) {
            for (TagFeatureProperties.TagProperty prop : props) {
                String prop_str = prop.getString();
                if (prop_str.length() > 0) {
                    text += (text.length() == 0 ? "" : "; ") + prop_str;
                }
            }
        }
    }
    if (tag instanceof TagFeatureExecOnAssign) {
        TagFeatureExecOnAssign eoa = (TagFeatureExecOnAssign) tag;
        int actions = eoa.getSupportedActions();
        if (actions != TagFeatureExecOnAssign.ACTION_NONE) {
            String actions_str = "";
            int[] action_ids = { TagFeatureExecOnAssign.ACTION_APPLY_OPTIONS_TEMPLATE, TagFeatureExecOnAssign.ACTION_DESTROY, TagFeatureExecOnAssign.ACTION_START, TagFeatureExecOnAssign.ACTION_FORCE_START, TagFeatureExecOnAssign.ACTION_NOT_FORCE_START, TagFeatureExecOnAssign.ACTION_STOP, TagFeatureExecOnAssign.ACTION_SCRIPT, TagFeatureExecOnAssign.ACTION_PAUSE, TagFeatureExecOnAssign.ACTION_RESUME };
            String[] action_keys = { "label.apply.options.template", "v3.MainWindow.button.delete", "v3.MainWindow.button.start", "v3.MainWindow.button.forcestart", "v3.MainWindow.button.notforcestart", "v3.MainWindow.button.stop", "label.script", "v3.MainWindow.button.pause", "v3.MainWindow.button.resume" };
            for (int i = 0; i < action_ids.length; i++) {
                int action_id = action_ids[i];
                if (eoa.supportsAction(action_id)) {
                    boolean enabled = eoa.isActionEnabled(action_id);
                    if (enabled) {
                        if (action_id == TagFeatureExecOnAssign.ACTION_SCRIPT) {
                            String script = eoa.getActionScript();
                            if (script.length() > 63) {
                                script = script.substring(0, 60) + "...";
                            }
                            actions_str += (actions_str.length() == 0 ? "" : ",") + MessageText.getString(action_keys[i]) + "=" + script;
                        } else {
                            actions_str += (actions_str.length() == 0 ? "" : ",") + MessageText.getString(action_keys[i]) + "=Y";
                        }
                    }
                }
            }
            if (actions_str.length() > 0) {
                text += (text.length() == 0 ? "" : "; ") + MessageText.getString("label.exec.on.assign") + ": ";
                text += actions_str;
            }
        }
    }
    if (!cell.setSortValue(text) && cell.isValid()) {
        return;
    }
    if (!cell.isShown()) {
        return;
    }
    cell.setText(text);
}
Also used : Tag(com.biglybt.core.tag.Tag) TagFeatureProperties(com.biglybt.core.tag.TagFeatureProperties) TagFeatureExecOnAssign(com.biglybt.core.tag.TagFeatureExecOnAssign)

Aggregations

Tag (com.biglybt.core.tag.Tag)2 TagFeatureProperties (com.biglybt.core.tag.TagFeatureProperties)2 TagFeatureExecOnAssign (com.biglybt.core.tag.TagFeatureExecOnAssign)1 TagProperty (com.biglybt.core.tag.TagFeatureProperties.TagProperty)1 TagManager (com.biglybt.core.tag.TagManager)1 TagType (com.biglybt.core.tag.TagType)1 MenuItem (com.biglybt.pif.ui.menus.MenuItem)1 MenuItemListener (com.biglybt.pif.ui.menus.MenuItemListener)1