Package org.gudy.azureus2.plugins.download

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


public class TorrentListener {
   
       
    public static void isSeeding(){

            final DownloadManager dm;
            dm = Plugin.getPluginInterface().getDownloadManager();
            DownloadManagerListener dml = new DownloadManagerListener()
                {
                    public void
                    downloadAdded(
                    final Download  download )
                    {
                        //DownloadManagerUtils.cleanAll();
                        download.addListener(new DownloadListener() {

                            public void stateChanged(Download download, int old_state, int new_state) {
                                //System.out.println(download.getName() + " : From: " + old_state + " : To: " + new_state);
                                if(old_state == Download.ST_DOWNLOADING
                                        && new_state == Download.ST_SEEDING
                                        && download.isComplete()){
                                   
                                    //Per Paul this should work to distinguish between the two states
                                    //Finished download and unpaused seeding
                                   
                                    if(download.getStats().getSecondsOnlySeeding() == 0){
                                        //System.out.println("Download to seed!");
                                        DownloadManagerUtils.cleanOne(Utilities.verifyName(download.getName()),1);
                                    }else{
                                       
                                        DownloadManagerUtils.cleanOne(Utilities.verifyName(download.getName()),1);
                                        //DownloadManagerUtils.cleanOne(download.getName(),2);
                                    }
                                       
                                                                       
                                  
                                   
                                }else if(old_state == Download.ST_DOWNLOADING && !download.isComplete()){
                                    //TODO check the states of a download finishing and see if we can distinguish between a 'stop'
                                    //for pausing and a stop for going to seeding
                                    //DownloadManagerUtils.cleanAll();
                                }else if(old_state == Download.ST_PREPARING){
                                    DownloadManagerUtils.cleanOne(Utilities.verifyName(download.getName()),1);
                                }else{
                                    //might not need the catchall here
                                    DownloadManagerUtils.cleanOne(Utilities.verifyName(download.getName()),2);
                                }
                               
                               
                            }

                            public void positionChanged(Download download, int oldPosition, int newPosition) {
                                //DownloadManagerUtils.cleanAll();
                            }
                           
                        });              
                       
                       
                       
                      
                    }
                    public void
                    downloadRemoved(
                        Download    download )
                    {
                        //DownloadManagerUtils.cleanAll();
                      
                        //First check to see if it is in the seeds section
                        DownloadManagerUtils.cleanOne(Utilities.verifyName(download.getName()),2);
                       
                        //Then run through hidden removal
                        String[] hidden = HideFiles.read();
                        for(int i = 0 ; i < hidden.length ; i++){
                            if(hidden[i] != null && hidden[i].equalsIgnoreCase(Utilities.verifyName(download.getName()))){
                                HideFiles.removeFile(Utilities.verifyName(download.getName()));
                            }
                        }
                    }
                };
           

                dm.addListener(dml);
        }
View Full Code Here


 
  public void get_connected_IPs(){
    try{
      
      
        DownloadManager dm = pluginInterface.getDownloadManager();
      final PeerManagerListener pml = new PeerManagerListener()
      {                     
        public void
        peerAdded(
          final PeerManager  manager,
          final Peer    peer )
        {
          boolean tester = true;
          newView.addTableElement(newView.currentIPs,peer.getIp() );
         
         
       
        }
       
        public void
        peerRemoved(
          PeerManager  manager,
          Peer    peer )
        {
         
        }
      }
        dm.addListener(
              new DownloadManagerListener()
            {
              public void
              downloadAdded(
                final Download  download )
View Full Code Here

   
   
   
    public void downloadListener(){
        //First we have to use a downloadManager to 'manage' all of the downloads
        final DownloadManager dm = pluginInterface.getDownloadManager();
       
       
        //this is setting up the main listener.. in the main listener, there are
        //two controls.. either downloadAdded or downloadRemoved.. at that point
        //we can pick up on a 'download' and add an additional listener to it
        //to listen for changes in its state.
        DownloadManagerListener dml = new DownloadManagerListener()
        {
            public void
            downloadAdded(
            final Download  download )
            {
              try{
                       
                        //we now have the 'download' and need to add the specific listener
                        //for change state.. a downloadListener comes with two methods that need
                        //to be addressed: stateChanged which is what we want and positionChanged
                        //which we just don't use
                        download.addListener(new DownloadListener()
                                {

                                    public void stateChanged(Download download, int old_state, int new_state) {
                                        //Statechange to look for.. we are only interested in a torrent going from
                                        //downloading (state 4) to some other state
                                        if(old_state==4){
                                            //System.out.println(download.getName() + ": old_state: " + old_state + "  new_state: " + new_state);
                                            writeFile(download.getName(),new_state);
                                        }
                                    }

                                    public void positionChanged(Download download, int oldPosition, int newPosition) {
                                        // Not used
                                       
                                    }
                           
                                });
                       
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
               
               
            }
                public void
                downloadRemoved(
                    Download    download )
                {
                //Not used   
            }
        };
   

        dm.addListener(dml);
   
}  
View Full Code Here

                            //System.out.println("Complete.. inserting now");
                            try {
                                TorrentManager torrentManager = pluginInterface.getTorrentManager()
                                try {
                         Torrent new_torrent =  torrentManager.createFromBEncodedInputStream(data);
                           DownloadManager dm = pluginInterface.getDownloadManager();
                           dm.addDownload(new_torrent);
                                } catch (TorrentException e1) {
                                   
                                    e1.printStackTrace();
                                } catch (DownloadException e2) {
                                    e2.printStackTrace();
View Full Code Here

  // back to the left.
  return (float)tmp / factor;
  }

public static void killConnectedPeers(){
  DownloadManager dm = Plugin.getPluginInterface().getDownloadManager();
  Download downloads[] = dm.getDownloads();
  if(downloads == null || downloads.length == 0) return;
  for(int i = 0; i < downloads.length ; i++){

    try{
    Peer[] peers = downloads[i].getPeerManager().getPeers();
View Full Code Here

      finally {
        if (fin!=null) try { fin.close(); } catch (IOException e) {}}
        }
       
       
        DownloadManager dm = pluginInterface.getDownloadManager();
        //final TorrentAttribute ta = pluginInterface.getTorrentManager().getAttribute(TorrentAttribute.TA_CATEGORY);
       
        dm.addListener(
            new DownloadManagerListener()
            {                   
              public void downloadAdded(Download dl) {
                if (!dl.isComplete())  //add only if the download isn't already complete
                  dl.addListener(AzCatDestDownloadListener.getInstance()); //attach DownloadListener                       
View Full Code Here

    try{

      final PluginInterface pluginInterface = Plugin.getPluginInterface();

      DownloadManager dm = pluginInterface.getDownloadManager();


      //Setting up the main listener
      final PeerManagerListener pml = new PeerManagerListener()
      {
        public void
        peerAdded(
            final PeerManager   manager,
            final Peer      peer )
        {

          IP peerIP = new IP(peer.getIp());
/*                    if(!Plugin.totalPeer_set.isPresent(peerIP)){
            TotalPeerContainer tpc = new TotalPeerContainer(peerIP,Plugin.getPluginInterface().getUtilities().getCurrentSystemTime());
            Plugin.totalPeer_set.addToMap(tpc);
          }else{
            TotalPeerContainer tpc = Plugin.totalPeer_set.getTotalPeerContainer(peerIP);
            tpc.setConnectionAttemptsPlusOne();
            tpc.setLastConnectionTime(Plugin.getPluginInterface().getUtilities().getCurrentSystemTime());
            if(tpc.rule1(peer.getPercentDoneInThousandNotation())){
              try {
                makeIPFilterRule(peer.getIp(),getPeerID(peer.getId()),peer.getClient(),manager.getDownload().getName(),"r255,g255,b255");
              } catch (DownloadException e) {
                e.printStackTrace();
              }
            }
          }
*/
          peer.addListener(new PeerListener2(){
            public void eventOccurred(PeerEvent event) {

            if(event.getType() == PeerEvent.ET_STATE_CHANGED){
              if(Plugin.areRulesPaused) return;
              if(((Integer)event.getData()).intValue() == Peer.TRANSFERING){
                try{
                  if(Plugin.getPluginInterface().getPluginconfig().getPluginBooleanParameter("Stuffer_Block_Seeder",false)){
                    System.out.println(" % done: " + peer.getPercentDoneInThousandNotation());
                    if(peer.isSeed() || peer.getPercentDoneInThousandNotation() == 1000){
                      //System.out.println(" % done: " + peer.getPercentDoneInThousandNotation());
                      String color = Plugin.getPluginInterface().getPluginconfig().getPluginStringParameter("Stuffer_Block_Seeder_Color","r255g0b0");
                      //System.out.println("Seeder Color: "  + color);
                      if(!color.equalsIgnoreCase("null")){
                        String peerID = getPeerID(peer.getId());
                        String clientName = peer.getClient();
                        // peer.setSnubbed(true);
                        makeIPFilterRule(peer.getIp(),"Seeder: " + peerID,clientName + " Seeder",manager.getDownload().getName(), color);
                        Constants.SEEDER_CLIENT_BLOCKS++;
                        Plugin.getTab2().renumberMOD_Seeder(false, true);
                      }
                    }
                  }


                  if(Plugin.getPluginInterface().getPluginconfig().getPluginBooleanParameter("Stuffer_Block_Mods",true)){
                    Pattern p = Pattern.compile("Azureus (?:[^0-2]|[^01]\\.[^0-2]|[^01]\\.[^01]\\.[^0]|[^01]\\.[^01]\\.[\\d]\\.[^0-2])");
                    Matcher m = p.matcher(peer.getClient());

                    if(m.find()){
                      //System.out.println("Inside RegEx Expression:  " + peer.getClient());
                      if(!peer.supportsMessaging()){
                        String clientName = peer.getClient();

                        System.out.println("Found MOD client " + clientName + " : " + peer.getIp() + " at " + Utils.getCurrentTime());


                        try {
                          if(manager != null){
                            String color = Plugin.getPluginInterface().getPluginconfig().getPluginStringParameter("Stuffer_Block_Mods_Color","r255g0b0");
                            //String peerID = Plugin.getPluginInterface().getUtilities().getFormatters().encodeBytesToString(peer.getId());
                            if(!color.equalsIgnoreCase("null")){
                              String peerID = getPeerID(peer.getId());
                              // peer.setSnubbed(true);
                              makeIPFilterRule(peer.getIp(),"MOD: " + peerID,clientName + " MOD",manager.getDownload().getName(), color);
                              Constants.MOD_CLIENT_BLOCKS++;
                              Plugin.getTab2().renumberMOD_Seeder(true,false);
                            }
                          }
                        } catch (DownloadException e) {
                          e.printStackTrace();
                        }
                      }
                    }
                  }
                }catch(Exception e){
                  e.printStackTrace();
                }


                try {
                  if(manager != null){
                    String clientName = peer.getClient();
                    String color = mainRuleRun(clientName,manager.isSuperSeeding(), manager.getDownload().getState());
                    if(!color.equalsIgnoreCase("null")){
                      String peerID = getPeerID(peer.getId());
                      /*String peerID;
                          try {
                            peerID = new String(peer.getId(),"ISO-8859-1");
                          } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                            peerID = "Normal Peer";
                          }*/
                      //String peerID = Plugin.getPluginInterface().getUtilities().getFormatters().encodeBytesToString(peer.getId());
                      //peer.setSnubbed(true);
                      makeIPFilterRule(peer.getIp(),peerID,clientName,manager.getDownload().getName(), color);
                    }
                  }
                } catch (DownloadException e) {
                  e.printStackTrace();
                }
              }
            }else if(event.getType() == PeerEvent.ET_BAD_CHUNK){
              System.out.println(" sentBadChunk listener has been triggered by " + peer.getIp() + " : " + peer.getClient());
              /*if(arg1 >= 1){
              System.out.println("Peer has sent a bad chunk: " + peer.getClient() + peer.getIp());
              if(Plugin.getPluginInterface().getPluginconfig().getPluginBooleanParameter("Stuffer_Block_Bad",true)){
                try {
                  String color = Plugin.getPluginInterface().getPluginconfig().getPluginStringParameter("Stuffer_Block_Bad_Color","r0g255b0");
                  if(!color.equalsIgnoreCase("null")){

                    makeIPFilterRule(peer.getIp(),"Bad Data Peer",peer.getClient(),manager.getDownload().getName(), color);
                    Constants.BAD_CLIENT_BLOCKS++;
                    Tab2Utilities.renumberMOD_BAD(false,true);
                  }
                } catch (DownloadException e) {

                  e.printStackTrace();
                }
              }
            }*/

            }












            }//End of Event Occurred

          });



        }

        public void
        peerRemoved(
            PeerManager manager,
            Peer        peer )
        {
          IP peerIP = new IP(peer.getIp());
/*                    TotalPeerContainer tpc = Plugin.totalPeer_set.getTotalPeerContainer(peerIP);
          if(tpc != null){
            tpc.setDisconnectsPlusOne();
            tpc.setPercentDone(peer.getPercentDoneInThousandNotation());
          }*/


          if(peer != null){

            if(peer.getState() != 50){
              total30++;
              System.out.println("peer: " + peer.getIp() + " State: " + peer.getState() + " Total: " + total30);

            }

          }


        }
      };
      dm.addListener(
          new DownloadManagerListener()
          {
            public void
            downloadAdded(
                final Download  download )
View Full Code Here

                      try{
                        installer.install(
                          sps.toArray( new InstallablePlugin[ sps.size()]),
                          false,
                          properties,
                          new PluginInstallationListener() {
   
                            public void
                            completed()
                            {
                            }
View Full Code Here

              final String  config_key = "recommended.processed." + rp_id;
             
              if ( !plugin_config.getPluginBooleanParameter( config_key, false )){
               
                try{
                  final PluginInstaller installer = plugin_interface.getPluginManager().getPluginInstaller();
                 
                  StandardPlugin[]  sps = installer.getStandardPlugins();
                 
                  for (int j=0;j<sps.length;j++){
                   
                    final StandardPlugin  sp = sps[j];
                   
                    if ( sp.getId().equals( rp_id )){
                   
                      found_one = true;
                     
                      checker.getCheckInstance().addListener(
                        new UpdateCheckInstanceListener()
                        {
                          public void
                          cancelled(
                            UpdateCheckInstance    instance )
                          {                         
                          }
                         
                          public void
                          complete(
                            UpdateCheckInstance    instance )
                          {
                            if ( instance.getUpdates().length == 0 ){
                             
                              installRecommendedPlugin( installer, sp );
                             
                              plugin_config.setPluginParameter( config_key, true );
                            }
                          }
                        });
                     
                      break;
                    }
                  }
                 
                }catch( Throwable e ){
                 
                }
              }
             
              if ( found_one ){
               
                break;
              }
            }
           
            if ( !found_one ){
             
              Set<String>  auto_install = vc.getAutoInstallPluginIDs();
             
              final List<String>  to_do = new ArrayList<String>();
             
              for ( String pid: auto_install ){
               
                if ( plugin_manager.getPluginInterfaceByID( pid, false ) == null ){
                 
                  to_do.add( pid );
                }
              }
             
              if ( to_do.size() > 0 ){
               
                new AEThread2( "pup:autoinst" )
                {
                  public void
                  run()
                  {   
                    try{
                      Thread.sleep( 120*1000 );
                     
                    }catch( Throwable e ){
                     
                      Debug.out( e );
                     
                      return;
                    }
                   
                    UpdateManager update_manager = plugin_interface.getUpdateManager();
                   
                    final List<UpdateCheckInstance>  l_instances = new ArrayList<UpdateCheckInstance>();
                   
                    update_manager.addListener(
                      new UpdateManagerListener()
                      {
                        public void
                        checkInstanceCreated(
                          UpdateCheckInstance  instance )
                        {
                          synchronized( l_instances ){
                           
                            l_instances.add( instance );
                          }
                        }
                      });
                   
                    UpdateCheckInstance[] instances = update_manager.getCheckInstances();
                   
                    l_instances.addAll( Arrays.asList( instances ));
                   
                    long start = SystemTime.getMonotonousTime();
                   
                    while( true ){
                     
                      if ( SystemTime.getMonotonousTime() - start >= 5*60*1000 ){
                       
                        break;
                      }
                     
                      try{
                        Thread.sleep(5000);
                       
                      }catch( Throwable e ){
                       
                        Debug.out( e );
                       
                        return;
                      }
                     
                      if ( l_instances.size() > 0 ){
                     
                        boolean  all_done = true;
                       
                        for ( UpdateCheckInstance instance: l_instances ){
                         
                          if ( !instance.isCompleteOrCancelled()){
                           
                            all_done = false;
                           
                            break;
                          }
                        }
                       
                        if ( all_done ){
                         
                          break;
                        }
                      }
                    }
                   
                    if ( update_manager.getInstallers().length > 0 ){
                     
                      return;
                    }
                   
                    PluginInstaller installer = plugin_interface.getPluginManager().getPluginInstaller();
                   
                    List<InstallablePlugin>  sps = new ArrayList<InstallablePlugin>();
                   
                    for ( String pid: to_do ){
                     
                      try{
                        StandardPlugin sp = installer.getStandardPlugin( pid );
                       
                        if ( sp != null ){
                         
                          log.log( "Auto-installing " + pid );
                         
                          sps.add( sp );
                         
                        }else{
                         
                          log.log( "Standard plugin '" + pid + "' missing" );
                        }
                      }catch( Throwable e ){
                       
                        log.log( "Standard plugin '" + pid + "' missing", e );
                      }
                    } 
                    
                    if ( sps.size() > 0 ){
                     
                      Map<Integer, Object> properties = new HashMap<Integer, Object>();
                 
                      properties.put( UpdateCheckInstance.PT_UI_STYLE, UpdateCheckInstance.PT_UI_STYLE_NONE );
                       
                      properties.put(UpdateCheckInstance.PT_UI_DISABLE_ON_SUCCESS_SLIDEY, true);
 
                      try{
                        installer.install(
                          sps.toArray( new InstallablePlugin[ sps.size()]),
                          false,
                          properties,
                          new PluginInstallationListener() {
   
View Full Code Here

                 
                  StandardPlugin[]  sps = installer.getStandardPlugins();
                 
                  for (int j=0;j<sps.length;j++){
                   
                    final StandardPlugin  sp = sps[j];
                   
                    if ( sp.getId().equals( rp_id )){
                   
                      found_one = true;
                     
                      checker.getCheckInstance().addListener(
                        new UpdateCheckInstanceListener()
                        {
                          public void
                          cancelled(
                            UpdateCheckInstance    instance )
                          {                         
                          }
                         
                          public void
                          complete(
                            UpdateCheckInstance    instance )
                          {
                            if ( instance.getUpdates().length == 0 ){
                             
                              installRecommendedPlugin( installer, sp );
                             
                              plugin_config.setPluginParameter( config_key, true );
                            }
                          }
                        });
                     
                      break;
                    }
                  }
                 
                }catch( Throwable e ){
                 
                }
              }
             
              if ( found_one ){
               
                break;
              }
            }
           
            if ( !found_one ){
             
              Set<String>  auto_install = vc.getAutoInstallPluginIDs();
             
              final List<String>  to_do = new ArrayList<String>();
             
              for ( String pid: auto_install ){
               
                if ( plugin_manager.getPluginInterfaceByID( pid, false ) == null ){
                 
                  to_do.add( pid );
                }
              }
             
              if ( to_do.size() > 0 ){
               
                new AEThread2( "pup:autoinst" )
                {
                  public void
                  run()
                  {   
                    try{
                      Thread.sleep( 120*1000 );
                     
                    }catch( Throwable e ){
                     
                      Debug.out( e );
                     
                      return;
                    }
                   
                    UpdateManager update_manager = plugin_interface.getUpdateManager();
                   
                    final List<UpdateCheckInstance>  l_instances = new ArrayList<UpdateCheckInstance>();
                   
                    update_manager.addListener(
                      new UpdateManagerListener()
                      {
                        public void
                        checkInstanceCreated(
                          UpdateCheckInstance  instance )
                        {
                          synchronized( l_instances ){
                           
                            l_instances.add( instance );
                          }
                        }
                      });
                   
                    UpdateCheckInstance[] instances = update_manager.getCheckInstances();
                   
                    l_instances.addAll( Arrays.asList( instances ));
                   
                    long start = SystemTime.getMonotonousTime();
                   
                    while( true ){
                     
                      if ( SystemTime.getMonotonousTime() - start >= 5*60*1000 ){
                       
                        break;
                      }
                     
                      try{
                        Thread.sleep(5000);
                       
                      }catch( Throwable e ){
                       
                        Debug.out( e );
                       
                        return;
                      }
                     
                      if ( l_instances.size() > 0 ){
                     
                        boolean  all_done = true;
                       
                        for ( UpdateCheckInstance instance: l_instances ){
                         
                          if ( !instance.isCompleteOrCancelled()){
                           
                            all_done = false;
                           
                            break;
                          }
                        }
                       
                        if ( all_done ){
                         
                          break;
                        }
                      }
                    }
                   
                    if ( update_manager.getInstallers().length > 0 ){
                     
                      return;
                    }
                   
                    PluginInstaller installer = plugin_interface.getPluginManager().getPluginInstaller();
                   
                    List<InstallablePlugin>  sps = new ArrayList<InstallablePlugin>();
                   
                    for ( String pid: to_do ){
                     
                      try{
                        StandardPlugin sp = installer.getStandardPlugin( pid );
                       
                        if ( sp != null ){
                         
                          log.log( "Auto-installing " + pid );
                         
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.plugins.download.DownloadManager

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.