Package org.gudy.azureus2.core3.disk

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


    DownloadManager dm = (DownloadManager) ds;
    if (rowCore.getSubItemCount() == 0 && dm.getTorrent() != null
        && !dm.getTorrent().isSimpleTorrent() && rowCore.isVisible()
        && dm.getNumFileInfos() > 0) {
      DiskManagerFileInfoSet fileInfos = dm.getDiskManagerFileInfoSet();
      if (fileInfos != null) {
        DiskManagerFileInfo[] files = fileInfos.getFiles();
        boolean copied = false;
        int pos = 0;
        for (int i = 0; i < files.length; i++) {
          DiskManagerFileInfo fileInfo = files[i];
          if (fileInfo.isSkipped()
View Full Code Here


            boolean partially_written = false;
            if (firstPiece >= 0)
              for (int j = a0; j < a1; j++)
              {
                final int this_index = j + firstPiece;
                final DiskManagerPiece dm_piece = dm_pieces[this_index];
                if (dm_piece.isDone())
                  nbAvailable++;
                if (written)
                  continue;
                if (pe_pieces != null)
                {
                  PEPiece pe_piece = pe_pieces[this_index];
                  if (pe_piece != null)
                    written = written || (pe_piece.getLastDownloadTime(now) + 500) > last_draw_time;
                }
                if ((!written) && (!partially_written))
                {
                  final boolean[] blocks = dm_piece.getWritten();
                  if (blocks != null)
                    for (int k = 0; k < blocks.length; k++)
                      if (blocks[k])
                      {
                        partially_written = true;
View Full Code Here

   
    int  piece_number = y_block*iNumCols + x_block + first_piece;
   
    if ( piece_number >= first_piece && piece_number < first_piece + num_pieces ){
     
      DiskManagerPiece  dm_piece = dm_pieces[piece_number];
      PEPiece        pe_piece = pe_pieces[piece_number];
     
      String  text =  "Piece " + piece_number + ": " + dm_piece.getString();
     
      if ( pe_piece != null ){
       
        text += ", active: " + pe_piece.getString();

      }else{
       
        if ( dm_piece.isNeeded() && !dm_piece.isDone()){
         
          text += ", inactive: " + peer_manager.getPiecePicker().getPieceString( piece_number );
        }
      }
     
View Full Code Here

      int iRow = 0;
      int iCol = 0;
     
      for (int i = first_piece; i < first_piece+num_pieces; i++) {
     
        DiskManagerPiece  dm_piece = dm_pieces[i];
        PEPiece        pe_piece = pe_pieces[i];
       
        int colorIndex;
     
        int iXPos = iCol * BLOCK_SIZE;
        int iYPos = iRow * BLOCK_SIZE;

        if ( dm_piece.isDone()){

          colorIndex = BLOCKCOLOR_DONE;

        }else if ( !dm_piece.isNeeded()){
         
          colorIndex = BLOCKCOLOR_SKIPPED;

        }else if ( pe_piece != null ){
         
View Full Code Here

          for (int i = 0; i < pieces.length; i++){
           
            check_position  = i;
           
            DiskManagerPiece  dm_piece  = pieces[i];
           
            disk_manager.setPercentDone(((i + 1) * 1000) / disk_manager.getNbPieces() );
           
            boolean pieceCannotExist = false;
           
            byte  piece_state = resume_pieces[i];
           
              // valid resume data means that the resume array correctly represents
              // the state of pieces on disk, be they done or not
           
            if ( piece_state == PIECE_DONE || !resumeValid || recheck_all ){
           
                // at least check that file sizes are OK for this piece to be valid
             
              DMPieceList list = disk_manager.getPieceList(i);
             
              for (int j=0;j<list.size();j++){
               
                DMPieceMapEntry  entry = list.get(j);
               
                Long  file_size     = (Long)file_sizes.get(entry.getFile());
               
                if ( file_size == null ){
                 
                  piece_state  = PIECE_NOT_DONE;
                  pieceCannotExist = true;
                 
                  if (Logger.isEnabled())
                    Logger.log(new LogEvent(disk_manager, LOGID,
                        LogEvent.LT_WARNING, "Piece #" + i
                            + ": file is missing, " + "fails re-check."));
 
                  break;
                }
               
                long  expected_size   = entry.getOffset() + entry.getLength();
               
                if ( file_size.longValue() < expected_size ){
                 
                  piece_state  = PIECE_NOT_DONE;
                  pieceCannotExist = true;
                 
                  if (Logger.isEnabled())
                    Logger.log(new LogEvent(disk_manager, LOGID,
                        LogEvent.LT_WARNING, "Piece #" + i
                            + ": file is too small, fails re-check. File size = "
                            + file_size + ", piece needs " + expected_size));
 
                  break;
                }
              }
            }
           
            if ( piece_state == PIECE_DONE ){
             
              dm_piece.setDone( true );
             
            }else if ( piece_state == PIECE_NOT_DONE && !recheck_all ){
             
                // if the piece isn't done and we haven't been asked to recheck all pieces
                // on restart (only started pieces) then just set as not done
                                   
            }else{
             
                // We only need to recheck pieces that are marked as not-ok
                // if the resume data is invalid or explicit recheck needed
              if(pieceCannotExist)
              {
                dm_piece.setDone( false );
              } else if ( piece_state == PIECE_RECHECK_REQUIRED || !resumeValid ){
                   
                run_sem.reserve();
               
                while( !stopped ){
                   
                  if ( recheck_inst.getPermission()){
                   
                    break;
                  }
                }
               
                if ( stopped ){
                                   
                  break;
                 
                }else{
                 
                  try
                    DiskManagerCheckRequest  request = disk_manager.createCheckRequest( i, null );
                   
                    request.setLowPriority( true );
                   
                    checker.enqueueCheckRequest(
                      request,
                      new DiskManagerCheckRequestListener()
                      {
                        public void
                        checkCompleted(
                          DiskManagerCheckRequest   request,
                          boolean            passed )
                        {
                          if ( TEST_RECHECK_FAILURE_HANDLING && (int)(Math.random()*10) == 0 ){
                           
                            disk_manager.getPiece(request.getPieceNumber()).setDone(false);
                           
                            passed  = false;
                          }
                         
                          if ( !passed ){
                           
                            synchronized( failed_pieces ){
                           
                              failed_pieces.add( request );
                            }
                          }
                         
                          complete();
                        }
                        
                        public void
                        checkCancelled(
                          DiskManagerCheckRequest    request )
                        {
                          complete();
                        }
                       
                        public void
                        checkFailed(
                          DiskManagerCheckRequest   request,
                          Throwable           cause )
                        {
                          complete();
                        }
                       
                        protected void
                        complete()
                        {
                          run_sem.release();
                         
                          pending_checks_sem.release();
                        }
                      });
                   
                    pending_check_num++;
                   
                  }catch( Throwable e ){
                 
                    Debug.printStackTrace(e);
                  }
                }
              }
            }
          }
         
          while( pending_check_num > 0 ){
           
            pending_checks_sem.reserve();
           
            pending_check_num--;
          }
         
          if ( partialPieces != null ){
                             
            Iterator iter = partialPieces.entrySet().iterator();
           
            while (iter.hasNext()) {
             
              Map.Entry key = (Map.Entry)iter.next();
             
              int pieceNumber = Integer.parseInt((String)key.getKey());
               
              DiskManagerPiece  dm_piece = pieces[ pieceNumber ];
             
              if ( !dm_piece.isDone()){
               
                List blocks = (List)partialPieces.get(key.getKey());
               
                Iterator iterBlock = blocks.iterator();
               
                while (iterBlock.hasNext()) {
                 
                  dm_piece.setWritten(((Long)iterBlock.next()).intValue());
                }
              }
            }
          }
        }else{
View Full Code Here

   
    byte[] resume_pieces = new byte[pieces.length];
   
    for (int i = 0; i < resume_pieces.length; i++) {
     
      DiskManagerPiece piece = pieces[i];

        // if we are terminating due to az closure and this has interrupted a recheck then
        // make sure that the recheck continues appropriately on restart
     
      if ( stopped_for_close && check_interrupted && check_is_full_check && i >= check_position ){
       
        resume_pieces[i] = PIECE_RECHECK_REQUIRED;
       
      }else if ( piece.isDone()){
         
        resume_pieces[i] = PIECE_DONE;
         
        }else if ( piece.getNbWritten() > 0 ){
         
          resume_pieces[i] = PIECE_STARTED;
         
        }else{
       
        resume_pieces[i] = PIECE_NOT_DONE;
        }
    }
   
    Map  resume_data = new HashMap();
       
    resume_data.put( "resume data", resume_pieces );
   
    Map partialPieces = new HashMap();
                     
    for (int i = 0; i < pieces.length; i++) {
     
      DiskManagerPiece piece = pieces[i];
     
        // save the partial pieces for any pieces that have not yet been completed
        // and are in-progress (i.e. have at least one block downloaded)
     
      boolean[] written = piece.getWritten();

      if (( !piece.isDone()) && piece.getNbWritten() > 0 && written != null ){
       
        boolean  all_written = true;
       
        for (int j = 0; j < written.length; j++) {
View Full Code Here

        writeCompleted(
          org.gudy.azureus2.core3.disk.DiskManagerWriteRequest   _request )
        {
          DiskManagerPiece[]  dm_pieces = disk_manager.getPieces();
       
          DiskManagerPiece  dm_piece = dm_pieces[piece_number];

          if (!dm_piece.isDone()){
           
            int  current_offset = offset;
           
            for ( int i=0;i<length;i+=DiskManager.BLOCK_SIZE ){
           
              dm_piece.setWritten( current_offset / DiskManager.BLOCK_SIZE );
             
              current_offset += DiskManager.BLOCK_SIZE;
            }
          }
         
View Full Code Here

          current = have_map[pos++]&0xff;
        }
       
        if (( current & 0x80 ) != 0 ){
         
          DiskManagerPiece piece = pieces[i];
         
          boolean[] written = piece.getWritten();
         
          if ( written == null ){
           
            if ( !piece.isDone()){
         
              remaining += piece.getLength();
            }
          }else{
           
            for (int j=0;j<written.length;j++){
             
              if ( !written[j] ){
               
                remaining += piece.getBlockSize( j );
              }
            }
          }
        }
       
View Full Code Here

    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;
   
    if ( !first_piece.isDone()){
     
      boolean[] blocks = first_piece.getWritten();
           
      if ( blocks == null ){
       
        if ( first_piece.isDone()){
         
          available = first_piece.getLength() - first_piece_offset;
        }
      }else{
       
        int  piece_offset = 0;
       
        for (int j=0;j<blocks.length;j++){
       
          if ( blocks[j] ){
         
            int  block_size = first_piece.getBlockSize( j );
           
            piece_offset = piece_offset + block_size;
           
            if ( available == 0 ){
           
              if ( piece_offset > first_piece_offset ){
               
                available = piece_offset - first_piece_offset;
              }
            }else{
             
              available += block_size;
            }           
          }else{
           
            break;
          }
        }
      } 
    }else{
   
      available = first_piece.getLength() - first_piece_offset;
   
      for (int i=first_piece_index+1;i<=last_piece_index;i++){
       
        if ( stop_counting_after > 0 && available >= stop_counting_after ){
         
          break;
        }
       
        DiskManagerPiece piece = pieces[i];
       
        if ( piece.isDone()){
         
          available += piece.getLength();
         
        }else{
       
          boolean[] blocks = piece.getWritten();
             
          if ( blocks == null ){
           
            if ( piece.isDone()){
         
              available += piece.getLength();
             
            }else{
             
              break;
            }
          }else{
           
            for (int j=0;j<blocks.length;j++){
           
              if ( blocks[j] ){
             
                available += piece.getBlockSize( j );
               
              }else{
               
                break;
              }
View Full Code Here

       
        int  last_piece_number = primary_file.getFile().getLastPieceNumber();
       
        for (int i=(int)(provider_byte_position/piece_size);i<=last_piece_number;i++){
         
          DiskManagerPiece piece = pieces[i];
         
          if ( piece.isDone()){
           
            continue;
          }
         
          if ( first_incomplete_piece == -1 ){
           
            first_incomplete_piece = i;
          }
         
          boolean[] blocks = piece.getWritten();
         
          int  bytes_this_piece = 0;
         
          if ( blocks == null ){
           
            bytes_this_piece = piece.getLength();
           
          }else{
            for (int j=0;j<blocks.length;j++){
             
              if ( !blocks[j] ){
               
                bytes_this_piece += piece.getBlockSize( j );
              }
            }
          }
         
          if ( bytes_this_piece > 0 ){
           
            actual_bytes_to_download += bytes_this_piece;
           
            int  diff = i - first_incomplete_piece;
           
            if ( diff == 0 ){
             
              weighted_bytes_to_download += bytes_this_piece;
             
            }else{
                           
              int  weighted_bytes_done =  piece.getLength() - bytes_this_piece;
           
              weighted_bytes_done = ( weighted_bytes_done * ( pieces.length - i )) / (pieces.length - first_incomplete_piece);
           
              weighted_bytes_to_download += piece.getLength() - weighted_bytes_done;
            }
          }
        }
      }
     
View Full Code Here

TOP

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

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.