Examples of DownloadStats


Examples of org.gudy.azureus2.plugins.download.DownloadStats

  public Download getDownloadObject() {
    return dl;
  }
 
  public boolean isForceActive() {
    DownloadStats stats = dl.getStats();
    return SystemTime.getCurrentTime() - stats.getTimeStarted() <= FORCE_ACTIVE_FOR;
  }
View Full Code Here

Examples of org.gudy.azureus2.plugins.download.DownloadStats

   *
   * @return true: actively downloading
   */
  public boolean getActivelyDownloading() {
    boolean bIsActive = false;
    DownloadStats stats = dl.getStats();
    int state = dl.getState();

    // In order to be active,
    // - Must be downloading (and thus incomplete)
    // - Must be above speed threshold, or started less than 30s ago
    if (state != Download.ST_DOWNLOADING) {
      bIsActive = false;
    } else if (SystemTime.getCurrentTime() - stats.getTimeStarted() <= FORCE_ACTIVE_FOR) {
      bIsActive = true;
    } else {
      // activity based on DL Average
      bIsActive = (stats.getDownloadAverage() >= minSpeedForActiveDL);

      if (bActivelyDownloading != bIsActive) {
        long now = SystemTime.getCurrentTime();
        // Change
        if (lDLActivelyChangedOn == -1) {
View Full Code Here

Examples of org.gudy.azureus2.plugins.download.DownloadStats

   *
   * @return true: actively seeding
   */
  public boolean getActivelySeeding() {
    boolean bIsActive = false;
    DownloadStats stats = dl.getStats();
    int state = dl.getState();
    // Timed torrents don't use a speed threshold, since they are based on time!
    // However, First Priorities need to be checked for activity so that
    // timed ones can start when FPs are below threshold.  Ditto for 0 Peers
    // when bAutoStart0Peers
    if (iRankType == StartStopRulesDefaultPlugin.RANK_TIMED
        && !isFirstPriority()
        && !(bAutoStart0Peers && rules.calcPeersNoUs(dl) == 0 && lastScrapeResultOk)) {
      bIsActive = (state == Download.ST_SEEDING);

    } else if (state != Download.ST_SEEDING
        || (bAutoStart0Peers && rules.calcPeersNoUs(dl) == 0)) {
      // Not active if we aren't seeding
      // Not active if we are AutoStarting 0 Peers, and peer count == 0
      bIsActive = false;
      staleCDSince = -1;
    } else if (SystemTime.getCurrentTime() - stats.getTimeStarted() <= FORCE_ACTIVE_FOR) {
      bIsActive = true;
      staleCDSince = -1;
    } else {
      bIsActive = (stats.getUploadAverage() >= minSpeedForActiveSeeding);

      if (bActivelySeeding != bIsActive) {
        long now = SystemTime.getCurrentTime();
        // Change
        if (lCDActivelyChangedOn < 0) {
View Full Code Here

Examples of org.gudy.azureus2.plugins.download.DownloadStats

      downloadData_this_mon.enter();

      sExplainSR = "";

      int oldSR = dl.getSeedingRank();
      DownloadStats stats = dl.getStats();

      int newSR = 0;

      // make undownloaded sort to top so they can start first.
      if (!dl.isComplete()) {
        newSR = SR_COMPLETE_STARTS_AT + (10000 - dl.getPosition());
        dl.setSeedingRank(newSR);
        // make sure we capture FP being turned off when torrent does from
        // complete to incomplete
        isFirstPriority();
        if ( rules.bDebugLog ){
          sExplainSR += "  not complete. SetSR " + newSR + "\n";
        }
        return newSR;
      }

      // here we are seeding

      lastModifiedShareRatio = stats.getShareRatio();
      lastModifiedScrapeResultPeers = rules.calcPeersNoUs(dl);
      lastModifiedScrapeResultSeeds = rules.calcSeedsNoUs(dl);

      boolean bScrapeResultsOk = (lastModifiedScrapeResultPeers > 0 || lastModifiedScrapeResultSeeds > 0
          || lastScrapeResultOk) && (lastModifiedScrapeResultPeers >= 0 && lastModifiedScrapeResultSeeds >= 0);

      if (!isFirstPriority()) {
        // Check Ignore Rules
        // never apply ignore rules to First Priority Matches
        // (we don't want leechers circumventing the 0.5 rule)

        //0 means unlimited
        if (iIgnoreShareRatio != 0 && lastModifiedShareRatio >= iIgnoreShareRatio
            && (lastModifiedScrapeResultSeeds >= iIgnoreShareRatio_SeedStart || !bScrapeResultsOk)
            && lastModifiedShareRatio != -1) {
         
          if (rules.bDebugLog)
            sExplainSR += "  shareratio met: shareRatio(" + lastModifiedShareRatio
                + ") >= " + iIgnoreShareRatio + "\n";

          dl.setSeedingRank(SR_SHARERATIOMET);
          return SR_SHARERATIOMET;
        } else if (rules.bDebugLog && iIgnoreShareRatio != 0
            && lastModifiedShareRatio >= iIgnoreShareRatio) {
          sExplainSR += "  shareratio NOT met: ";
          if (lastModifiedScrapeResultSeeds >= iIgnoreShareRatio_SeedStart)
            sExplainSR += lastModifiedScrapeResultSeeds + " below seed threshold of "
                + iIgnoreShareRatio_SeedStart;
          sExplainSR += "\n";
        }

        if (lastModifiedScrapeResultPeers == 0 && bScrapeResultsOk) {
          // If both bIgnore0Peers and bFirstPriorityIgnore0Peer are on,
          // we won't know which one it is at this point.
          // We have to use the normal SR_0PEERS in case it isn't FP
          if (bIgnore0Peers) {
            if (rules.bDebugLog)
              sExplainSR += "  Ignore 0 Peers criteria met\n";

            dl.setSeedingRank(SR_0PEERS);
            return SR_0PEERS;
          }

//          if (bFirstPriorityIgnore0Peer) {
//            if (rules.bDebugLog)
//              sExplainSR += "  Ignore 0 Peers criteria for FP met\n";
//
//            dl.setSeedingRank(SR_FP0PEERS);
//            return SR_FP0PEERS;
//          }
        } else if (rules.bDebugLog && lastModifiedScrapeResultPeers == 0) {
          sExplainSR += "  0 Peer Ignore rule NOT applied: Scrape invalid\n";
        }

//        if (numPeers != 0 && iFirstPriorityIgnoreSPRatio != 0
//            && numSeeds / numPeers >= iFirstPriorityIgnoreSPRatio) {
//          if (rules.bDebugLog)
//            sExplainSR += "  Ignore rule for S:P Ratio for FP met.  Current: ("
//                + (numSeeds / numPeers)
//                + ") >= Threshold("
//                + iFirstPriorityIgnoreSPRatio + ")\n";
//
//          dl.setSeedingRank(SR_FP_SPRATIOMET);
//          return SR_FP_SPRATIOMET;
//        }

        //0 means disabled
        if ((iIgnoreSeedCount != 0) && (lastModifiedScrapeResultSeeds >= iIgnoreSeedCount)) {
          if (rules.bDebugLog)
            sExplainSR += "  SeedCount Ignore rule met.  numSeeds("
                + lastModifiedScrapeResultSeeds + " >= iIgnoreSeedCount(" + iIgnoreSeedCount + ")\n";

          dl.setSeedingRank(SR_NUMSEEDSMET);
          return SR_NUMSEEDSMET;
        }

        // Ignore when P:S ratio met
        // (More Peers for each Seed than specified in Config)
        //0 means never stop
        if (iIgnoreRatioPeers != 0 && lastModifiedScrapeResultSeeds != 0) {
          float ratio = (float) lastModifiedScrapeResultPeers / lastModifiedScrapeResultSeeds;
          if (ratio <= iIgnoreRatioPeers
              && lastModifiedScrapeResultSeeds >= iIgnoreRatioPeers_SeedStart) {

            if (rules.bDebugLog)
              sExplainSR += "  P:S Ignore rule met.  ratio(" + ratio
                  + " <= threshold(" + iIgnoreRatioPeers_SeedStart + ")\n";

            dl.setSeedingRank(SR_RATIOMET);
            return SR_RATIOMET;
          }
        }
      }

      // Never do anything with rank type of none
      if (iRankType == StartStopRulesDefaultPlugin.RANK_NONE) {
        if (rules.bDebugLog)
          sExplainSR += "  Ranking Type set to none.. blanking seeding rank\n";
       
        // everythink ok!
        dl.setSeedingRank(newSR);
        return newSR;
      }

      if (iRankType == StartStopRulesDefaultPlugin.RANK_TIMED) {
        if (bIsFirstPriority) {
          newSR += SR_TIMED_QUEUED_ENDS_AT + 1;
          dl.setSeedingRank(newSR);
          return newSR;
        }

        int state = dl.getState();
        if (state == Download.ST_STOPPING || state == Download.ST_STOPPED
            || state == Download.ST_ERROR) {
          if (rules.bDebugLog)
            sExplainSR += "  Download stopping, stopped or in error\n";
          dl.setSeedingRank(SR_NOTQUEUED);
          return SR_NOTQUEUED;
        } else if (state == Download.ST_SEEDING || state == Download.ST_READY
            || state == Download.ST_WAITING || state == Download.ST_PREPARING) {
          // force sort to top
          long lMsElapsed = 0;
          if (state == Download.ST_SEEDING && !dl.isForceStart())
            lMsElapsed = (SystemTime.getCurrentTime() - stats
                .getTimeStartedSeeding());

          if (lMsElapsed >= minTimeAlive) {
            dl.setSeedingRank(1);
            if (oldSR > SR_TIMED_QUEUED_ENDS_AT) {
View Full Code Here

Examples of org.gudy.azureus2.plugins.download.DownloadStats

                          last_preview_mode = preview_mode;
                         
                          b_map.put( "msg", MessageText.getString( last_preview_mode?"stream.analysing.media.preview":"stream.analysing.media" ));

                        }
                        DownloadStats stats = download.getStats();
                       
                        b_map.put( "dl_rate", stats.getDownloadAverage());
                        b_map.put( "dl_size", stats.getDownloaded());
                        b_map.put( "dl_time", SystemTime.getMonotonousTime() - stream_start );
                       
                        try{
                          buffering_method.invoke(player, new Object[] { b_map });

                        }catch( Throwable e ){
                         
                        }
                      }
                    }
                  }
                }.start();
               
              sem.reserve();
             
              synchronized( StreamManager.this ){
               
                if ( cancelled ){
                   
                  throw( new Exception( "Cancelled" ));
                }
               
                active_job   = null;
                active_sem  = null;
              }
             
              if ( error[0] != null ){
               
                throw( error[0] );
              }
             
              duration     = properties[0];
              video_width    = properties[1];
              video_height  = properties[2];
             
              if ( duration > 0 ){
               
                if ( map == null ){
                 
                  map = new HashMap<String, Map<String,Object>>();
                 
                }else{
                 
                  map = new HashMap<String, Map<String,Object>>( map );
                }
               
                Map<String,Object> file_map = map.get( String.valueOf( file_index ));
               
                if ( file_map == null ){
               
                  file_map = new HashMap<String, Object>();
                 
                  map.put( String.valueOf( file_index ), file_map );
                }
               
                file_map.put( "duration", duration );
                file_map.put( "video_width", video_width );
                file_map.put( "video_height", video_height );
               
                download.setMapAttribute( mi_ta, map );
              }
             
            }catch( Throwable e ){
             
              tj.removeForce();
             
              throw( e );
            }
           
          }catch( Throwable e ){
           
            throw( new Exception( "Media analysis failed", e ));
           
          }finally{
           
          }
        }else{
           
          duration     = l_duration;
          video_width    = l_video_width==null?0:l_video_width;
          video_height  = l_video_height==null?0:l_video_height;
        }
         
        if ( video_width == 0 || video_height == 0){
         
          throw( new Exception( "Media analysis failed - video stream not found" ));
        }
       
        if ( duration == 0 ){
         
          throw( new Exception( "Media analysis failed - duration unknown" ));
        }
       
        listener.updateActivity( "MetaData read: duration=" + TimeFormatter.formatColon( duration/1000) + ", width=" + video_width + ", height=" + video_height );
       
        Method smd_method = player.getClass().getMethod( "setMetaData", new Class[] { Map.class });
       
        Map<String,Object>  md_map = new HashMap<String,Object>();
       
        md_map.put( "duration", duration );
        md_map.put( "width", video_width );
        md_map.put( "height", video_height );
       
        smd_method.invoke( player, new Object[] { md_map });

        final long  bytes_per_sec = file.getLength() / (duration/1000);
     
        long  dl_lim_max     = COConfigurationManager.getIntParameter( "Plugin.azemp.azemp.config.dl_lim_max" ) * 1024L;
        long  dl_lim_extra   = COConfigurationManager.getIntParameter( "Plugin.azemp.azemp.config.dl_lim_extra" ) * 1024L;

        existing_dl_limit = download.getDownloadRateLimitBytesPerSecond();
       
        long  required_limit = Math.max( dl_lim_max, bytes_per_sec + dl_lim_extra );

        if ( required_limit > 0 ){
       
          download.setDownloadRateLimitBytesPerSecond((int)required_limit );
        }
       
        listener.updateActivity( "Average rate=" + DisplayFormatters.formatByteCountToKiBEtcPerSec( bytes_per_sec ) + ", applied dl limit=" + DisplayFormatters.formatByteCountToKiBEtcPerSec( required_limit ));

        synchronized( StreamManager.this ){
         
          if ( cancelled ){
           
            throw( new Exception( "Cancelled" ));
          }
                                                   
          active_edm.setExplicitProgressive( BUFFER_SECS, bytes_per_sec, file_index );
         
          if ( !active_edm.setProgressiveMode( true )){
           
            throw( new Exception( "Failed to set download as progressive" ));
          }
         
          active_edm_activated = true;
        }
       
        new AEThread2( "streamMon" )
        {
         
          public void
          run()
          { 
            final int TIMER_PERIOD     = 250;
            final int PLAY_STATS_PERIOD  = 5000;
            final int PLAY_STATS_TICKS  = PLAY_STATS_PERIOD / TIMER_PERIOD;
           
            final int DL_STARTUP_PERIOD  = 5000;
            final int DL_STARTUP_TICKS  = DL_STARTUP_PERIOD / TIMER_PERIOD;
     
            boolean playback_started   = false;
            boolean  playback_paused    = false;

            boolean  error_reported = false;
           
            try{
              Method start_method     = player.getClass().getMethod( "startPlayback", new Class[] { URL.class });
              Method pause_method     = player.getClass().getMethod( "pausePlayback", new Class[] {});
              Method resume_method     = player.getClass().getMethod( "resumePlayback", new Class[] {});
              Method buffering_method    = player.getClass().getMethod( "bufferingPlayback", new Class[] { Map.class });
              Method play_stats_method  = player.getClass().getMethod( "playStats", new Class[] { Map.class });

              int tick_count = 0;
             
              while( !cancelled ){
                 
                tick_count++;
               
                int dm_state = dm.getState();
               
                boolean complete = file.getLength() == file.getDownloaded();

                if ( !complete ){
                 
                  if (   dm_state == DownloadManager.STATE_ERROR ||
                      dm_state == DownloadManager.STATE_STOPPED ||
                      dm_state == DownloadManager.STATE_QUEUED ){
                   
                    if ( tick_count >= DL_STARTUP_TICKS ){
                   
                      throw( new Exception( "Streaming abandoned, download isn't running" ));
                    }
                  }
 
                  if ( !active_edm.getProgressiveMode()){
                 
                    complete = file.getLength() == file.getDownloaded();
                   
                    if ( !complete ){
                   
                      throw( new Exception( "Streaming mode abandoned for download" ));
                    }
                  }
                }
             
                long[] details = updateETA( active_edm );
               
                int    eta     = (int)details[0];
                int    buffer_secs  = (int)details[1];
                long  buffer    = details[2];
               
                listener.updateStats( eta, buffer_secs, buffer, BUFFER_SECS );

                boolean playable;
               
                int  buffer_to_use = playback_started?BUFFER_MIN_SECS:BUFFER_SECS;
               
                if ( complete ){
                 
                  playable = true;
                 
                }else{
                 
                  playable = buffer_secs > buffer_to_use;
               
                  playable = playable && ( eta <= || (playback_started && !playback_paused ) || preview_mode );
                }
               
                if ( playback_started ){
                 
                  if ( playable ){
                   
                    if ( playback_paused ){
                     
                      listener.updateActivity( "Resuming playback" );
                     
                      resume_method.invoke(player, new Object[] {});

                      playback_paused = false;
                    }
                  }else{
                     
                    if ( !playback_paused ){
                     
                      listener.updateActivity( "Pausing playback to prevent stall" );
                                             
                      pause_method.invoke(player, new Object[] {});
 
                      playback_paused = true;
                    }
                  }
                }else{
                 
                  if ( playable ){
                   
                    listener.ready();
                     
                    start_method.invoke(player, new Object[] { url });
                   
                    playback_started = true;
                  }
                }
             
                if ( playable ){
                 
                  if ( tick_count % PLAY_STATS_TICKS == 0 ){
                     
                    long contiguous_done = active_edm.getContiguousAvailableBytes( active_edm.getPrimaryFile().getIndex(), 0, 0 );
                 
                    Map<String,Object> map = new HashMap<String,Object>();
                   
                    map.put( "buffer_min", new Long( BUFFER_SECS ));
                    map.put( "buffer_secs", new Integer( buffer_secs ));
                    map.put( "buffer_bytes", new Long( buffer ));
                   
                    map.put( "stream_rate", bytes_per_sec );
                   
                    DownloadStats stats = download.getStats();
                   
                    map.put( "dl_rate", stats.getDownloadAverage());
                    map.put( "dl_size", stats.getDownloaded());
                    map.put( "dl_time", SystemTime.getMonotonousTime() - stream_start );
 
                    map.put( "duration", duration );
                    map.put( "file_size", file.getLength());
                    map.put( "cont_done", contiguous_done );
                   
                    play_stats_method.invoke(player, new Object[] { map });
                  }
                }else{
                 
                  DownloadStats stats = download.getStats();

                  Map<String,Object> map = new HashMap<String,Object>();
                 
                  map.put( "state", new Integer( 2 ));

                  if ( preview_mode && !complete ){
                   
                    long rate = stats.getDownloadAverage();
                   
                    int  preview_eta;
                   
                    if ( rate <= 0 ){
                     
                      preview_eta = Integer.MAX_VALUE;
                     
                    }else{
                     
                      double secs_per_sec = ((double)bytes_per_sec)/rate;
                   
                      preview_eta = (int)(( buffer_to_use - buffer_secs ) * secs_per_sec);
                    }
                   
                    map.put( "eta", new Integer( preview_eta ));
                   
                    map.put( "preview", 1 );
                   
                  }else{
                   
                    map.put( "eta", new Integer( eta ));
                   
                    map.put( "preview", 0 );
                  }
                 
                  map.put( "buffer_min", new Long( BUFFER_SECS ));
                  map.put( "buffer_secs", new Integer( buffer_secs ));
                  map.put( "buffer_bytes", new Long( buffer ));
                 
                  map.put( "stream_rate", bytes_per_sec );
                 
                  map.put( "dl_rate", stats.getDownloadAverage());
                  map.put( "dl_size", stats.getDownloaded());
                  map.put( "dl_time", SystemTime.getMonotonousTime() - stream_start );
                 
                  buffering_method.invoke(player, new Object[] { map });
                }
               
View Full Code Here

Examples of org.gudy.azureus2.plugins.download.DownloadStats

       
        DownloadManager  core_download = PluginCoreUtils.unwrap( download );
       
        PEPeerManager pm = core_download.getPeerManager();
       
        DownloadStats  stats = download.getStats();
       
        JSONObject torrent = new JSONObject();
       
        torrents.add( torrent );
       
        int  peers_from_us   = 0;
        int  peers_to_us    = 0;
       
        if ( pm != null ){
         
          List<PEPeer> peers = pm.getPeers();
         
          for ( PEPeer peer: peers ){
           
            PEPeerStats pstats = peer.getStats();
           
            if ( pstats.getDataReceiveRate() > 0 ){
             
              peers_to_us++;
            }
           
            if ( pstats.getDataSendRate() > 0 ){
             
              peers_from_us++;
            }
          }
        }
       
        for ( String field: fields ){
         
          Object  value = null;
         
          if ( field.equals( "addedDate" )){
            value = new Long(core_download.getDownloadState().getLongParameter(DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME)/1000);
          }else if ( field.equals( "announceURL" )){ 
            value = t.getAnnounceURL().toExternalForm();
          }else if ( field.equals( "comment" )){ 
            value = t.getComment();
          }else if ( field.equals( "creator" )){ 
            value = t.getCreatedBy();
          }else if ( field.equals( "dateCreated" )){ 
            value = new Long( t.getCreationDate());
          }else if ( field.equals( "downloadedEver" )){
            value = new Long( stats.getDownloaded() + stats.getDiscarded() + stats.getHashFails());
          }else if ( field.equals( "error" )){
            String str = download.getErrorStateDetails();
           
              // o = none, 1=tracker warn,2=tracker error,2=other
            if ( str != null && str.length() > 0 ){
              value = new Long(3);
            }else{
              value = ZERO;
              TRTrackerAnnouncer tracker_client = core_download.getTrackerClient();
             
              if ( tracker_client != null ){
                TRTrackerAnnouncerResponse x = tracker_client.getBestAnnouncer().getLastResponse();
                if ( x != null ){
                  if ( x.getStatus() == TRTrackerAnnouncerResponse.ST_REPORTED_ERROR ){
                    value = new Long(2);
                  }
                }
              }else{
                DownloadScrapeResult x = download.getLastScrapeResult();
                if ( x != null ){
                  if ( x.getResponseType() == DownloadScrapeResult.RT_ERROR ){
                    String status = x.getStatus();
                   
                    if ( status != null && status.length() > 0 ){
                   
                      value = new Long(2);
                    }
                  }
                }
              }
            }
          }else if ( field.equals( "errorString" )){ 
            String str = download.getErrorStateDetails();
           
            if ( str != null && str.length() > 0 ){
              value = str;
            }else{
              value = "";
              TRTrackerAnnouncer tracker_client = core_download.getTrackerClient();
             
              if ( tracker_client != null ){
                TRTrackerAnnouncerResponse x = tracker_client.getBestAnnouncer().getLastResponse();
                if ( x != null ){
                  if ( x.getStatus() == TRTrackerAnnouncerResponse.ST_REPORTED_ERROR ){
                    value = x.getStatusString();
                  }
                }
              }else{
                DownloadScrapeResult x = download.getLastScrapeResult();
                if ( x != null ){
                  if ( x.getResponseType() == DownloadScrapeResult.RT_ERROR ){
                    value = x.getStatus();
                  }
                }
              }
            }
          }else if ( field.equals( "eta" )){
              // infinite -> 215784000
            long eta_secs = stats.getETASecs();
           
            eta_secs = Math.min( eta_secs, 215784000 );
           
            value = new Long( eta_secs );
          }else if ( field.equals( "hashString" )){ 
            value = ByteFormatter.encodeString( t.getHash());
          }else if ( field.equals( "haveUnchecked" )){ 
            value = ZERO;
          }else if ( field.equals( "haveValid" )){
            value = new Long( stats.getDownloaded());
          }else if ( field.equals( "id" )){   
            value = new Long( getID( download ));
          }else if ( field.equals( "trackerSeeds" )){
            DownloadScrapeResult scrape = download.getLastScrapeResult();
            value = new Long( scrape==null?0:scrape.getSeedCount());
          }else if ( field.equals( "trackerLeechers" )){
            DownloadScrapeResult scrape = download.getLastScrapeResult();
            value = new Long( scrape==null?0:scrape.getNonSeedCount());
          }else if ( field.equals( "leechers" )){ 
            if ( pm == null ){
              value = new Long(0);
            }else{
              value = new Long( pm.getNbPeers());
            }
          }else if ( field.equals( "leftUntilDone" )){ 
            value = new Long( stats.getRemaining());
          }else if ( field.equals( "name" )){ 
            value = download.getName();
          }else if ( field.equals( "peersConnected" )){ 
            if ( pm == null ){
              value = new Long(0);
            }else{
              value = new Long( pm.getNbPeers() + pm.getNbSeeds());
            }
          }else if ( field.equals( "peersGettingFromUs" )){ 
            value = new Long( peers_from_us );
          }else if ( field.equals( "peersSendingToUs" )){
            value = new Long( peers_to_us );
          }else if ( field.equals( "isPrivate" )){
            value = t.isPrivate()?TRUE:FALSE;
          }else if ( field.equals( "rateDownload" )){ 
            value = new Long( stats.getDownloadAverage());
          }else if ( field.equals( "rateUpload" )){
            value = new Long( stats.getUploadAverage());
          }else if ( field.equals( "speedLimitDownload" )){ 
            value = new Long( download.getDownloadRateLimitBytesPerSecond());
          }else if ( field.equals( "speedLimitUpload" )){
            value = new Long( download.getUploadRateLimitBytesPerSecond());
          }else if ( field.equals( "seeders" )){
            if ( pm == null ){
              value = new Long(-1);
            }else{
              value = new Long( pm.getNbSeeds());
            }
          }else if ( field.equals( "sizeWhenDone" )){ 
            value = new Long( t.getSize())// TODO: excluded DND
          }else if ( field.equals( "status" )){ 
              // 1 - waiting to verify
              // 2 - verifying
              // 4 - downloading
              // 5 - queued (incomplete)
              // 8 - seeding
              // 9 - queued (complete)
              // 16 - paused
           
            int  status_int = 7;
           
            if ( download.isPaused()){
             
              status_int = 16;
                           
            }else{
              int state = download.getState();
             
              if ( state == Download.ST_DOWNLOADING ){
               
                status_int = 4;
               
              }else if ( state == Download.ST_SEEDING ){
               
                status_int = 8;
               
              }else if ( state == Download.ST_QUEUED ){

                if ( download.isComplete()){
                 
                  status_int = 9;
                 
                }else{
                 
                  status_int = 5;
                }
              }else if ( state == Download.ST_STOPPED || state == Download.ST_STOPPING ){
               
                status_int = 16;
               
              }else if ( state == Download.ST_ERROR ){
               
                status_int = 0;
               
              }else{
               
                if ( core_download.getState() == DownloadManager.STATE_CHECKING ){
               
                  status_int = 2;
                 
                }else{
                 
                  status_int = 1;
                }
              }
            }
            value = new Long(status_int);
          }else if ( field.equals( "swarmSpeed" )){ 
            value = new Long( core_download.getStats().getTotalAveragePerPeer());
          }else if ( field.equals( "totalSize" )){
            value = new Long( t.getSize());
          }else if ( field.equals( "pieceCount" )){
            value = new Long( t.getPieceCount());
          }else if ( field.equals( "pieceSize" )){
            value = new Long( t.getPieceSize());
          }else if ( field.equals( "metadataPercentComplete" )){
            value = new Long( 100 );
          }else if ( field.equals( "uploadedEver" )){ 
            value = new Long( stats.getUploaded());
          }else if ( field.equals( "recheckProgress" )){
           
            double x = 0;
           
            if ( core_download.getState() == DownloadManager.STATE_CHECKING ){
             
              DiskManager dm = core_download.getDiskManager();
             
              if ( dm != null ){
               
                x = ((double)stats.getCompleted())/1000;
              }
            }
           
            value = new Double( x );
          }else if ( field.equals( "uploadRatio" )){
            value = new Double( ((double)stats.getShareRatio())/1000);
          }else if ( field.equals( "seedRatioLimit" )){
            value = new Double( COConfigurationManager.getFloatParameter( "Stop Ratio" ));
          }else if ( field.equals( "seedRatioMode" )){
            // 0=global,1=local,2=unlimited
            value = new Long(1);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.