FileDocCategorySizeDatePackage
NetworkConnectionHelper.javaAPI DocAzureus 3.0.3.44626Tue Feb 06 17:25:00 GMT 2007com.aelitis.azureus.core.networkmanager

NetworkConnectionHelper

public abstract class NetworkConnectionHelper extends Object implements NetworkConnectionBase

Fields Summary
private int
upload_limit
private final LimitedRateGroup
upload_limiter
private int
download_limit
private final LimitedRateGroup
download_limiter
private LimitedRateGroup[]
upload_limiters
private LimitedRateGroup[]
download_limiters
Constructors Summary
Methods Summary
public voidaddRateLimiter(LimitedRateGroup limiter, boolean upload)

			synchronized( this ){
				
				if ( upload ){
					
					for (int i=0;i<upload_limiters.length;i++){
						
						if ( upload_limiters[i] == limiter ){
							
							return;
						}
					}
					
					LimitedRateGroup[] new_upload_limiters = new LimitedRateGroup[upload_limiters.length+1];
					
					System.arraycopy(upload_limiters, 0, new_upload_limiters, 0, upload_limiters.length );
					
					new_upload_limiters[ upload_limiters.length ] = limiter;
					
					upload_limiters = new_upload_limiters;
				}else{
				
					for (int i=0;i<download_limiters.length;i++){

						if ( download_limiters[i] == limiter ){

							return;
						}
					}
					LimitedRateGroup[] new_download_limiters = new LimitedRateGroup[download_limiters.length+1];
					
					System.arraycopy(download_limiters, 0, new_download_limiters, 0, download_limiters.length );
					
					new_download_limiters[ download_limiters.length ] = limiter;
					
					download_limiters = new_download_limiters;
				}
			}
			
			NetworkManager.getSingleton().addRateLimiter( this, limiter, upload );
		
public intgetDownloadLimit()

			return( download_limit );
		
public LimitedRateGroup[]getRateLimiters(boolean upload)

			if ( upload ){
				
				return( upload_limiters );
				
			}else{
				
				return( download_limiters );
			}
		
public intgetUploadLimit()

	  
		 
		
		
			return( upload_limit );
		
public voidremoveRateLimiter(LimitedRateGroup limiter, boolean upload)

			synchronized( this ){
				
				if ( upload ){
					
					if ( upload_limiters.length == 0 ){
						
						return;
					}
					
					int	pos = 0;
									
					LimitedRateGroup[] new_upload_limiters = new LimitedRateGroup[upload_limiters.length-1];
									
					for (int i=0;i<upload_limiters.length;i++){
						
						if ( upload_limiters[i] != limiter ){
							
							if ( pos == new_upload_limiters.length ){
								
								return;
							}
							
							new_upload_limiters[pos++] = upload_limiters[i];
						}
					}
					
					upload_limiters = new_upload_limiters;
					
				}else{
				
					if ( download_limiters.length == 0 ){
						
						return;
					}
					
					int	pos = 0;
									
					LimitedRateGroup[] new_download_limiters = new LimitedRateGroup[download_limiters.length-1];
									
					for (int i=0;i<download_limiters.length;i++){
						
						if ( download_limiters[i] != limiter ){
							
							if ( pos == new_download_limiters.length ){
								
								return;
							}
							
							new_download_limiters[pos++] = download_limiters[i];
						}
					}
					
					download_limiters = new_download_limiters;
				}
			}
		
			NetworkManager.getSingleton().removeRateLimiter( this, limiter, upload );
		
public voidsetDownloadLimit(int limit)

			download_limit = limit;
		
public voidsetUploadLimit(int limit)

			upload_limit = limit;