⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 startstoprulesdefaultplugin.java

📁 Azureus is a powerful, full-featured, cross-platform java BitTorrent client
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
      download_tracker_listener = new StartStopDMTrackerListener();
      download_listener = new StartStopDownloadListener();
    }

    public void downloadAdded( Download  download )
    {
      downloadData dlData = null;
      if (downloadDataMap.containsKey(download)) {
        dlData = (downloadData)downloadDataMap.get(download);
      } else {
        dlData = new downloadData(download);
        downloadDataMap.put( download, dlData );
        download.addListener( download_listener );
        download.addTrackerListener( download_tracker_listener );
      }

      if (dlData != null) {
        dlData.recalcSeedingRank();
        somethingChanged = true;
        if (bDebugLog) 
          log.log(LoggerChannel.LT_INFORMATION,
                  "somethingChanged: downloadAdded: " + download.getName());
      }
    }

    public void downloadRemoved( Download  download )
    {
      download.removeListener( download_listener );
      download.removeTrackerListener( download_tracker_listener );

      if (downloadDataMap.containsKey(download)) {
        downloadDataMap.remove(download);
      }

      somethingChanged = true;
      if (bDebugLog) 
        log.log(LoggerChannel.LT_INFORMATION,
                "somethingChanged: downloadRemoved: " + download.getName());
    }
  }
  
  private class ChangeCheckerTimerTask extends TimerTask {
    public void run() {
      // make sure process isn't running and stop it from running while we do stuff
      try{
      	this_mon.enter();
      	
        downloadData[] dlDataArray = 
          (downloadData[])downloadDataMap.values().toArray(new downloadData[0]);

        int iNumDLing = 0;
        int iNumCDing = 0;
        for (int i = 0; i < dlDataArray.length; i++) {
          Download dl = dlDataArray[i].getDownloadObject();
          DownloadStats stats = dl.getStats();
          
          // Check DLs for change in activeness (speed threshold)
          // (The call sets somethingChanged it was changed)
          if (dlDataArray[i].getActivelyDownloading())
            iNumDLing++;
          
          // Check Seeders for change in activeness (speed threshold)
          // (The call sets somethingChanged it was changed)
          if (dlDataArray[i].getActivelySeeding()) {
            iNumCDing++;

            int shareRatio = dl.getStats().getShareRatio();
            int numSeeds = calcSeedsNoUs(dl);

            if (iIgnoreShareRatio != 0 && 
                shareRatio > iIgnoreShareRatio && 
                numSeeds >= iIgnoreShareRatio_SeedStart &&
                shareRatio != -1)
              somethingChanged = true;
          }
          
          /* READY downloads are usually waiting for a seeding torrent to
             stop (the seeding torrent probably is within the "Minumum Seeding
             Time" setting)
           */
          if (dl.getState() == Download.ST_READY) {
            somethingChanged = true;
              if (bDebugLog) 
                log.log(LoggerChannel.LT_INFORMATION,
                        "somethingChanged: Download is ready");
          }

          /* Check if First Priority has been lost
             (In order for a gain in FP, the user has to manually increase
              one of the FP rules, which is trapped already by the ConfigListener)
          */
          int completionLevel = stats.getDownloadCompleted(false);
          if (completionLevel == 1000 && 
              dlDataArray[i].getSeedingRank() >= SR_FIRST_PRIORITY_STARTS_AT &&
              !dlDataArray[i].isFirstPriority()) {
            dlDataArray[i].recalcSeedingRank();
            somethingChanged = true;
            if (bDebugLog) 
              log.log(LoggerChannel.LT_INFORMATION,
                      "somethingChanged: FirstPriority lost for " + dl.getName());
          }
        }

        int iMaxSeeders = calcMaxSeeders(iNumDLing);
        if (iNumCDing > iMaxSeeders) {
          somethingChanged = true;
            if (bDebugLog) 
              log.log(LoggerChannel.LT_INFORMATION,
                      "somethingChanged: More Seeding than limit");
        }
      }finally{
      	
      	this_mon.exit();
      }
    }
  }

  // ConfigurationListener
  public void configurationSaved() {
    reloadConfigParams();
  }

  private void reloadConfigParams() {
  	try{
  		this_mon.enter();
  	
	    // int iOldIgnoreShareRatio = iIgnoreShareRatio;
	    int iNewRankType = plugin_config.getIntParameter("StartStopManager_iRankType");
	    minPeersToBoostNoSeeds = plugin_config.getIntParameter("StartStopManager_iMinPeersToBoostNoSeeds");
	    minSpeedForActiveDL = plugin_config.getIntParameter("StartStopManager_iMinSpeedForActiveDL");
	    minSpeedForActiveSeeding = plugin_config.getIntParameter("StartStopManager_iMinSpeedForActiveSeeding");
	    maxActive = plugin_config.getIntParameter("max active torrents");
	    maxDownloads = plugin_config.getIntParameter("max downloads");
	    numPeersAsFullCopy = plugin_config.getIntParameter("StartStopManager_iNumPeersAsFullCopy");
	    iFakeFullCopySeedStart = plugin_config.getIntParameter("StartStopManager_iFakeFullCopySeedStart");
	    iRankTypeSeedFallback = plugin_config.getIntParameter("StartStopManager_iRankTypeSeedFallback");
	    bAutoReposition = plugin_config.getBooleanParameter("StartStopManager_bAutoReposition");
	    minTimeAlive = plugin_config.getIntParameter("StartStopManager_iMinSeedingTime") * 1000;
	    bPreferLargerSwarms = plugin_config.getBooleanParameter("StartStopManager_bPreferLargerSwarms");
	    bDebugLog = plugin_config.getBooleanParameter("StartStopManager_bDebugLog");
	
	    // Ignore torrent if seed count is at least..
	    iIgnoreSeedCount = plugin_config.getIntParameter("StartStopManager_iIgnoreSeedCount");
	    bIgnore0Peers = plugin_config.getBooleanParameter("StartStopManager_bIgnore0Peers");
	    iIgnoreShareRatio = (int)(1000 * plugin_config.getFloatParameter("Stop Ratio"));
	    iIgnoreShareRatio_SeedStart = plugin_config.getIntParameter("StartStopManager_iIgnoreShareRatioSeedStart");
	    iIgnoreRatioPeers = plugin_config.getIntParameter("Stop Peers Ratio", 0);
	    iIgnoreRatioPeers_SeedStart = plugin_config.getIntParameter("StartStopManager_iIgnoreRatioPeersSeedStart", 0);
	
	    minQueueingShareRatio = plugin_config.getIntParameter("StartStopManager_iFirstPriority_ShareRatio");
	    iFirstPriorityType = plugin_config.getIntParameter("StartStopManager_iFirstPriority_Type");
	    iFirstPrioritySeedingMinutes = plugin_config.getIntParameter("StartStopManager_iFirstPriority_SeedingMinutes");
	    iFirstPriorityDLMinutes = plugin_config.getIntParameter("StartStopManager_iFirstPriority_DLMinutes");
	    
	    bAutoStart0Peers = plugin_config.getBooleanParameter("StartStopManager_bAutoStart0Peers");
	    iMaxUploadSpeed = plugin_config.getIntParameter("Max Upload Speed KBs",0);
	
	    if (iNewRankType != iRankType) {
	      iRankType = iNewRankType;
	      
	      // shorted 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) {
	          recalcSeedingRanksTask = new RecalcSeedingRanksTask();
	          changeCheckerTimer.schedule(recalcSeedingRanksTask, 1000, 1000);
	        }
	      } else if (recalcSeedingRanksTask != null) {
	        recalcSeedingRanksTask.cancel();
	        recalcSeedingRanksTask = null;
	      }
	    }
	    recalcAllSeedingRanks(true);
	    somethingChanged = true;
	    if (bDebugLog) {
	      log.log(LoggerChannel.LT_INFORMATION,
	              "somethingChanged: config reload");
	      try {
	        if (debugMenuItem == null && seedingRankColumn != null) {
	          debugMenuItem = ((TableColumnCore)seedingRankColumn).addContextMenuItem("StartStopRules.menu.viewDebug");
	          debugMenuItem.addListener(new MenuItemListener() {
	            public void selected(MenuItem _menu, Object _target) {
	    				  Download dl = (Download)((TableRow)_target).getDataSource();
	              downloadData dlData = (downloadData)downloadDataMap.get(dl);
	  
	              if (dlData != null) {
	                new TextViewerWindow(null, null, dlData.sExplainFP + "\n" + dlData.sTrace);
	              }
	            }
	          });
	        }
	      } catch (Throwable t) { Debug.printStackTrace( t ); }
	    } else if (debugMenuItem != null && seedingRankColumn != null) {
	      ((TableColumnCore)seedingRankColumn).removeContextMenuItem(debugMenuItem);
	      debugMenuItem = null;
	    }
  	}finally{
  		
  		this_mon.exit();
  	}
  }
  
  private int calcMaxSeeders(int iDLs) {
    // XXX put in subtraction logic here
    return (maxActive == 0) ? 99999 : maxActive - iDLs;
  }

  protected void process() {
  	try{
  		this_mon.enter();
  	
	    // long  process_time = SystemTime.getCurrentTime();
	
	    // total Forced Seeding doesn't include stalled torrents
	    int totalForcedSeeding = 0;
	    int totalWaitingToSeed = 0;
	    int totalWaitingToDL = 0;
	    int totalDownloading = 0;
	    int activeDLCount = 0;
	    int activeSeedingCount = 0;
	    int totalComplete = 0;
	    int totalIncompleteQueued = 0;
	    int totalFirstPriority = 0;
	    int totalStalledSeeders = 0;
	    int total0PeerSeeders = 0;
	
	    // pull the data into an local array, so we don't have to lock/synchronize
	    downloadData[] dlDataArray;
	    dlDataArray = (downloadData[])
	      downloadDataMap.values().toArray(new downloadData[downloadDataMap.size()]);
	
	    // Start seeding right away if there's no auto-ranking
	    // Otherwise, wait a maximium of 90 seconds for scrape results to come in
	    // When the first scrape result comes in, bSeedHasRanking will turn to true
	    // (see logic in 1st loop)
	    boolean bSeedHasRanking = (iRankType == RANK_NONE) || 
	                              (iRankType == RANK_TIMED) || 
	                              (SystemTime.getCurrentTime() - startedOn > 90000);
	
	    // Loop 1 of 2:
	    // - Build a SeedingRank list for sorting
	    // - Build Count Totals
	    // - Do anything that doesn't need to be done in Queued order
	    for (int i = 0; i < dlDataArray.length; i++) {
	      downloadData dlData = dlDataArray[i];
	      
	      Download download = dlData.getDownloadObject();
	      DownloadStats stats = download.getStats();
	      int completionLevel = stats.getDownloadCompleted(false);
	
	      // Count forced seedings as using a slot
	      // Don't count forced downloading as using a slot
	      if (completionLevel < 1000 && download.isForceStart())
	        continue;
	
	      int state = download.getState();
	
	      if (completionLevel == 1000) {
	        if (!bSeedHasRanking && 
	            (dlData.getSeedingRank() > 0) && 
	            (state == Download.ST_QUEUED ||
	             state == Download.ST_READY)) {
	          bSeedHasRanking = true;
	        }
	
	        if (state != Download.ST_ERROR && state != Download.ST_STOPPED) {
	          totalComplete++;
	          if (dlData.getActivelySeeding()) {
	            activeSeedingCount++;
	            if (download.isForceStart())
	              totalForcedSeeding++;
	          } else if (state == Download.ST_SEEDING) {
	            totalStalledSeeders++;
	            if (bAutoStart0Peers && calcPeersNoUs(download) == 0 && scrapeResultOk(download))
	              total0PeerSeeders++;
	          }
	          if (state == Download.ST_READY ||
	              state == Download.ST_WAITING ||
	              state == Download.ST_PREPARING) {
	            totalWaitingToSeed++;
	          }
	  
	          if (dlData.isFirstPriority()) {
	            totalFirstPriority++;
	            bSeedHasRanking = true;
	          }
	        }
	      } else {
	        if (state == Download.ST_DOWNLOADING)
	          totalDownloading++;
	        if (dlData.getActivelyDownloading())
	          activeDLCount++;
	
	        if (state == Download.ST_READY ||
	            state == Download.ST_WAITING ||
	            state == Download.ST_PREPARING) {
	          totalWaitingToDL++;
	        } else if (state == Download.ST_QUEUED) {
	          totalIncompleteQueued++;
	        }
	      }
	    }
	    
	    int maxSeeders = calcMaxSeeders(activeDLCount + totalWaitingToDL);
	    int iExtraFPs = (maxActive != 0) && (maxDownloads != 0) && 
	                    (maxDownloads + totalFirstPriority - maxActive) > 0 ? (maxDownloads + totalFirstPriority - maxActive) 
	                                                                        : 0;
	    int maxTorrents;
	    if (maxActive == 0) {
	      maxTorrents = 9999;
	    } else if (iMaxUploadSpeed == 0) {
	      maxTorrents = maxActive + 4;
	    } else {
	      // Don't allow more "seeding/downloading" torrents than there is enough
	      // bandwidth for.  There needs to be enough bandwidth for at least
	      // each torrent to get to its minSpeedForActiveSeeding  
	      // (we buffer it at 2x just to be safe).
	      int minSpeedPerActive = (minSpeedForActiveSeeding * 2) / 1024;
	      // Even more buffering/limiting.  Limit to enough bandwidth for
	      // each torrent to have potentially 3kbps.
	      if (minSpeedPerActive < 3)
	        minSpeedPerActive = 3;
	      maxTorrents = (iMaxUploadSpeed / minSpeedPerActive);
	      // Allow user to do stupid things like have more slots than their 
	      // upload speed can handle
	      if (maxTorrents < maxActive)
	        maxTorrents = maxActive;
	      //System.out.println("maxTorrents = " + maxTorrents + " = " + iMaxUploadSpeed + " / " + minSpeedPerActive);
	      //System.out.println("totalTorrents = " + (activeSeedingCount + totalStalledSeeders + totalDownloading));
	    }
	
	    String[] mainDebugEntries = null;
	    if (bDebugLog) {
	      log.log(LoggerChannel.LT_INFORMATION, ">>process()");
	      mainDebugEntries = new String[] { 
	              "bHasSR="+bSeedHasRanking,
	              "tFrcdCding="+totalForcedSeeding,
	              "actvCDs="+activeSeedingCount,
	              "tW8tingToCd="+totalWaitingToSeed,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -