Fields Summary |
---|
protected static final int | UPDATE_PERIOD_MILLIS |
private static final int | CONTACT_NUMBER |
private static final int | CONTACT_PING_SECS |
private static final int | LONG_PERIOD_SECS |
private static final int | LONG_PERIOD_TICKS |
private static final int | SHORT_ESTIMATE_SECS |
private static final int | MEDIUM_ESTIMATE_SECS |
static final int | SHORT_ESTIMATE_SAMPLES |
static final int | MEDIUM_ESTIMATE_SAMPLES |
private static final int | SAVE_PERIOD_SECS |
private static final int | SAVE_PERIOD_TICKS |
private static final int | SPEED_AVERAGE_PERIOD |
private static boolean | DEBUG |
public static final String | CONFIG_VERSION_STR |
public static final String | CONFIG_VERSION |
private static final String | CONFIG_AVAIL |
private static final String | CONFIG_DEBUG |
private static final String[] | CONFIG_PARAMS |
private static boolean | emulated_ping_source |
private com.aelitis.azureus.core.AzureusCore | core |
private com.aelitis.azureus.core.dht.speed.DHTSpeedTester | speed_tester |
private com.aelitis.azureus.core.speedmanager.SpeedManagerAdapter | adapter |
private SpeedManagerAlgorithmProvider | provider |
private int | provider_version |
private boolean | enabled |
private Map | contacts |
private volatile int | total_contacts |
private pingContact[] | contacts_array |
private Object | original_limits |
private org.gudy.azureus2.core3.util.AsyncDispatcher | dispatcher |
private SpeedManagerPingMapperImpl | ping_mapper |
private SpeedManagerPingMapperImpl[] | ping_mappers |
private com.aelitis.azureus.core.util.CopyOnWriteList | transient_mappers |
private org.gudy.azureus2.core3.util.AEDiagnosticsLogger | logger |
private String | asn |
private com.aelitis.azureus.core.util.CopyOnWriteList | listeners |
Methods Summary |
---|
public void | addListener(com.aelitis.azureus.core.speedmanager.SpeedManagerListener l)
listeners.add( l );
|
protected void | addPingHistory(int rtt, boolean re_base)
int x = (adapter.getCurrentDataUploadSpeed(SPEED_AVERAGE_PERIOD) + adapter.getCurrentProtocolUploadSpeed(SPEED_AVERAGE_PERIOD));
int y = (adapter.getCurrentDataDownloadSpeed(SPEED_AVERAGE_PERIOD) + adapter.getCurrentProtocolDownloadSpeed(SPEED_AVERAGE_PERIOD));
for (int i=0;i<ping_mappers.length;i++){
ping_mappers[i].addPing( x, y, rtt, re_base );
}
Iterator it = transient_mappers.iterator();
while( it.hasNext()){
((SpeedManagerPingMapperImpl)it.next()).addPing( x, y, rtt, re_base );
}
|
public com.aelitis.azureus.core.speedmanager.SpeedManagerPingMapper | createTransientPingMapper()
SpeedManagerPingMapper res = new SpeedManagerPingMapperImpl( this, "Transient", LONG_PERIOD_TICKS, true, true );
transient_mappers.add( res );
if ( transient_mappers.size() > 32 ){
Debug.out( "Transient mappers are growing too large" );
}
return( res );
|
protected void | destroy(com.aelitis.azureus.core.speedmanager.SpeedManagerPingMapper mapper)
transient_mappers.remove( mapper );
|
protected void | enableOrAlgChanged()
total_contacts = 0;
SpeedManagerAlgorithmProvider old_provider = provider;
if ( provider_version == 1 ){
if ( !( provider instanceof SpeedManagerAlgorithmProviderV1 )){
provider = new SpeedManagerAlgorithmProviderV1( this );
}
}else if ( provider_version == 2 ){
if ( !( provider instanceof SpeedManagerAlgorithmProviderV2 )){
provider = new SpeedManagerAlgorithmProviderV2( this );
}
}else if ( provider_version == 3 ){
provider = new SpeedManagerAlgorithmProviderV2( this );
}else{
Debug.out( "Unknown provider version " + provider_version );
if ( !( provider instanceof nullProvider )){
provider = new nullProvider();
}
}
if ( old_provider != provider ){
log( "Algorithm set to " + provider.getClass().getName());
}
if ( old_provider != null ){
old_provider.destroy();
}
provider.reset();
|
public void | generate(org.gudy.azureus2.core3.util.IndentWriter writer)
writer.println( "SpeedManager: enabled=" + enabled + ",provider=" + provider );
try{
writer.indent();
ping_mapper.generateEvidence( writer );
}finally{
writer.exdent();
}
|
public java.lang.String | getASN()
return( asn );
|
public com.aelitis.azureus.core.speedmanager.SpeedManagerPingMapper | getActiveMapper()
return( ping_mapper );
|
public int | getCurrentChokeSpeed()Returns the current view of when choking occurs
return( provider.getCurrentChokeSpeed());
|
public int | getCurrentDataDownloadSpeed()
return( adapter.getCurrentDataDownloadSpeed(-1) );
|
public int | getCurrentDataUploadSpeed()
return( adapter.getCurrentDataUploadSpeed(-1));
|
public int | getCurrentDownloadLimit()
return( adapter.getCurrentDownloadLimit());
|
public int | getCurrentPingMillis()
return( provider.getCurrentPingMillis());
|
public int | getCurrentProtocolDownloadSpeed()
return( adapter.getCurrentProtocolDownloadSpeed(-1) );
|
public int | getCurrentProtocolUploadSpeed()
return( adapter.getCurrentProtocolUploadSpeed(-1));
|
public int | getCurrentUploadLimit()
return( adapter.getCurrentUploadLimit());
|
public com.aelitis.azureus.core.speedmanager.SpeedManagerLimitEstimate | getEstimatedDownloadCapacityBytesPerSec()
return( ping_mapper.getEstimatedDownloadCapacityBytesPerSec());
|
public com.aelitis.azureus.core.speedmanager.SpeedManagerLimitEstimate | getEstimatedUploadCapacityBytesPerSec()
return( ping_mapper.getEstimatedUploadCapacityBytesPerSec());
|
public int | getIdlePingMillis()
return( provider.getIdlePingMillis());
|
public com.aelitis.azureus.core.speedmanager.SpeedManagerPingMapper[] | getMappers()
return( ping_mappers );
|
public int | getMaxPingMillis()
return( provider.getMaxPingMillis());
|
public int | getMaxUploadSpeed()
return( provider.getMaxUploadSpeed());
|
public com.aelitis.azureus.core.speedmanager.SpeedManagerPingMapper | getPingMapper()
return( getActiveMapper());
|
public com.aelitis.azureus.core.speedmanager.SpeedManagerPingSource[] | getPingSources()
return( contacts_array );
|
public com.aelitis.azureus.core.speedmanager.SpeedManager | getSpeedManager()
return( this );
|
public com.aelitis.azureus.core.dht.speed.DHTSpeedTester | getSpeedTester()
return( speed_tester );
|
protected void | informDownCapChanged()
informListeners( SpeedManagerListener.PR_DOWN_CAPACITY );
|
protected void | informListeners(int type)
Iterator it = listeners.iterator();
while( it.hasNext()){
try{
((SpeedManagerListener)it.next()).propertyChanged( type );
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
|
protected void | informUpCapChanged()
informListeners( SpeedManagerListener.PR_UP_CAPACITY );
|
public boolean | isAvailable()
return( speed_tester != null );
|
public boolean | isEnabled()
return( enabled );
|
public void | log(java.lang.String str)
logger.log( str );
|
public void | removeListener(com.aelitis.azureus.core.speedmanager.SpeedManagerListener l)
listeners.remove( l );
|
public void | reset()
ping_mapper.reset();
|
public void | setCurrentDownloadLimit(int bytes_per_second)
if ( enabled ){
adapter.setCurrentDownloadLimit( bytes_per_second );
}
|
public void | setCurrentUploadLimit(int bytes_per_second)
if ( enabled ){
adapter.setCurrentUploadLimit( bytes_per_second );
}
|
public void | setEnabled(boolean _enabled)
// 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" );
}
|
protected void | setEnabledSupport(boolean _enabled)
if ( enabled != _enabled ){
log( "Enabled set to " + _enabled );
if ( _enabled ){
original_limits = adapter.getLimits();
}else{
ping_mapper.saveHistory();
}
enableOrAlgChanged();
enabled = _enabled;
if ( speed_tester != null ){
speed_tester.setContactNumber( enabled?CONTACT_NUMBER:0);
}
if ( !enabled ){
adapter.setLimits( original_limits, true, provider.getAdjustsDownloadLimits());
}
}
|
public void | setEstimatedDownloadCapacityBytesPerSec(int bytes_per_sec, float metric)
ping_mapper.setEstimatedDownloadCapacityBytesPerSec( bytes_per_sec, metric );
|
public void | setEstimatedUploadCapacityBytesPerSec(int bytes_per_sec, float metric)
ping_mapper.setEstimatedUploadCapacityBytesPerSec( bytes_per_sec, metric );
|
public void | setLoggingEnabled(boolean enabled)
COConfigurationManager.setParameter( CONFIG_DEBUG, enabled );
|
public void | setSpeedTester(com.aelitis.azureus.core.dht.speed.DHTSpeedTester _tester)
if ( speed_tester != null ){
if ( !emulated_ping_source ){
Debug.out( "speed tester already set!" );
}
return;
}
COConfigurationManager.setParameter( CONFIG_AVAIL, true );
speed_tester = _tester;
speed_tester.addListener(
new DHTSpeedTesterListener()
{
private DHTSpeedTesterContact[] last_contact_group = new DHTSpeedTesterContact[0];
public void
contactAdded(
DHTSpeedTesterContact contact )
{
if ( core.getInstanceManager().isLANAddress(contact.getAddress().getAddress())){
contact.destroy();
}else{
log( "activePing: " + contact.getString());
contact.setPingPeriod( CONTACT_PING_SECS );
synchronized( contacts ){
pingContact source = new pingContact( contact );
contacts.put( contact, source );
contacts_array = new pingContact[ contacts.size() ];
contacts.values().toArray( contacts_array );
total_contacts++;
provider.pingSourceFound( source, total_contacts > CONTACT_NUMBER );
}
contact.addListener(
new DHTSpeedTesterContactListener()
{
public void
ping(
DHTSpeedTesterContact contact,
int round_trip_time )
{
}
public void
pingFailed(
DHTSpeedTesterContact contact )
{
}
public void
contactDied(
DHTSpeedTesterContact contact )
{
log( "deadPing: " + contact.getString());
synchronized( contacts ){
pingContact source = (pingContact)contacts.remove( contact );
if ( source != null ){
contacts_array = new pingContact[ contacts.size() ];
contacts.values().toArray( contacts_array );
provider.pingSourceFailed( source );
}
}
}
});
}
}
public void
resultGroup(
DHTSpeedTesterContact[] st_contacts,
int[] round_trip_times )
{
if ( !enabled ){
for (int i=0;i<st_contacts.length;i++){
st_contacts[i].destroy();
}
return;
}
boolean sources_changed = false;
for (int i=0;i<st_contacts.length;i++){
boolean found = false;
for (int j=0;j<last_contact_group.length;j++){
if ( st_contacts[i] == last_contact_group[j] ){
found = true;
break;
}
}
if ( !found ){
sources_changed = true;
break;
}
}
last_contact_group = st_contacts;
pingContact[] sources = new pingContact[st_contacts.length];
boolean miss = false;
int worst_value = -1;
int num_values = 0;
int total = 0;
synchronized( contacts ){
for (int i=0;i<st_contacts.length;i++){
pingContact source = sources[i] = (pingContact)contacts.get( st_contacts[i] );
if ( source != null ){
int rtt = round_trip_times[i];
if ( rtt > 0 ){
if ( rtt > worst_value ){
worst_value = rtt;
}
num_values++;
total += rtt;
}
source.setPingTime( rtt );
}else{
miss = true;
}
}
}
if ( miss ){
Debug.out( "Auto-speed: source missing" );
}else{
provider.calculate( sources );
// remove worst value if we have > 1
if ( num_values > 1 ){
total -= worst_value;
num_values--;
}
if ( num_values> 0 ){
addPingHistory( total/num_values, sources_changed );
}
}
}
});
SimpleTimer.addPeriodicEvent(
"SpeedManager:stats",
SpeedManagerAlgorithmProvider.UPDATE_PERIOD_MILLIS,
new TimerEventPerformer()
{
public void
perform(
TimerEvent event )
{
if ( enabled ){
provider.updateStats();
}
}
});
|