Examples of Download


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

      } else   if (ds instanceof TranscodeJob) {
        TranscodeJob tj = (TranscodeJob) ds;
        try {
          DiskManagerFileInfo file = tj.getFile();
          if (file != null) {
            Download download = tj.getFile().getDownload();
            if (download != null) {
              DownloadManager dm = PluginCoreUtils.unwrap(download);
              return getContentNetwork(dm);
            }
          }
        } catch (DownloadException e) {
        }
      } else if (ds instanceof TranscodeFile) {
        TranscodeFile tf = (TranscodeFile) ds;
        try {
          DiskManagerFileInfo file = tf.getSourceFile();
          if (file != null) {
            Download download = file.getDownload();
            if (download != null) {
              DownloadManager dm = PluginCoreUtils.unwrap(download);
              return getContentNetwork(dm);
            }
          }
View Full Code Here

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

  public static boolean isExternallyPlayable(TOTorrent torrent, int file_index, boolean complete_only ) {
    if (torrent == null) {
      return false;
    }
    try {
      Download download = AzureusCoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface().getDownloadManager().getDownload(torrent.getHash());
      if (download != null) {
        return isExternallyPlayable(download, file_index, complete_only);
      }
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

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

               
                while( it.hasNext()){
                 
                  Map.Entry<Download,long[]>  entry = it.next();
                 
                  Download  dl     = entry.getKey();
                  long    when  = entry.getValue()[0];
                 
                  if ( when > current_time || current_time - when > ANNOUNCE_PERIOD ){
                   
                    todo.add( dl );
View Full Code Here

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

  handleTrackResult(
    AZInstanceTracked    tracked_inst )
  {
    AZInstance  inst  = tracked_inst.getInstance();
   
    Download  download = (Download)tracked_inst.getTarget().getTarget();
       
    boolean  is_seed = tracked_inst.isSeed();
   
    long  now    = plugin_interface.getUtilities().getCurrentSystemTime();
   
    boolean  skip   = false;
   
      // this code is here to deal with multiple interface machines that receive the result multiple times
   
    try{
      mon.enter();
     
      Map<String,Long>  map = track_times.get( inst.getID() );
     
      if ( map == null ){
       
        map  = new HashMap<String, Long>();
       
        track_times.put( inst.getID(), map );
      }
     
      String  dl_key = plugin_interface.getUtilities().getFormatters().encodeBytesToString(download.getTorrent().getHash());
     
      Long  last_track = map.get( dl_key );
     
      if ( last_track != null ){
       
        long  lt = last_track.longValue();
       
        if ( now - lt < 30*1000 ){
         
          skip  = true;
        }
      }
     
      map.put( dl_key, new Long(now));
     
    }finally{
     
      mon.exit();
    }
   
    if ( skip ){
   
      return( -1 );
    }
   
    log.log( "Tracked: " + inst.getString() + ": " + download.getName() + ", seed = " + is_seed );

    if ( download.isComplete() && is_seed ){
     
      return( is_seed?1:0 );
    }
   
    PeerManager  peer_manager = download.getPeerManager();
   
    if ( peer_manager != null ){ 
     
      String  peer_ip      = inst.getInternalAddress().getHostAddress();
      int    peer_tcp_port  = inst.getTCPListenPort();
      int    peer_udp_port  = inst.getUDPListenPort();
     
      log.log( "    " + download.getName() + ": Injecting peer " + peer_ip + ":" + peer_tcp_port + "/" + peer_udp_port);
     
      peer_manager.addPeer( peer_ip, peer_tcp_port, peer_udp_port, false );
    }
   
    return( is_seed?3:2 );
View Full Code Here

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

     
      List<Object[]> interesting = new ArrayList<Object[]>();
     
      while( rds_it.hasNext()){
       
        Download  dl = rds_it.next();
       
        int  reg_type = REG_TYPE_NONE;
       
        try{
          this_mon.enter();
       
          int[] run_data = running_downloads.get( dl );
         
          if ( run_data != null ){
           
            reg_type = run_data[0];
          }
        }finally{
         
          this_mon.exit();
        }
         
          if ( reg_type == REG_TYPE_NONE ){

            continue;
          }
         
          long metric = getDerivedTrackMetric( dl );
         
          interesting.add( new Object[]{ dl, new Long( metric )} );
      }
     
      Collections.sort(
        interesting,
        new Comparator<Object[]>()
        {
          public int
          compare(
            Object[] entry1,
            Object[] entry2)
          {           
            long  res = ((Long)entry2[1]).longValue() - ((Long)entry1[1]).longValue();
           
            if( res < 0 ){
             
              return( -1 );
             
            }else if ( res > 0 ){
             
              return( 1 );
             
            }else{
             
              return( 0 );
            }
          }
        });
     
      Iterator<Object[]> it  = interesting.iterator();
     
      int  num = 0;
     
      while( it.hasNext()){
       
        Object[] entry = it.next();
       
        Download  dl     = (Download)entry[0];
        long    metric  = ((Long)entry[1]).longValue();
       
        num++;
       
        if ( metric > 0 ){
         
          if ( num <= DL_DERIVED_MIN_TRACK ){
           
              // leave as is
           
          }else if ( num <= DL_DERIVED_MAX_TRACK ){
           
              // scale metric between limits
           
            metric = ( metric * ( DL_DERIVED_MAX_TRACK - num )) / ( DL_DERIVED_MAX_TRACK - DL_DERIVED_MIN_TRACK );
           
          }else{
           
            metric = 0;
          }
        }
       
        if ( metric > 0 ){
         
          dl.setUserData( DL_DERIVED_METRIC_KEY, new Long( metric ));
         
        }else{
         
          dl.setUserData( DL_DERIVED_METRIC_KEY, null );
        }
      }
    }
   
    Iterator<Download>  rds_it = rds.iterator();
   
      // first off do any puts
   
    while( rds_it.hasNext()){
     
      Download  dl = rds_it.next();
     
      int  reg_type = REG_TYPE_NONE;
     
      try{
        this_mon.enter();
     
        int[] run_data = running_downloads.get( dl );
       
        if ( run_data != null ){
         
          reg_type = run_data[0];
        }
      }finally{
       
        this_mon.exit();
      }
       
        if ( reg_type == REG_TYPE_NONE ){

          continue;
        }
       
      byte  flags = isComplete( dl )?DHTPlugin.FLAG_SEEDING:DHTPlugin.FLAG_DOWNLOADING;
     
      RegistrationDetails  registration = (RegistrationDetails)registered_downloads.get( dl );
     
      boolean  do_it = false;
     
      if ( registration == null ){
       
        log( dl, "Registering download as " + (flags == DHTPlugin.FLAG_SEEDING?"Seeding":"Downloading"));

        registration = new RegistrationDetails( dl, reg_type, put_details, flags );
       
        registered_downloads.put( dl, registration );

        do_it = true;
       
      }else{

        boolean  targets_changed = false;
       
        if ( full_processing ){
         
          targets_changed = registration.updateTargets( dl, reg_type );
        }
       
        if targets_changed ||
            registration.getFlags() != flags ||
            !registration.getPutDetails().sameAs( put_details )){
       
          log( dl,(registration==null?"Registering":"Re-registering") + " download as " + (flags == DHTPlugin.FLAG_SEEDING?"Seeding":"Downloading"));
         
          registration.update( put_details, flags );
         
          do_it = true;
        }
      }
     
      if ( do_it ){
       
        try{
          this_mon.enter();

          query_map.put( dl, new Long( now ));

        }finally{
         
          this_mon.exit();
        }
                                           
        trackerPut( dl, registration );
      }
    }
   
      // second any removals
   
    Iterator<Map.Entry<Download,RegistrationDetails>> rd_it = registered_downloads.entrySet().iterator();
   
    while( rd_it.hasNext()){
     
      Map.Entry<Download,RegistrationDetails>  entry = rd_it.next();
     
      final Download  dl = entry.getKey();

      boolean  unregister;
     
      try{
        this_mon.enter();

        unregister = !running_downloads.containsKey( dl );
       
      }finally{
       
        this_mon.exit();
      }
     
      if ( unregister ){
       
        log.log( dl, "Unregistering download" );
               
        rd_it.remove();
       
        try{
          this_mon.enter();

          query_map.remove( dl );
         
        }finally{
         
          this_mon.exit();
        }
       
        trackerRemove( dl, entry.getValue());
      }
    }
   
      // lastly gets
   
    rds_it = rds.iterator();
   
    while( rds_it.hasNext()){
     
      final Download  dl = (Download)rds_it.next();
     
      Long  next_time;
     
      try{
        this_mon.enter();
 
        next_time = (Long)query_map.get( dl );
       
      }finally{
       
        this_mon.exit();
      }
     
      if ( next_time != null && now >= next_time.longValue()){
     
        int  reg_type = REG_TYPE_NONE;
       
        try{
          this_mon.enter();
   
          query_map.remove( dl );
         
          int[] run_data = running_downloads.get( dl );
         
          if ( run_data != null ){
           
            reg_type = run_data[0];
          }
        }finally{
         
          this_mon.exit();
        }
       
        final long  start = SystemTime.getCurrentTime();
         
          // if we're already connected to > NUM_WANT peers then don't bother with the main announce
       
        PeerManager  pm = dl.getPeerManager();
       
          // don't query if this download already has an active DHT operation
       
        boolean  skip  = isActive( dl ) || reg_type == REG_TYPE_NONE;
       
View Full Code Here

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

  }
 
  protected void
  processNonRegistrations()
  {
    Download  ready_download         = null;
    long    ready_download_next_check  = -1;
   
    long  now = plugin_interface.getUtilities().getCurrentSystemTime();
   
      // unfortunately getting scrape results can acquire locks and there is a vague
      // possibility of deadlock here, so pre-fetch the scrape results
   
    List<Download>  to_scrape = new ArrayList<Download>();
   
    try{
      this_mon.enter();

      Iterator<Download>  it = interesting_downloads.keySet().iterator();
     
      while( it.hasNext() && ready_download == null ){
       
        Download  download = it.next();
       
        Torrent  torrent = download.getTorrent();
       
        if ( torrent == null ){
         
          continue;
        }
       
        int[] run_data = running_downloads.get( download );

        if ( run_data == null || run_data[0] == REG_TYPE_DERIVED ){
         
            // looks like we'll need the scrape below
         
          to_scrape.add( download );
        }
      }
    }finally{
     
      this_mon.exit();
    }
   
    Map<Download,DownloadScrapeResult> scrapes = new HashMap<Download,DownloadScrapeResult>();
   
    for (int i=0;i<to_scrape.size();i++){
     
      Download  download = (Download)to_scrape.get(i);
           
      scrapes.put( download, download.getLastScrapeResult());   
    }
   
    try{
      this_mon.enter();

      Iterator<Download>  it = interesting_downloads.keySet().iterator();
     
      while( it.hasNext() && ready_download == null ){
       
        Download  download = it.next();
       
        Torrent  torrent = download.getTorrent();
       
        if ( torrent == null ){
         
          continue;
        }
       
        int[] run_data = running_downloads.get( download );
       
        if ( run_data == null || run_data[0] == REG_TYPE_DERIVED ){
         
          boolean  force =  torrent.wasCreatedByUs();
         
          if ( !force ){
           
            if ( false && !dht.isReachable()){
             
              continue;
            }
           
            if ( interesting_pub_max > 0 && interesting_published > interesting_pub_max ){
             
              continue;
            }
           
            DownloadScrapeResult  scrape = (DownloadScrapeResult)scrapes.get( download );
           
            if ( scrape == null ){
             
                // catch it next time round
             
              continue;
            }
           
            if ( scrape.getSeedCount() + scrape.getNonSeedCount() > NUM_WANT ){
             
              continue;
            }
          }
         
          long  target = ((Long)interesting_downloads.get( download )).longValue();
         
          long check_period = TorrentUtils.isDecentralised( torrent.getAnnounceURL())?INTERESTING_DHT_CHECK_PERIOD:INTERESTING_CHECK_PERIOD;
         
          if ( target <= now ){
           
            ready_download        = download;
            ready_download_next_check   = now + check_period;
           
            interesting_downloads.put( download, new Long( ready_download_next_check ));
           
          }else if ( target - now > check_period ){
           
            interesting_downloads.put( download, new Long( now + (target%check_period)));
          }
        }
      }
     
    }finally{
     
      this_mon.exit();
    }
   
    if ( ready_download != null ){
     
      final Download  f_ready_download = ready_download;
     
      final Torrent torrent = ready_download.getTorrent();
     
      if ( dht.isDiversified( torrent.getHash())){
       
        // System.out.println( "presence query for " + f_ready_download.getName() + "-> diversified pre start" );

        try{
          this_mon.enter();

          interesting_downloads.remove( f_ready_download );
         
        }finally{
         
          this_mon.exit();
        }
      }else{
     
        //System.out.println( "presence query for " + ready_download.getName());
       
        final long start     = now;
        final long f_next_check = ready_download_next_check;
       
        dht.gettorrent.getHash(),
              "Presence query for '" + ready_download.getName() + "'",
              (byte)0,
              INTERESTING_AVAIL_MAX,
              ANNOUNCE_TIMEOUT,
              false, false,
              new DHTPluginOperationListener()
              {
                private boolean diversified;
                private int   leechers = 0;
                private int   seeds   = 0;
               
                public void
                diversified()
                {
                  diversified  = true;
                }
               
                public void
                starts(
                  byte[]         key )
                {
                }
               
                public void
                valueRead(
                  DHTPluginContact  originator,
                  DHTPluginValue    value )
                {
                  if (( value.getFlags() & DHTPlugin.FLAG_DOWNLOADING ) == 1 ){

                    leechers++;
                   
                  }else{
                   
                    seeds++;
                  }
                }
               
                public void
                valueWritten(
                  DHTPluginContact  target,
                  DHTPluginValue    value )
                {
                }
               
                public void
                complete(
                  byte[]  key,
                  boolean  timeout_occurred )
                {
                  // System.out.println( "    presence query for " + f_ready_download.getName() + "->" + total + "/div = " + diversified );
 
                  int  total = leechers + seeds;
                 
                  log( torrent,
                      "Presence query: availability="+
                      (total==INTERESTING_AVAIL_MAX?(INTERESTING_AVAIL_MAX+"+"):(total+"")) + ",div=" + diversified +
                      " (elapsed=" + TimeFormatter.formatColonMillis(SystemTime.getCurrentTime() - start) + ")");
                     
                  if ( diversified ){
                   
                    try{
                      this_mon.enter();
 
                      interesting_downloads.remove( f_ready_download );
                     
                    }finally{
                     
                      this_mon.exit();
                    }
                   
                  }else if ( total < INTERESTING_AVAIL_MAX ){
                   
                      // once we're registered we don't need to process this download any
                      // more unless it goes active and then inactive again
                   
                    try{
                      this_mon.enter();
 
                      interesting_downloads.remove( f_ready_download );
                     
                    }finally{
                     
                      this_mon.exit();
                    }
                   
                    interesting_published++;
                   
                    if ( !disable_put ){
                     
                      dht.put(
                        torrent.getHash(),
                        "Presence store '" + f_ready_download.getName() + "'",
                        "0".getBytes()// port 0, no connections
                        (byte)0,
                        new DHTPluginOperationListener()
                        {
                          public void
                          diversified()
                          {
                          }
                         
                          public void
                          starts(
                            byte[]         key )
                          {
                          }
                         
                          public void
                          valueRead(
                            DHTPluginContact  originator,
                            DHTPluginValue    value )
                          {
                          }
                         
                          public void
                          valueWritten(
                            DHTPluginContact  target,
                            DHTPluginValue    value )
                          {
                          }
                         
                          public void
                          complete(
                            byte[]  key,
                            boolean  timeout_occurred )
                          {
                          }
                        });
                    }
                  }
                 
                 
                  try{
                    this_mon.enter();
                 
                    int[] run_data = running_downloads.get( f_ready_download );
                   
                    if ( run_data == null ){
                     
                      run_data = run_data_cache.get( f_ready_download );
                    }
                   
                    if ( run_data != null ){

                      if ( total < INTERESTING_AVAIL_MAX ){
                     
                        run_data[1] = seeds;
                        run_data[2= leechers;
                        run_data[3] = total;
                       
                      }else{
                       
                        run_data[1] = Math.max( run_data[1], seeds );
                        run_data[2] = Math.max( run_data[2], leechers );
                      }
                    }
                  }finally{
                   
                    this_mon.exit();
                  }
                 
                  f_ready_download.setScrapeResult(
                    new DownloadScrapeResult()
                    {
                      public Download
                      getDownload()
                      {
View Full Code Here

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

           
            Object obj = row.getDataSource();
         
            if ( obj instanceof Download ){
           
              Download download = (Download)obj;

              if ( download.getState() == Download.ST_ERROR ){
               
                enabled = false;
              }
            }else{
             
              DiskManagerFileInfo file = (DiskManagerFileInfo)obj;
             
              try{
                if ( file.getDownload().getState() == Download.ST_ERROR ){
               
                  enabled = false;
                }
              }catch( Throwable e ){
               
                enabled = false;
              }
            }
          }
         
          menu.setEnabled( enabled );
         
          menu.removeAllChildItems();
         
          if ( enabled ){
           
            Device[] devices = device_manager.getDevices();
           
            int  devices_added = 0;
           
            for ( Device device: devices ){
             
              if ( device.isHidden()){
               
                continue;
              }
             
              if ( device instanceof TranscodeTarget ){
               
                devices_added++;
               
                final TranscodeTarget renderer = (TranscodeTarget)device;
               
                TranscodeProfile[] profiles = renderer.getTranscodeProfiles();
               

                TableContextMenuItem device_item =
                  plugin_interface.getUIManager().getTableManager().addContextMenuItem(
                    (TableContextMenuItem)menu,
                    "!" + device.getName() + (profiles.length==0?" (No Profiles)":"") + "!");
               
                device_item.setStyle( MenuItem.STYLE_MENU );
               
                if ( profiles.length == 0 ){
                 
                  device_item.setEnabled( false );
                 
                }else{

                  Arrays.sort(profiles, new Comparator<TranscodeProfile>() {
                    public int compare(TranscodeProfile o1, TranscodeProfile o2) {
                      int i1 = o1.getIconIndex();
                      int i2 = o2.getIconIndex();
                     
                      if ( i1 == i2 ){
                     
                        return o1.getName().compareToIgnoreCase(o2.getName());
                      }else{
                       
                        return( i1 - i2 );
                      }
                    }
                  });

                 
                  for ( final TranscodeProfile profile: profiles ){
                   
                    TableContextMenuItem profile_item =
                      plugin_interface.getUIManager().getTableManager().addContextMenuItem(
                        device_item,
                        "!" + profile.getName() + "!");

                    profile_item.addMultiListener(
                      new MenuItemListener()
                      {
                        public void
                        selected(
                          MenuItem   menu,
                          Object     x )
                        {                         
                          for ( TableRow row: target ){
                           
                            Object obj = row.getDataSource();
                         
                            try{
                              if ( obj instanceof Download ){
                             
                                Download download = (Download)obj;
 
                                addDownload( renderer, profile, -1, download );
                                 
                              }else{
                               
View Full Code Here

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

           
            Object obj = row.getDataSource();
         
            if ( obj instanceof Download ){
           
              Download download = (Download)obj;

              downloads.add( download );
             
              if ( dodm.isManualDownload( download )){
               
View Full Code Here

Examples of org.platformlayer.ops.OneTimeDownloads.Download

  OneTimeDownloads oneTimeDownloads;

  @GET
  @Path("blob/{blobId}")
  public Response downloadBlob(@PathParam("blobId") String blobId) {
    Download download = oneTimeDownloads.get(blobId);
    if (download == null) {
      throw new WebApplicationException(Status.NOT_FOUND);
    }

    String responseData = download.getContent();
    String contentType = download.getContentType();

    ResponseBuilder rBuild = Response.ok(responseData, contentType);
    return rBuild.build();
  }
View Full Code Here

Examples of org.rssowl.contrib.podcast.core.download.Download

            gc.fillRectangle(rect);
            return;
        }

        if (content instanceof Download) {
            Download lDownload = (Download) content;
            String lDraw = "";
            switch (col) {
                case 0: { // The download index.
                    lDraw = new Integer(row).toString();
                }
                    break;
                case 1: { // The file name.
                    if (lDownload.getAttachment().getFile() != null) {
                        lDraw = lDownload.getAttachment().getFile().getName();
                    }else{
                      lDraw = "Error, File name not set";
                    }
                }
                    break; // The feed title.
                case 2: {
                    lDraw = lDownload.getAttachment().getNews().getFeedReference().resolve().getTitle();
                }
                    break;
                case 3: {
                    lDraw = "TODO"; // this is the proress bar.
                }
                    break;
                case 4: {
                    lDraw = Util.formatSpeed(lDownload.getBytesPerSecond())
                            + " kB/s";
                }
                    break;
                case 5: {
                    lDraw = Util.formatTime(lDownload.getTimeElapsed());
                }
                    break;
                case 6: {
                    String status = KDownloadTableModel.STATUS_NAMES[lDownload
                            .getState()];

                    if (lDownload.getState() == DownloadService.RETRYING
                            || lDownload.getState() == DownloadService.ERROR
                            || lDownload.getState() == DownloadService.RELEASING) {
                        status += lDownload.getMessage();
                    }
                    lDraw = status;
                }
                    break;
                case 7: {
                    lDraw = Util.formatSize(lDownload.getCurrent());
                }
            }
            gc.setForeground(textColor);
            gc.setBackground(backColor);
            gc.fillRectangle(rect);
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.