FileDocCategorySizeDatePackage
TestPingSourceImpl.javaAPI DocAzureus 3.0.3.45002Wed Aug 08 09:41:18 BST 2007com.aelitis.azureus.core.speedmanager.impl

TestPingSourceImpl

public abstract class TestPingSourceImpl extends Object implements com.aelitis.azureus.core.dht.speed.DHTSpeedTester

Fields Summary
private SpeedManagerAlgorithmProviderAdapter
adapter
private volatile int
contact_num
private List
listeners
private com.aelitis.azureus.core.util.CopyOnWriteList
sources
private int
period
Constructors Summary
protected TestPingSourceImpl(SpeedManagerAlgorithmProviderAdapter _adapter)

	
	
	
				 
	
		adapter	= _adapter;
		
		SimpleTimer.addPeriodicEvent(
			"TestPingSourceImpl",
			1000,
			new TimerEventPerformer()
			{
				private int	ticks;
				
				public void 
				perform(
					TimerEvent event ) 
				{
					ticks++;
					
					List	sources_to_update;
					
					synchronized( sources ){

						while( sources.size() < contact_num ){
							
							addContact( new testSource());
						}
						
						sources_to_update = sources.getList();
					}
					
					if ( period > 0 ){
						
						if ( ticks % period == 0 ){
							
							testSource[]	contacts = new testSource[sources_to_update.size()];
							
							sources_to_update.toArray( contacts );

							update( contacts );
						}
					}
				}
			});
	
Methods Summary
protected voidaddContact(com.aelitis.azureus.core.speedmanager.impl.TestPingSourceImpl$testSource contact)

		synchronized( sources ){
			
			sources.add( contact );
		}
		
		for (int i=0;i<listeners.size();i++){
			
			((DHTSpeedTesterListener)listeners.get(i)).contactAdded(contact);
		}
	
public voidaddListener(com.aelitis.azureus.core.dht.speed.DHTSpeedTesterListener listener)

		listeners.add( listener );
	
protected SpeedManagerAlgorithmProviderAdaptergetAdapter()

		return( adapter );
	
public intgetContactNumber()

		return( contact_num );
	
protected voidremoveContact(com.aelitis.azureus.core.speedmanager.impl.TestPingSourceImpl$testSource contact)

		synchronized( sources ){
			
			sources.remove( contact );
		}
	
public voidremoveListener(com.aelitis.azureus.core.dht.speed.DHTSpeedTesterListener listener)

		listeners.remove( listener );
	
public voidsetContactNumber(int number)

		contact_num = number;
	
protected voidupdate(com.aelitis.azureus.core.speedmanager.impl.TestPingSourceImpl$testSource[] contacts)

		int[]	round_trip_times = new int[contacts.length];

		updateSources( contacts );
	
		for (int i=0;i<round_trip_times.length;i++){
			
			round_trip_times[i] = contacts[i].getRTT();
		}
		
		for (int i=0;i<listeners.size();i++){
			
			((DHTSpeedTesterListener)listeners.get(i)).resultGroup( contacts, round_trip_times );
		}
	
protected abstract voidupdateSources(com.aelitis.azureus.core.speedmanager.impl.TestPingSourceImpl$testSource[] sources)