Package org.gudy.azureus2.core3.download

Examples of org.gudy.azureus2.core3.download.DownloadManagerState


         
          public void
          setPeerSources(
            String[]  allowed_sources )
          {
            DownloadManagerState  dms = download_manager.getDownloadState();
           
            String[]  sources = PEPeerSource.PS_SOURCES;
           
            for (int i=0;i<sources.length;i++){
             
              String  s = sources[i];
             
              boolean  ok = false;
             
              for (int j=0;j<allowed_sources.length;j++){
               
                if ( s.equals( allowed_sources[j] )){
                 
                  ok = true;
                 
                  break;
                }
              }
             
              if ( !ok ){
               
                dms.setPeerSourcePermitted( s, false );
              }
            }
           
            PEPeerManager pm = getPeerManager();
           
View Full Code Here


    }

    cached_complete_excluding_dnd = complete_excluding_dnd;
    cached_has_dnd_files = has_dnd_files;
    cached_values_set = true;
    DownloadManagerState state = download_manager.getDownloadState();
    long flags = (cached_complete_excluding_dnd ? STATE_FLAG_COMPLETE_NO_DND : 0) |
                 (cached_has_dnd_files ? STATE_FLAG_HASDND : 0);
    state.setLongParameter(DownloadManagerState.PARAM_DND_FLAGS, flags);
  }
View Full Code Here

                   
                    if ( file_done == file_length ){
                        
                      try{
                        try{
                            DownloadManagerState state = download_manager.getDownloadState();
                         
                          String suffix = state.getAttribute( DownloadManagerState.AT_INCOMP_FILE_SUFFIX );
                         
                          if ( suffix != null && suffix.length() > 0 ){
                           
                            File base_file = this_file.getFile( false );
                           
                            File link = state.getFileLink( base_file );
                           
                            if ( link != null ){
                             
                              String  name = link.getName();
                             
                              if ( name.endsWith( suffix ) && name.length() > suffix.length()){
                               
                                String  new_name = name.substring( 0, name.length() - suffix.length());
                               
                                File new_file = new File( link.getParentFile(), new_name );
                               
                                if ( !new_file.exists()){
                                 
                                  this_file.renameFile( new_name, false );
                                 
                                  if ( base_file.equals( new_file )){
                                   
                                    state.setFileLink( base_file, null );
                                   
                                  }else{
                                   
                                    state.setFileLink( base_file, new_file );
                                  }
                                }
                              }
                            }
                          }
View Full Code Here

  storeFileDownloaded(
    DownloadManager         download_manager,
    DiskManagerFileInfo[]   files,
    boolean          persist )
  {
      DownloadManagerState  state = download_manager.getDownloadState();

      Map   details = new HashMap();

      List  downloaded = new ArrayList();

      details.put( "downloaded", downloaded );

      for (int i=0;i<files.length;i++){

          downloaded.add( new Long( files[i].getDownloaded()));
      }

      state.setMapAttribute( DownloadManagerState.AT_FILE_DOWNLOADED, details );

      if ( persist ){
       
        state.save();
      }
  }
View Full Code Here

    }

      // Used by DownloadManagerImpl too.
   
    public static String[] getStorageTypes(DownloadManager download_manager) {
        DownloadManagerState state = download_manager.getDownloadState();
        String[] types = state.getListAttribute(DownloadManagerState.AT_FILE_STORE_TYPES);
        if (types.length == 0) {
          TOTorrentFile[] files = download_manager.getTorrent().getFiles();
            types = new String[download_manager.getTorrent().getFiles().length];
           
           if ( reorder_storage_mode ){
           
            int  existing = state.getIntAttribute( DownloadManagerState.AT_REORDER_MIN_MB );
           
            if ( existing < 0 ){
             
              existing = reorder_storage_mode_min_mb;
             
              state.setIntAttribute( DownloadManagerState.AT_REORDER_MIN_MB, existing );
            }
                     
            for (int i=0; i<types.length; i++){
                              
                if ( files[i].getLength()/(1024*1024) >= existing ){
                                   
                  types[i] = "R";
                 
                }else{
                 
                  types[i] = "L";
                }
              }
            }else{
            
             for (int i=0; i<types.length; i++){
              
               types[i] = "L";
             }
            }
          
      state.setListAttribute(DownloadManagerState.AT_FILE_STORE_TYPES, types );
        }
       
        return( types );
    }
View Full Code Here

    }
   
      // Used by DownloadManagerImpl too.
   
    public static String getStorageType(DownloadManager download_manager, int fileIndex) {
        DownloadManagerState state = download_manager.getDownloadState();
        String type = state.getListAttribute(DownloadManagerState.AT_FILE_STORE_TYPES,fileIndex);
       
        if ( type != null ){
         
          return( type );
        }
View Full Code Here

                  return( false );
              }
          }
      }
 
      DownloadManagerState    state = download_manager.getDownloadState();
 
      state.setFileLink( from_file, to_link );
 
      state.save();
 
      return( true );
  }
