FileDocCategorySizeDatePackage
PingSpaceMon.javaAPI DocAzureus 3.0.3.47197Tue Aug 14 07:44:54 BST 2007com.aelitis.azureus.core.speedmanager.impl.v2

PingSpaceMon

public class PingSpaceMon extends Object
Created on Jul 16, 2007 Created by Alan Snyder Copyright (C) 2007 Aelitis, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

AELITIS, SAS au capital de 63.529,40 euros 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.

Fields Summary
private static final long
INTERVAL
long
nextCheck
TransferMode
mode
List
listeners
Constructors Summary
Methods Summary
public voidaddListener(PSMonitorListener listener)

//List<PSMonitorListener>


       

        //don't register the same listener twice.
        for(int i=0; i<listeners.size(); i++){
            PSMonitorListener t = (PSMonitorListener) listeners.get(i);
            if( t==listener ){
                SpeedManagerLogger.trace("Not logging same listener twice. listener="+listener.toString());
                return;
            }
        }

        listeners.add( listener );
    
booleancheckForLowerLimits()


        long curr = SystemTime.getCurrentTime();
        if( curr > nextCheck ){
            SpeedManagerLogger.trace("PingSpaceMon checking for lower limits.");

            for(int i=0; i<listeners.size(); i++ ){
                PSMonitorListener l =(PSMonitorListener) listeners.get(i);

                if(l!=null){
                    l.notifyUpload( getUploadEstCapacity() );
                }else{
                    SpeedManagerLogger.trace("listener index _"+i+"_ was null.");
                }
            }

            resetTimer();
            return true;
        }
        return false;
    
public static com.aelitis.azureus.core.speedmanager.SpeedManagerLimitEstimategetDownloadEstCapacity()
Get the estimated download capacity from the SpeedManager.

return
- SpeedManagerLimitEstimate

        try{
            SMInstance pm = SMInstance.getInstance();
            SpeedManagerAlgorithmProviderAdapter adapter = pm.getAdapter();
            SpeedManager sm = adapter.getSpeedManager();
            SpeedManagerLimitEstimate downEstCapacity = sm.getEstimatedDownloadCapacityBytesPerSec();

            return downEstCapacity;

        }catch(Throwable t){
            //log this event and
            SpeedManagerLogger.log( t.toString() );
            t.printStackTrace();

            //something to return 0 and -1.0f results.
            return new DefaultLimitEstimate();
        }
    
public static com.aelitis.azureus.core.speedmanager.SpeedManagerLimitEstimategetDownloadLimit()
Get the current estimated download limit from the ping mapper.

return
- SpeedManagerLimitEstimate

        try{
            SMInstance pm = SMInstance.getInstance();
            SpeedManagerAlgorithmProviderAdapter adapter = pm.getAdapter();
            SpeedManagerPingMapper persistentMap = adapter.getPingMapper();
            SpeedManagerLimitEstimate downEst = persistentMap.getEstimatedDownloadLimit(true);

            return downEst;

        }catch(Throwable t){
            //log this event and
            SpeedManagerLogger.log( t.toString() );
            t.printStackTrace();

            //something to return 0 and -1.0f results.
            return new DefaultLimitEstimate();
        }
    
public static com.aelitis.azureus.core.speedmanager.SpeedManagerLimitEstimategetUploadEstCapacity()

        try{
            SMInstance pm = SMInstance.getInstance();
            SpeedManagerAlgorithmProviderAdapter adapter = pm.getAdapter();
            SpeedManager sm = adapter.getSpeedManager();
            SpeedManagerLimitEstimate upEstCapacity = sm.getEstimatedUploadCapacityBytesPerSec();

            return upEstCapacity;

        }catch(Throwable t){
            //log this event and
            SpeedManagerLogger.log( t.toString() );
            t.printStackTrace();

            //something to return 1 and -1.0f results.
            return new DefaultLimitEstimate();
        }
    
public static com.aelitis.azureus.core.speedmanager.SpeedManagerLimitEstimategetUploadLimit(boolean persistent)
Get the current estimated upload limit from the ping mapper.

param
- true if the long-term persistent result should be used.
return
- SpeedManagerLimitEstimate.

        try{
            SMInstance pm = SMInstance.getInstance();
            SpeedManagerAlgorithmProviderAdapter adapter = pm.getAdapter();
            SpeedManagerPingMapper persistentMap = adapter.getPingMapper();
            SpeedManagerLimitEstimate upEst = persistentMap.getEstimatedUploadLimit(true);

            return upEst;
            
        }catch(Throwable t){
            //log this event and
            SpeedManagerLogger.log( t.toString() );
            t.printStackTrace();

            //something to return 1 and -1.0f results.
            return new DefaultLimitEstimate();
        }
    
public booleanremoveListener(PSMonitorListener listener)


        return listeners.remove(listener);

    
voidresetTimer()

        long curr = SystemTime.getCurrentTime();
        nextCheck = curr + INTERVAL;
        SpeedManagerLogger.trace("Monitor resetting time. Next check in interval.");
    
booleanupdateStatus(TransferMode tMode)

param
tMode -
return
- true if is has a new mode, and the clock starts over.


        if(mode==null){
            mode=tMode;
            return true;
        }

        if( mode.getMode() != tMode.getMode() ){
            mode = tMode;
            resetTimer();
            return true;
        }
        return checkForLowerLimits();