Package org.gudy.azureus2.core3.util

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


  MonitorImpl(
    PluginInterface    pi )
  {
    synchronized( MonitorImpl.class ){

      mon = new AEMonitor("Plugin " + pi.getPluginID() + ":" + next_mon_id++ );
    }
  }
View Full Code Here


    final long            max_queue_size )
  {
    return(
      new AggregatedList()
      {
        AEMonitor  timer_mon  = new AEMonitor( "aggregatedList" );
       
        Timer    timer = new Timer( "AggregatedList" );
        TimerEvent  event;
       
        List    list  = new ArrayList();
       
        public void
        add(
          Object  obj )
        {
         
          List  dispatch_now = null;
         
          try{
            timer_mon.enter();
           
              // if the list is full kick off a dispatch and reset the list
           
            if max_queue_size > 0 &&
                max_queue_size  == list.size()){
             
              dispatch_now = list;
             
              list  = new ArrayList();
             
            }
             
            list.add( obj );
           
              // set up a timer to wakeup in required time period
           
            long  now = SystemTime.getCurrentTime();
         
            if ( event != null ){
             
              event.cancel();
            }
           
            event =
              timer.addEvent(
                  now + idle_dispatch_time,
                  new TimerEventPerformer()
                  {
                    public void
                    perform(
                      TimerEvent  event )
                    {
                      dispatch();
                    }
                  });
          }finally{
           
            timer_mon.exit();
          }
         
          if ( dispatch_now != null ){
           
            dispatch( dispatch_now );
          }
        }

        public Object
        remove(
          Object  obj )
        {
          Object  res = null;
         
          try{
            timer_mon.enter();
         
            res = list.remove( obj )?obj:null;
             
            if ( res != null ){
             
              long  now = SystemTime.getCurrentTime();
             
              if ( event != null ){
               
                event.cancel();
              }
               
              if ( list.size() == 0 ){
               
                event  = null;
               
              }else{
               
                event =
                  timer.addEvent(
                      now + idle_dispatch_time,
                      new TimerEventPerformer()
                      {
                        public void
                        perform(
                          TimerEvent  event )
                        {
                          dispatch();
                        }
                      });
              }
            }
          }finally{
           
            timer_mon.exit();
          }
         
          return( res );
        }
       
        protected void
        dispatch()
        {
          List  dispatch_list;
         
          try{
            timer_mon.enter();
         
            dispatch_list  = list;
           
            list  = new ArrayList();
           
          }finally{
           
            timer_mon.exit();
          }
         
          dispatch( dispatch_list );
        }
View Full Code Here

   */
  public TransferProcessor( int processor_type, LimitedRateGroup max_rate_limit, boolean multi_threaded ) {
    this.max_rate     = max_rate_limit;
    this.multi_threaded  = multi_threaded;
   
    connections_mon = new AEMonitor( "TransferProcessor:" +processor_type );

    main_bucket = createBucket( max_rate.getRateLimitBytesPerSecond() );

    main_rate_handler =
      new RateHandler() {
View Full Code Here

     
      final DistributedDatabase db = plugin_interface.getDistributedDatabase();
     
      final List      potential_contacts     = new ArrayList();
      final AESemaphore  potential_contacts_sem   = new AESemaphore( "MagnetPlugin:liveones" );
      final AEMonitor    potential_contacts_mon  = new AEMonitor( "MagnetPlugin:liveones" );
     
      final int[]      outstanding    = {0};
      final boolean[]    lookup_complete  = {false};
     
      listener.reportActivitygetMessageText( "report.searching" ));
     
      DistributedDatabaseListener  ddb_listener =
        new DistributedDatabaseListener()
        {
          private Set  found_set = new HashSet();
         
          public void
          event(
            DistributedDatabaseEvent     event )
          {
            int  type = event.getType();
 
            if ( type == DistributedDatabaseEvent.ET_OPERATION_STARTS ){

                // give live results a chance before kicking in explicit ones
             
              if ( sources.length > 0 ){
               
                new DelayedEvent(
                  "MP:sourceAdd",
                  10*1000,
                  new AERunnable()
                  {
                    public void
                    runSupport()
                    {
                      addExplicitSources();
                    }
                  });
              }
             
            }else if ( type == DistributedDatabaseEvent.ET_VALUE_READ ){
                         
              contactFound( event.getValue().getContact());
     
            }else if type == DistributedDatabaseEvent.ET_OPERATION_COMPLETE ||
                  type == DistributedDatabaseEvent.ET_OPERATION_TIMEOUT ){
               
              listener.reportActivity( getMessageText( "report.found", String.valueOf( found_set.size())));
             
                // now inject any explicit sources

              addExplicitSources();
             
              try{
                potential_contacts_mon.enter();                         

                lookup_complete[0] = true;
               
              }finally{
               
                potential_contacts_mon.exit();
              }
             
              potential_contacts_sem.release();
            }
          }
         
          protected void
          addExplicitSources()
          { 
            for (int i=0;i<sources.length;i++){
             
              try{
                contactFound( db.importContact(sources[i]));
               
              }catch( Throwable e ){
               
                Debug.printStackTrace(e);
              }
            }
          }
         
          public void
          contactFound(
            final DistributedDatabaseContact  contact )
          {
            String  key = contact.getAddress().toString();
           
            synchronized( found_set ){
             
              if ( found_set.contains( key )){
               
                return;
              }
             
              found_set.add( key );
            }
           
            if ( listener.verbose()){
           
              listener.reportActivity( getMessageText( "report.found", contact.getName()));
            }
           
            try{
              potential_contacts_mon.enter();                         

              outstanding[0]++;
             
            }finally{
             
              potential_contacts_mon.exit();
            }
           
            contact.isAlive(
              20*1000,
              new DistributedDatabaseListener()
              {
                public void
                event(
                  DistributedDatabaseEvent event)
                {
                  try{
                    boolean  alive = event.getType() == DistributedDatabaseEvent.ET_OPERATION_COMPLETE;
                     
                    if ( listener.verbose()){
                   
                      listener.reportActivity(
                        getMessageText( alive?"report.alive":"report.dead",  contact.getName()));
                    }
                   
                    try{
                      potential_contacts_mon.enter();
                     
                      Object[]  entry = new Object[]{ new Boolean( alive ), contact};
                     
                      boolean  added = false;
                     
                      if ( alive ){
                       
                          // try and place before first dead entry
                   
                        for (int i=0;i<potential_contacts.size();i++){
                         
                          if (!((Boolean)((Object[])potential_contacts.get(i))[0]).booleanValue()){
                           
                            potential_contacts.add(i, entry );
                           
                            added = true;
                           
                            break;
                          }
                        }
                      }
                     
                      if ( !added ){
                       
                        potential_contacts.add( entry )// dead at end
                      }
                       
                    }finally{
                       
                      potential_contacts_mon.exit();
                    }
                  }finally{
                   
                    try{
                      potential_contacts_mon.enter();                         

                      outstanding[0]--;
                     
                    }finally{
                     
                      potential_contacts_mon.exit();
                    }
                   
                    potential_contacts_sem.release();
                  }
                }
              });
          }
        };
       
      db.read(
        ddb_listener,
        db.createKey( hash, "Torrent download lookup for '" + ByteFormatter.encodeString( hash ) + "'" ),
        timeout,
        DistributedDatabase.OP_EXHAUSTIVE_READ | DistributedDatabase.OP_PRIORITY_HIGH );
     
      long  remaining  = timeout;
     
      long   overall_start       = SystemTime.getMonotonousTime();
      boolean  sl_enabled        = secondary_lookup.getValue() && FeatureAvailability.isMagnetSLEnabled();

      long  secondary_lookup_time   = -1;
     
      long last_found = -1;
     
      final Object[] secondary_result = { null };
     
      while( remaining > 0 ){
         
        try{
          potential_contacts_mon.enter();

          if (   lookup_complete[0] &&
              potential_contacts.size() == 0 &&
              outstanding[0] == 0 ){
           
            break;
          }
        }finally{
         
          potential_contacts_mon.exit();
        }
               
       
        while( remaining > 0 ){
       
          long wait_start = SystemTime.getMonotonousTime();

          boolean got_sem = potential_contacts_sem.reserve( 1000 );
   
          long now = SystemTime.getMonotonousTime();
         
          remaining -= ( now - wait_start );
       
          if ( got_sem ){
         
            last_found = now;
           
            break;
           
          }else{
           
            if ( sl_enabled ){
             
              if ( secondary_lookup_time == -1 ){
             
                long  base_time;
               
                if ( last_found == -1 || now - overall_start > 60*1000 ){
                 
                  base_time = overall_start;
                 
                }else{
                 
                  base_time = last_found;
                }
               
                long  time_so_far = now - base_time;
               
                if ( time_so_far > SECONDARY_LOOKUP_DELAY ){
                 
                  secondary_lookup_time = SystemTime.getMonotonousTime();
                 
                  doSecondaryLookup( listener, secondary_result, hash, args );
                }
              }else{
               
                try{
                  byte[] torrent = getSecondaryLookupResult( secondary_result );
                 
                  if ( torrent != null ){
                   
                    return( torrent );
                  }
                }catch( ResourceDownloaderException e ){
                 
                  // ignore, we just continue processing
                }
              }
            }

            continue;
          }
        }
       
        DistributedDatabaseContact  contact;
        boolean            live_contact;
       
        try{
          potential_contacts_mon.enter();
         
          // System.out.println( "rem=" + remaining + ",pot=" + potential_contacts.size() + ",out=" + outstanding[0] );
         
          if ( potential_contacts.size() == 0 ){
           
            if ( outstanding[0] == 0 ){
           
              break;
             
            }else{
             
              continue;
            }
          }else{
         
            Object[]  entry = (Object[])potential_contacts.remove(0);
           
            live_contact   = ((Boolean)entry[0]).booleanValue();
            contact     = (DistributedDatabaseContact)entry[1];
          }
         
        }finally{
         
          potential_contacts_mon.exit();
        }
         
        // System.out.println( "magnetDownload: " + contact.getName() + ", live = " + live_contact );
       
        if ( !live_contact ){
View Full Code Here

    port      = _port;
    timeout_secs  = _timeout_secs;
    public_key    = _key;
    adapter      = _adapter;
       
    message_mon  = new AEMonitor( "SecureService:messages" );
   
    message_sem = new AESemaphore( "SecureService:messages" );
   
    new AEThread( "SecureService::messageSender", true )
    {
View Full Code Here

      Logger.log(new LogEvent(LOGID, "***************** SAFE SOCKET SELECTOR MODE ENABLED *****************"));
    }
   
    selector_impl = null;
    selectors = new HashMap<VirtualChannelSelectorImpl,ArrayList<AbstractSelectableChannel>>();
    selectors_mon = new AEMonitor( "VirtualChannelSelector:FM" );
    selectors.put( new VirtualChannelSelectorImpl( this, op, pause, randomise_keys ), new ArrayList<AbstractSelectableChannel>() );
    selectors_keyset_cow = new HashSet<VirtualChannelSelectorImpl>( selectors.keySet());
  }
View Full Code Here

    }
   
    final trustDialog[]  dialog = new trustDialog[1];
   
    try{
      Utils.execSWTThread(new AERunnable() {
            public void
            runSupport()
            {
              dialog[0] = new trustDialog( display, resource, cert );
            }
View Full Code Here

      return;
    }
   
    try{
      display.asyncExec(
          new AERunnable()
          {
            public void
            runSupport()
            {
               new createDialog( display );
View Full Code Here

    if (logAlert.details != null) {
      text += "\n<A HREF=\"details\">" + MessageText.getString("v3.MainWindow.button.viewdetails") + "</A>";
    }

    Utils.execSWTThread(new AERunnable() {
      public void runSupport() {
        openWindow();
      }
    });
  }
View Full Code Here

  /* (non-Javadoc)
   * @see org.eclipse.ui.IStartup#earlyStartup()
   */
  public void earlyStartup() {
    final Display display = Display.getDefault();
    display.syncExec(new AERunnable() {
      public void runSupport() {
        hookApplicationMenu(display);
      }
    });
  }
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.core3.util.AEMonitor

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.