Examples of AESemaphore


Examples of org.gudy.azureus2.core3.util.AESemaphore

  {
      // unfortunately we need this to run synchronously as the caller may be disabling it
      // and then setting speed limits in which case we can't go async and restore the
      // original values below and overwrite the new limit...
   
    final AESemaphore  sem = new AESemaphore( "SpeedManagerImpl.setEnabled" );
   
      // single thread enable/disable (and derivative reset) ops
   
    dispatcher.dispatch(
      new AERunnable()
      {
        public void
        runSupport()
        {
          try{
            setEnabledSupport( _enabled );
           
          }finally{
           
            sem.release();
          }
        }
      });
   
    if ( !sem.reserve( 10000 )){
     
      Debug.out( "operation didn't complete in time" );
    }
  }
View Full Code Here

Examples of org.gudy.azureus2.core3.util.AESemaphore

    DHTTransportContact       rendezvous,
    final DHTTransportUDPContact  target,
    Map                originator_client_data,
    boolean              no_tunnel )
  {   
    AESemaphore  wait_sem   = new AESemaphore( "DHTNatPuncher::sendPunch" );
    Object[]  wait_data   = new Object[]{ target, wait_sem, new Integer(0)};
   
    try{

      try{
        punch_mon.enter();
     
        oustanding_punches.add( wait_data );
       
      }finally{
       
        punch_mon.exit();
      }
     
      Map  request = new HashMap();
     
      request.put("type", new Long( RT_PUNCH_REQUEST ));
     
      request.put("target", target.getAddress().toString().getBytes());
     
      if ( originator_client_data != null ){
       
        if ( no_tunnel ){
         
          originator_client_data.put( "_notunnel", new Long(1));
        }
       
        request.put( "client_data", originator_client_data );
      }
 
        // for a message payload (i.e. no_tunnel) we double the initiator timeout to give
        // more chance for reasonable size messages to get through as they have to go through
        // 2 xfer processes
     
      Map response = sendRequest( rendezvous, request, no_tunnel?TRANSFER_TIMEOUT*2:TRANSFER_TIMEOUT );
     
      if ( response == null ){
       
        return( null );
      }
     
      if (((Long)response.get( "type" )).intValue() == RT_PUNCH_REPLY ){
       
        int  result = ((Long)response.get("ok")).intValue();

        trace( "received " + ( no_tunnel?"message":"punch") + " reply: " + (result==0?"failed":"ok" ));
       
        if ( result == 1 ){
         
            // pick up port changes from the rendezvous
                     
          Long  indirect_port = (Long)response.get( "port" );
         
          if ( indirect_port != null ){
           
            int transport_port  = indirect_port.intValue();
       
            if ( transport_port != 0 ){
           
              InetSocketAddress  existing_address = target.getTransportAddress();
           
              if ( transport_port != existing_address.getPort()){
             
                target.setTransportAddress(
                    new InetSocketAddress(existing_address.getAddress(), transport_port ));
              }
            }
          } 
         
          if ( !no_tunnel ){
           
              // ping the target a few times to try and establish a tunnel
                     
            UTTimerEvent  event =
              timer.addPeriodicEvent(
                  3000,
                  new UTTimerEventPerformer()
                  {
                    private int  pings = 1;
                   
                    public void
                    perform(
                      UTTimerEvent    event )
                    {
                      if ( pings > 3 ){
                       
                        event.cancel();
                     
                        return;
                      }
                   
                      pings++;
                       
                      if ( sendTunnelOutbound( target )){
                       
                        event.cancel();
                      }
                    }
                  });
             
            if ( sendTunnelOutbound( target )){
             
              event.cancel();
            }
           
              // give the other end a few seconds to kick off some tunnel events to us
           
            if ( wait_sem.reserve(10000)){
             
              event.cancel();
            }
          }
                     
View Full Code Here

Examples of org.gudy.azureus2.core3.util.AESemaphore

              }
             
              long  start    = SystemTime.getMonotonousTime();
              long  max      = MAX_REMOTE_SEARCH_MILLIS;
             
              final AESemaphore  sem = new AESemaphore( "RCM:rems" );
             
              int  sent = 0;
             
              final int[]      done = {0};
             
              for (int i=0;i<ddb_contacts.size();i++){
               
                final DistributedDatabaseContact c = ddb_contacts.get( i );
                               
                new AEThread2( "RCM:rems", true )
                {
                  public void
                  run()
                  {
                    try{
                      sendRemoteSearch( si, hashes, c, term, observer );
                                           
                    }finally{
                     
                      synchronized( done ){
                     
                        done[0]++;
                      }
                     
                      sem.release();
                    }
                  }
                }.start();
               
                sent++;
               
                synchronized( done ){
                 
                  if ( done[0] >= ddb_contacts.size() / 2 ){
                   
                    start    = SystemTime.getMonotonousTime();
                    max      = 5*1000;
                   
                    break;
                  }
                }
               
                if ( i > 10 ){
                 
                  try{
                    Thread.sleep( 250 );
                   
                  }catch( Throwable e ){
                  }
                }
              }
             
              for (int i=0;i<sent;i++){
               
                if ( done[0] > sent*4/5 ){
                 
                  break;
                }
               
                long  elapsed = SystemTime.getMonotonousTime() - start;
               
                if ( elapsed < max ){
                 
                  sem.reserve( max - elapsed );
                 
                }else{
                 
                  break;
                }
View Full Code Here

Examples of org.gudy.azureus2.core3.util.AESemaphore

      long    offset,
      int      length )
   
      throws IOException
    {
      AESemaphore  sem;
     
      synchronized( lock ){
       
        if ( raf.length() > offset ){
         
          raf.seek( offset );
         
          return( raf.read( buffer, 0, length ));
       
       
        if ( stream_details == null ){
         
          if ( stream_got_eof ){
           
            return( -1 );
          }
         
          throw( new IOException( "Premature end of stream (read)" ));
        }
       
        sem = new AESemaphore( "DMS:block" );
       
        waiters.add( sem );
      }
     
      try{
        sem.reserve( 1000 );
     
      }finally{
     
        synchronized( lock ){
View Full Code Here

Examples of org.gudy.azureus2.core3.util.AESemaphore

            if ( user_agent != null ){
           
              current_request.setUserAgent( user_agent );
            }
           
            final AESemaphore  sem = new AESemaphore( "waiter" );
            final Throwable[]  error = {null};
           
            current_request.addListener(
              new DiskManagerListener()
              {
                private int write_pos   = pos;
                private int  rem      = len;
               
                public void
                eventOccurred(
                  DiskManagerEvent  event )
                {
                  int  type = event.getType();
                 
                  if ( type == DiskManagerEvent.EVENT_TYPE_SUCCESS ){
                   
                    PooledByteBuffer p_buffer = event.getBuffer();
                   
                    try{
                      ByteBuffer  bb = p_buffer.toByteBuffer();
                                         
                      bb.position( 0 );
                     
                      int  read = bb.remaining();

                      bb.get( buffer, write_pos, read );
                     
                      write_pos   += read;
                      rem      -= read;
                     
                      if ( rem == 0 ){
                       
                        sem.release();
                      }
                    }finally{
                     
                      p_buffer.returnToPool();
                    }
                  }else if ( type == DiskManagerEvent.EVENT_TYPE_FAILED ){
                 
                    error[0] = event.getFailure();
                   
                    sem.release();
                  }
                }
              });
           
            current_request.run();
           
            while( true ){
             
              if ( sem.reserve( 1000 )){
               
                if ( error[0] != null ){
                 
                  throw( new IOException( Debug.getNestedExceptionMessage( error[0] )));
                }
View Full Code Here

Examples of org.gudy.azureus2.core3.util.AESemaphore

  {
    final UIManager ui_manager = PluginInitializer.getDefaultInterface().getUIManager();
   
    if ( ui_manager.getUIInstances().length == 0 ){
     
      final AESemaphore sem = new AESemaphore( "waitforui") ;
    
      ui_manager.addUIListener(
          new UIManagerListener()
          {
            public void
            UIAttached(
              UIInstance    instance )
            {
              ui_manager.removeUIListener( this );
             
              sem.releaseForever();
            }
           
            public void
            UIDetached(
              UIInstance    instance )
            {
            }
          });
     
        // UIAttached is only fired once initialisation is complete. However, the instance
        // can be made available prior to this and there is a case where this event is blocking
        // the firing of the completion event. therefore pick it up if present directly
     
      long  time_to_go = millis_to_wait_for_attach;
     
      while( ui_manager.getUIInstances().length == 0 ){
       
        if ( sem.reserve( 1000 )){
         
          break;
        }
       
        time_to_go -= 1000;
View Full Code Here

Examples of org.gudy.azureus2.core3.util.AESemaphore

    if ( display.isDisposed()){
     
      return( null );
    }
   
    final AESemaphore  sem = new AESemaphore("NetworkClassifier");
   
    final classifierDialog[]  dialog = new classifierDialog[1];
   
    try{
      Utils.execSWTThread(
        new AERunnable()
        {
          public void
          runSupport()
          {
            dialog[0] = new classifierDialog( sem, display, description, tracker_networks );
          }
        });
    }catch( Throwable e ){
     
      Debug.printStackTrace( e );
     
      return( null );
    }
   
    sem.reserve();
   
    return( dialog[0].getSelection());
  }
View Full Code Here

Examples of org.gudy.azureus2.core3.util.AESemaphore

    byte[]    hash )
  {
    final int[]  seeds     = {0};
    final int[] leechers   = {0};
   
    final AESemaphore  sem = new AESemaphore( "DHTTrackerPlugin:scrape" );
   
    dht.get(hash,
        "Scrape for '" + ByteFormatter.nicePrint( hash ) + "'",
        DHTPlugin.FLAG_DOWNLOADING,
        NUM_WANT,
        SCRAPE_TIMEOUT,
        false, false,
        new DHTPluginOperationListener()
        {
          public void
          diversified()
          {
          }
         
          public void
          starts(
            byte[]         key )
          {
          }
         
          public void
          valueRead(
            DHTPluginContact  originator,
            DHTPluginValue    value )
          {           
            if (( value.getFlags() & DHTPlugin.FLAG_DOWNLOADING ) == 1 ){
             
              leechers[0]++;
             
            }else{
             
              seeds[0]++;
            }
          }
         
          public void
          valueWritten(
            DHTPluginContact  target,
            DHTPluginValue    value )
          {
          }

          public void
          complete(
            byte[]  key,
            boolean  timeout_occurred )
          {
            sem.release();
          }
        });

    sem.reserve();
   
    return(
        new DownloadScrapeResult()
        {
          public Download
View Full Code Here

Examples of org.gudy.azureus2.core3.util.AESemaphore

 
      properties.put( UpdateCheckInstance.PT_UI_STYLE, UpdateCheckInstance.PT_UI_STYLE_NONE );
       
      properties.put(UpdateCheckInstance.PT_UI_DISABLE_ON_SUCCESS_SLIDEY, true);

      final AESemaphore sem = new AESemaphore("emp install");
      final boolean[] result = new boolean[1];
   
      instance =
        installer.install(
          new InstallablePlugin[]{ sp },
          false,
          properties,
          new PluginInstallationListener() {

            public void
            completed()
            {
              result[0] = true;
              if(listener != null) {
                listener.finished();
              }
              sem.release();
            }
           
            public void
            cancelled()
            {
              result[0] = false;
              if(listener != null) {
                listener.finished();
              }
              sem.release();
            }
           
            public void
            failed(
              PluginException  e )
            {
              result[0] = false;
              if(listener != null) {
                listener.finished();
              }
              sem.release();
            }
          });
   
      boolean kill_it;
     
      synchronized( this ){
       
        kill_it = cancelled;
      }

      if ( kill_it ){
       
        instance.cancel();
       
        return( false );
      }
     
      instance.addListener(
        new UpdateCheckInstanceListener() {

          public void
          cancelled(
            UpdateCheckInstance    instance )
          {             
          }
         
          public void
          complete(
            UpdateCheckInstance    instance )
          {
              Update[] updates = instance.getUpdates();
            
             for ( final Update update: updates ){
              
               ResourceDownloader[] rds = update.getDownloaders();
            
               for ( ResourceDownloader rd: rds ){
                
                 rd.addListener(
                   new ResourceDownloaderAdapter()
                   {
                     public void
                     reportActivity(
                       ResourceDownloader  downloader,
                       String        activity )
                     {
                      
                     }
                    
                     public void
                     reportPercentComplete(
                       ResourceDownloader  downloader,
                       int          percentage )
                     {
                       if(listener != null) {
                         listener.progress(percentage);
                       }
                     }
                   });
               }
             }
          }
        });
         
      sem.reserve();
     
      return result[0];
     
    }catch( Throwable e ){
     
View Full Code Here

Examples of org.gudy.azureus2.core3.util.AESemaphore

    final boolean  end_of_day )
  {
      // problems here at end of day regarding devices that hang and cause AZ to hang around
      // got ages before terminating
   
    final AESemaphore sem = new AESemaphore( "UPnPPlugin:closeTimeout" );
   
     
    new AEThread( "UPnPPlugin:closeTimeout" , true )
    {
      public void
      runSupport()
      {
        try{
          for (int i=0;i<mappings.size();i++){
           
            UPnPMapping  mapping = (UPnPMapping)mappings.get(i);
           
            if ( !mapping.isEnabled()){
             
              continue;
            }
           
            for (int j=0;j<services.size();j++){
             
              UPnPPluginService  service = (UPnPPluginService)services.get(j);
             
              service.removeMapping( log, mapping, end_of_day );
            }
          }
        }finally{
         
          sem.release();
        }
      }
    }.start();
 
 
    if ( !sem.reserve( end_of_day?15*1000:0 )){
   
      String  msg = "A UPnP device is taking a long time to release its port mappings, consider disabling this via the UPnP configuration.";

      if ( upnp_log_listener != null ){
       
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.