Package org.gudy.azureus2.core3.disk

Examples of org.gudy.azureus2.core3.disk.DiskManager


   
      try{
         // Data files don't exist, so we just don't do anything.
          if (!getSaveLocation().exists()) {return;}
         
          DiskManager dm = this.getDiskManager();
          if (dm != null) {
            dm.downloadRemoved();
            return;
          }
               
          SaveLocationChange move_details;
          move_details = DownloadManagerMoveHandler.onRemoval(this);
View Full Code Here


  {
    manager      = _manager;
    connection    = _connection;
    peer      = _peer;
   
    DiskManager dm = peer.getManager().getDiskManager();
   
    long  last_modified = 0;
   
    try{
      last_modified = dm.getFiles()[0].getFile(true).lastModified();
           
    }catch( Throwable e ){
    }
   
    last_modified_date = TimeFormatter.getHTTPDate( last_modified );
View Full Code Here

      return;
    }   
   
    PEPeerControl  control = getPeerControl();
   
    DiskManager  dm = control.getDiskManager();
   
    if ( dm == null ){
     
      Debug.out( "Disk manager is null" );
     
      throw( new IOException( "Disk manager unavailable" ));
    }
         
    TOTorrent  to_torrent = dm.getTorrent();
       
    char[]  chars = header.toCharArray();
   
    int  last_pos   = 0;
    int  line_num  = 0;
   
    String        target_str  = null;
   
    DiskManagerFileInfo  target_file = null;
   
    long  file_offset  = 0;
   
    List<long[]>  ranges = new ArrayList<long[]>();
   
    boolean  keep_alive  = false;
   
    for (int i=1;i<chars.length;i++){
     
      if ( chars[i-1] == '\r' && chars[i] == '\n' ){
       
        String  line = new String( chars, last_pos, i - last_pos ).trim();
       
        last_pos = i;
       
        line_num++;
       
        // System.out.println( "line " + line_num + " -> " + line );
       
        if ( line_num == 1 ){
         
          line = line.substring( line.indexOf( "files/" ) + 6 );
         
          int  hash_end = line.indexOf( "/" );
         
          final byte[] old_hash = control.getHash();

          final byte[] new_hash = URLDecoder.decode(line.substring(0, hash_end), "ISO-8859-1").getBytes( "ISO-8859-1" );
         
          if ( !Arrays.equals( new_hash, old_hash )){
           
            switching    = true;
           
            decoder.pauseInternally();
             
            flushRequests(
              new flushListener()
              {
                private boolean triggered;
               
                public void
                flushed()
                {
                  synchronized( this ){
                   
                    if ( triggered ){
                     
                      return;
                    }
                   
                    triggered = true;
                  }
                 
                  getManager().reRoute(
                      HTTPNetworkConnectionFile.this,
                      old_hash, new_hash, header );
                }
              });
             
            return;
          }
         
         
          line = line.substring( hash_end + 1 );
         
          line = line.substring( 0, line.lastIndexOf( ' ' ));
         
          String  file = line;

          if ( to_torrent.isSimpleTorrent()){
           
              // optimise for simple torrents. also support the case where
              // client has the hash but doesn't know the file name
           
            target_file = dm.getFiles()[0];
           
          }else{
           
            target_str  = file;
           
            StringTokenizer  tok = new StringTokenizer( file, "/" );
           
            List<byte[]>  bits = new ArrayList<byte[]>();
           
            while( tok.hasMoreTokens()){
             
              bits.add( URLDecoder.decode(tok.nextToken(), "ISO-8859-1").getBytes( "ISO-8859-1" ));
            }
           
              // latest spec has torrent file name encoded first for non-simple torrents
              // remove it if we find it so we have some backward compat
           
            if ( !to_torrent.isSimpleTorrent() && bits.size() > 1 ){
           
              if ( Arrays.equals( to_torrent.getName(), (byte[])bits.get(0))){
               
                bits.remove(0);
              }
            }
           
            DiskManagerFileInfo[]  files = dm.getFiles();
           
            file_offset  = 0;
           
            for (int j=0;j<files.length;j++){
             
View Full Code Here

          }
        }
       
        if ( state == DownloadManager.STATE_SEEDING ){
       
          DiskManager disk_manager = manager.getDiskManager();
 
          if ( disk_manager != null && disk_manager.getCompleteRecheckStatus() != -1 ){
         
              // wait until recheck is complete before we mark as downloading-complete
           
            is_downloading  = true;
           
View Full Code Here

        try{
          byte[] hash = torrent.getHash();
         
          String  hash_str = ByteFormatter.encodeString( hash );
         
          DiskManager disk = download.getDiskManager();
         
          if ( disk == null ){
           
            byte[] existing = old_cache.get( hash_str );
           
            if ( existing != null ){
             
              new_cache.put( hash_str, existing );
             
              download_map.put( download, existing );
             
            }else{
             
                // assume not yet started and just use the non-skipped files
             
              DiskManagerFileInfo[] files = download.getDiskManagerFileInfo();
             
              byte[] needed = new byte[( torrent.getNumberOfPieces() + 7 ) / 8];

              int  hits = 0;

              for ( DiskManagerFileInfo file: files ){
               
                if ( file.isSkipped()){
                 
                  continue;
                }
               
                int  first_piece   = file.getFirstPieceNumber();
                int  last_piece    = first_piece + file.getNbPieces() - 1;
                               
                int  needed_pos    = first_piece/8;
                int  current_byte  = 0;
                               
                for ( int pos=first_piece;pos<=last_piece;pos++ ){
                 
                  current_byte = current_byte << 1;
                                     
                  current_byte += 1;
                   
                  hits++;
                 
                  if (( pos %8 ) == 7 ){
                   
                    needed[needed_pos++] |= (byte)current_byte;
                   
                    current_byte = 0;
                  }
                }
               
                if ( current_byte != 0 ){
                 
                  needed[needed_pos++] |= (byte)(current_byte << (8 - (last_piece % 8)));
                }
              }
             
              if ( hits > 0 ){
                 
                new_cache.put( hash_str, needed );
                 
                download_map.put( download, needed );
              }
            }
          }else{
         
            DiskManagerPiece[] pieces = disk.getPieces();
           
            byte[] needed = new byte[( pieces.length + 7 ) / 8];
           
            int  needed_pos    = 0;
            int  current_byte  = 0;
View Full Code Here

      if ( now - last_calc_time < 2*1000 ){
       
        return( last_calc );
      }
     
      DiskManager disk = download.getDiskManager();

      if ( disk == null ){
       
        return( last_calc );
      }
     
      DiskManagerPiece[] pieces = disk.getPieces();
     
      int  pos    = 0;
      int  current  = 0;
     
      long remaining = 0;
View Full Code Here

                {
                  public void
                  peerManagerWillBeAdded(
                    PEPeerManager  peer_manager )
                  {
                      DiskManager  disk_manager = peer_manager.getDiskManager();
                     
                      DiskManagerPiece[]  pieces = disk_manager.getPieces();

                            int startPiece = setStartPieceBasedOnMode(testMode,pieces.length);
                           
                            for ( int i=startPiece; i<pieces.length; i++ ){
                                pieces[i].setDone( true );
View Full Code Here

    EnhancedDownloadManagerFile  efile = enhanced_files[ file_index ];
   
    DiskManagerFileInfo file = efile.getFile();
   
    DiskManager dm = download_manager.getDiskManager();
   
    if ( dm == null ){
     
      if ( file.getDownloaded() == file.getLength()){
       
        return( file.getLength() - file_start_offset );
      }
     
      return( -1 );
    }
   
    int  piece_size = dm.getPieceLength();
   
    DiskManagerFileInfo[]   files = dm.getFiles();
   
    long  start_index = efile.getByteOffestInTorrent() + file_start_offset;
 
   
    int  first_piece_index   = (int)( start_index / piece_size );
    int  first_piece_offset  = (int)( start_index % piece_size );
    int  last_piece_index  = file.getLastPieceNumber();
   
    DiskManagerPiece[]  pieces = dm.getPieces();
   
    DiskManagerPiece  first_piece = pieces[first_piece_index];
       
    long  available = 0;
   
View Full Code Here

        return( piece_rtas );
      }
     
      last_recalc  = mono_now;
               
        DiskManager  disk_manager = download_manager.getDiskManager();

        progressiveStats stats = progressive_stats;

        EnhancedDownloadManagerFile file = stats.getFile();

        if ( disk_manager == null || stats == null || file.isComplete()){
            
          deactivate( picker );
         
          return( null );
        }
       
      long  abs_provider_pos = stats.getCurrentProviderPosition( true );
       long  rel_provider_pos = stats.getCurrentProviderPosition( false );

      long  buffer_bytes = stats.getBufferBytes();
      
        boolean buffering = getProgressivePlayETA() >= 0;
       
        if ( buffering ){
         
        long   buffer_size = getContiguousAvailableBytes( file.getIndex(), rel_provider_pos, buffer_bytes );
       
        if ( buffer_size == buffer_bytes ){
         
          buffering = false;
        }
        }
         
        if ( buffering != is_buffering ){
       
          if ( buffering ){
           
            log( "Switching to buffer mode" );
           
          }else{
           
            log( "Switching to RTA mode" );
          }
         
          is_buffering = buffering;
        }
       
      long  piece_size = disk_manager.getPieceLength();
                    
      int    start_piece = (int)( abs_provider_pos / piece_size );

      int    end_piece  = file.getFile().getLastPieceNumber();
           
      piece_rtas = new long[ picker.getNumberOfPieces()];

      long  now = SystemTime.getCurrentTime();

      if ( is_buffering ){
               
        for (int i=start_piece;i<=end_piece;i++){
         
            // not bothered about times here but need to use large increments to ensure
            // that pieces are picked in order even for slower peers
         
          piece_rtas[i] = now+(i*60000);
        }
 
        long   buffer_size = getContiguousAvailableBytes( file.getIndex(), rel_provider_pos, 0 );
                    
          if ( last_buffer_size != buffer_size ){
           
            last_buffer_size = buffer_size;
           
            last_buffer_size_time = now;
           
          }else{
           
            if ( now < last_buffer_size_time ){
             
              last_buffer_size_time = now;
             
            }else{
             
              long  stalled_for = now - last_buffer_size_time;
             
               long  dl_speed = progressive_stats.getDownloadBytesPerSecond();
             
               if ( dl_speed > 0 ){
                
                 long  block_time = (DiskManager.BLOCK_SIZE * 1000) / dl_speed;
                
                 if ( stalled_for > Math.max( 5000, 5*block_time )){
               
                   long  target_rta = now + block_time;
                  
                   int  blocked_piece_index = (int)((abs_provider_pos + buffer_size ) / disk_manager.getPieceLength());
                  
                   DiskManagerPiece[] pieces = disk_manager.getPieces();
                                    
                   if ( blocked_piece_index < pieces.length ){
                                        
                     if ( pieces[blocked_piece_index].isDone()){
                      
View Full Code Here

     
      discard_rate_average.update( discards - last_discard_bytes );
     
      last_discard_bytes = discards;
     
      DiskManager  disk_manager = download_manager.getDiskManager();
     
      PiecePicker  picker = current_piece_pickler;

      if ( getStreamBytesPerSecondMin() > 0 && disk_manager != null && picker != null ){
       
        List  providers = picker.getRTAProviders();
       
        long  max_cp  = 0;
       
        PieceRTAProvider  best_provider = null;
       
        for (int i=0;i<providers.size();i++){
         
          PieceRTAProvider  provider = (PieceRTAProvider)providers.get(i);
         
          if ( provider.getStartTime() > 0 ){
           
            long  cp = provider.getCurrentPosition();
           
            if ( cp >= max_cp ){
             
              best_provider = provider;
             
              max_cp  = cp;
            }
          }
        }

        updateCurrentProvider( best_provider );
                       
        if ( best_provider != null ){
               
            // the file channel provider will try best-effort-RTA based which will result
            // in high discard - back it off based on how much slack we have
         
          long relative_pos = getCurrentProviderPosition( false );
         
          long buffer_bytes = getContiguousAvailableBytes( primary_file.getIndex(), relative_pos, getStreamBytesPerSecondMin() * 60 );
         
          long buffer_secs = buffer_bytes / getStreamBytesPerSecondMin();
         
            // don't be too aggresive with small buffers
         
          buffer_secs = Math.max( 10, buffer_secs );
         
          best_provider.setBufferMillis( 15*1000, buffer_secs * 1000 );
        }
       
        DiskManagerPiece[] pieces = disk_manager.getPieces();
       
        actual_bytes_to_download   = 0;
        weighted_bytes_to_download  = 0;
       
        int  first_incomplete_piece = -1;
       
        int  piece_size = disk_manager.getPieceLength();
       
        int  last_piece_number = primary_file.getFile().getLastPieceNumber();
       
        for (int i=(int)(provider_byte_position/piece_size);i<=last_piece_number;i++){
         
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.core3.disk.DiskManager

Copyright © 2018 www.massapicom. 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.