FileDocCategorySizeDatePackage
TransferSpeedValidator.javaAPI DocAzureus 3.0.3.47091Fri Jun 08 12:08:42 BST 2007org.gudy.azureus2.core3.config.impl

TransferSpeedValidator

public final class TransferSpeedValidator extends Object
Provides validation for transfer speed settings
version
1.0
since
1.4
author
James Yeh

Fields Summary
public static final String
AUTO_UPLOAD_ENABLED_CONFIGKEY
public static final String
AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY
public static final String
UPLOAD_CONFIGKEY
public static final String
UPLOAD_SEEDING_CONFIGKEY
public static final String
DOWNLOAD_CONFIGKEY
public static final String
UPLOAD_SEEDING_ENABLED_CONFIGKEY
public static final String[]
CONFIG_PARAMS
private final String
configKey
private final Number
configValue
private static boolean
seeding_upload_enabled
Constructors Summary
public TransferSpeedValidator(String configKey, Number value)
Creates a TransferSpeedValidator with the given configuration key and value

param
configKey Configuration key; must be "Max Upload Speed KBs" or "Max Download Speed KBs"
param
value Configuration value to be validated

    
    
    	    		
    	COConfigurationManager.addAndFireParameterListener(
    			UPLOAD_SEEDING_ENABLED_CONFIGKEY,
    			new ParameterListener()
        		{
        			public void 
        			parameterChanged(
        				String parameterName)
        			{
        				seeding_upload_enabled = COConfigurationManager.getBooleanParameter( parameterName );
        			}
        		});	
    
        this.configKey = configKey;
        configValue = value;
    
Methods Summary
public static java.lang.StringgetActiveAutoUploadParameter(org.gudy.azureus2.core3.global.GlobalManager gm)

    		// if downloading+seeding is set then we always use this regardless of
    		// only seeding status
    	
    	if ( COConfigurationManager.getBooleanParameter(TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY)){
    		
    		return( TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY );
    	}
    	
    	if ( gm.isSeedingOnly()){
        	
        	return( TransferSpeedValidator.AUTO_UPLOAD_SEEDING_ENABLED_CONFIGKEY );
        	
      	}else{
      		
      		return( TransferSpeedValidator.AUTO_UPLOAD_ENABLED_CONFIGKEY );
      	}
    
public static java.lang.StringgetActiveUploadParameter(org.gudy.azureus2.core3.global.GlobalManager gm)

       if ( seeding_upload_enabled && gm.isSeedingOnly()){
        	
        	return( TransferSpeedValidator.UPLOAD_SEEDING_CONFIGKEY );
        	
      	}else{
      		
      		return( TransferSpeedValidator.UPLOAD_CONFIGKEY );
      	}
    
public static java.lang.StringgetDownloadParameter()

    	return( DOWNLOAD_CONFIGKEY );
    
public static intgetGlobalDownloadRateLimitBytesPerSecond()

		return( COConfigurationManager.getIntParameter( getDownloadParameter()) * 1024 );
	
public java.lang.ObjectgetValue()
Validates the given configuration key/value pair and returns the validated value

return
Modified configuration value that conforms to validation as an Integer

        return validate(configKey, configValue);
    
public static booleanisAutoSpeedActive(org.gudy.azureus2.core3.global.GlobalManager gm)

    	return( COConfigurationManager.getBooleanParameter( getActiveAutoUploadParameter( gm )));
    
public static booleanisAutoUploadAvailable(com.aelitis.azureus.core.AzureusCore core)

    	return( core.getSpeedManager().isAvailable());
    
public static voidsetGlobalDownloadRateLimitBytesPerSecond(int bytes_per_second)

		COConfigurationManager.setParameter( getDownloadParameter(), bytes_per_second/1024 );
	
private static java.lang.Objectvalidate(java.lang.String configKey, java.lang.Number value)
Gets the transformed value as an Integer

        //assert value instanceof Number;

        int newValue = value.intValue();

        if(newValue < 0)
        {
            newValue = 0;
        }

        if(configKey == UPLOAD_CONFIGKEY)
        {
            final int downValue = COConfigurationManager.getIntParameter(DOWNLOAD_CONFIGKEY);

            if(
                    newValue != 0 &&
                    newValue < COConfigurationManager.CONFIG_DEFAULT_MIN_MAX_UPLOAD_SPEED &&
                    (downValue == 0 || downValue > newValue*2)
            )
            {
                newValue = (downValue + 1)/2;
                //COConfigurationManager.setParameter(DOWNLOAD_CONFIGKEY, newValue * 2);
            }
        }
        else if(configKey == DOWNLOAD_CONFIGKEY)
        {
            final int upValue = COConfigurationManager.getIntParameter(UPLOAD_CONFIGKEY);

            if(
                    upValue != 0 &&
                    upValue < COConfigurationManager.CONFIG_DEFAULT_MIN_MAX_UPLOAD_SPEED
            )
            {
                if(newValue > upValue*2)
                {
                    newValue = upValue*2;
                    //COConfigurationManager.setParameter(UPLOAD_CONFIGKEY, (newValue+1)/2);
                }
                else if(newValue == 0)
                {
                    newValue = upValue*2;
                    //COConfigurationManager.setParameter(UPLOAD_CONFIGKEY, 0);
                }
            }
        }else if ( configKey == UPLOAD_SEEDING_CONFIGKEY ){

        		// nothing to do as this is active only when were not downloading
        		// so we don't really care
        }else
        {
            throw new IllegalArgumentException("Invalid Configuation Key; use key for max upload and max download");
        }

        return new Integer(newValue);
        //return value;