View Full Code Here

         
          String[] types = DiskManagerImpl.getStorageTypes(download_manager);
          boolean[] modified = new boolean[res.length];
          boolean[] toSkip = new boolean[res.length];
          int toSkipCount = 0;
          DownloadManagerState dmState = download_manager.getDownloadState();
         
          try {
            dmState.suppressStateSave(true);
 
            for(int i=0;i<res.length;i++)
            {
              if(!toChange[i])
                continue;
 
 
              final int idx = i;
 
              int old_type = DiskManagerUtil.convertDMStorageTypeFromString( types[i] );
 
              //System.out.println(old_type + " <> " + newStroageType);
 
              if ( newStorageType == old_type )
              {
                modified[i] = true;
                continue;
              }
 
              try{
                File    target_file = res[i].getFile( true );
 
                // if the file doesn't exist then this is the start-of-day, most likely
                // being called from the torrent-opener, so we don't need to do any
                // file fiddling (in fact, if we do, we end up leaving zero length
                // files for dnd files which then force a recheck when the download
                // starts for the first time)
 
                if ( target_file.exists()){
 
                  CacheFile cache_file =
                    CacheFileManagerFactory.getSingleton().createFile(
                      new CacheFileOwner()
                      {
                        public String
                        getCacheFileOwnerName()
                        {
                          return( download_manager.getInternalName());
                        }
 
                        public TOTorrentFile
                        getCacheFileTorrentFile()
                        {
                          return( res[idx].getTorrentFile() );
                        }
 
                        public File
                        getCacheFileControlFileDir()
                        {
                          return( download_manager.getDownloadState().getStateFile( ));
                        }
                        public int
                        getCacheMode()
                        {
                          return( CacheFileOwner.CACHE_MODE_NORMAL );
                        }
                      },
                      target_file,
                      DiskManagerUtil.convertDMStorageTypeToCache( newStorageType ));
 
                  cache_file.close();
 
                  toSkip[i] = ( newStorageType == FileSkeleton.ST_COMPACT || newStorageType == FileSkeleton.ST_REORDER_COMPACT )&& !res[i].isSkipped();
                  if(toSkip[i])
                    toSkipCount++;
                }
 
 
                modified[i] = true;
 
              }catch( Throwable e ){
 
                Debug.printStackTrace(e);
 
                Logger.log(
                  new LogAlert(download_manager,
                    LogAlert.REPEATABLE,
                    LogAlert.AT_ERROR,
                    "Failed to change storage type for '" + res[i].getFile(true) +"': " + Debug.getNestedExceptionMessage(e)));
 
                // download's not running - tag for recheck
 
                RDResumeHandler.recheckFile( download_manager, res[i] );
 
              }
 
              types[i] = DiskManagerUtil.convertDMStorageTypeToString( newStorageType );
            }
           
            /*
             * set storage type and skipped before we do piece clearing and file
             * clearing checks as those checks work better when skipped/stype is set
             * properly
             */
            dmState.setListAttribute( DownloadManagerState.AT_FILE_STORE_TYPES, types);
            if(toSkipCount > 0)
              setSkipped(toSkip, true);
           
           
            for(int i=0;i<res.length;i++)
            {
              if(!toChange[i])
                continue;
             
              // download's not running, update resume data as necessary
 
              int cleared = RDResumeHandler.storageTypeChanged( download_manager, res[i] );
 
              // try and maintain reasonable figures for downloaded. Note that because
              // we don't screw with the first and last pieces of the file during
              // storage type changes we don't have the problem of dealing with
              // the last piece being smaller than torrent piece size
 
              if (cleared > 0)
              {
                res[i].downloaded = res[i].downloaded - cleared * res[i].getTorrentFile().getTorrent().getPieceLength();
                if (res[i].downloaded < 0) res[i].downloaded = 0;
              }
            }
 
            DiskManagerImpl.storeFileDownloaded( download_manager, res, true );
 
            doFileExistenceChecks(this, toChange, download_manager, newStorageType == FileSkeleton.ST_LINEAR || newStorageType == FileSkeleton.ST_REORDER );
 
          } finally {
            dmState.suppressStateSave(false);
            dmState.save();
          }
         
          return modified;
        }
          };
View Full Code Here

  protected static void
    loadFileDownloaded(
      DownloadManager             download_manager,
      DiskManagerFileInfoHelper[] files )
    {
        DownloadManagerState  state = download_manager.getDownloadState();
 
        Map   details = state.getMapAttribute( DownloadManagerState.AT_FILE_DOWNLOADED );
 
        if ( details == null ){
 
            return;
        }
View Full Code Here

      if ( TorrentUtils.isDecentralised(to_torrent)){
       
        TorrentUtils.setDecentralised( to_torrent );
      }
           
      DownloadManagerState  download_manager_state =
        DownloadManagerStateFactory.getDownloadState( to_torrent );

      TorrentUtils.setResumeDataCompletelyValid( download_manager_state );

      download_manager_state.save();
     
      if ( item == null ){
       
        byte[] fingerprint = getFingerPrint();
     
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.core3.download.DownloadManagerState

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.