Search in sources :

Example 6 with Average

use of com.biglybt.core.util.average.Average in project BiglyBT by BiglySoftware.

the class CoreStats method setEnableAverages.

public static synchronized void setEnableAverages(boolean enabled) {
    if (enabled == enable_averages) {
        return;
    }
    enable_averages = enabled;
    if (enabled) {
        if (average_timer == null) {
            average_timer = new Timer("CoreStats:average");
            averages = new HashMap();
            average_timer.addPeriodicEvent(AVERAGE_PERIOD, new TimerEventPerformer() {

                private final Map ave = averages;

                @Override
                public void perform(TimerEvent event) {
                    Map stats = getStatsSupport(null);
                    Iterator it = stats.entrySet().iterator();
                    boolean new_averages = false;
                    while (it.hasNext()) {
                        Map.Entry entry = (Map.Entry) it.next();
                        String key = (String) entry.getKey();
                        Object value = entry.getValue();
                        if (value instanceof Long) {
                            long last_value;
                            Average a;
                            boolean new_average;
                            Object[] a_entry = (Object[]) ave.get(key);
                            if (a_entry == null) {
                                a = AverageFactory.MovingImmediateAverage(10);
                                last_value = 0;
                                a_entry = new Object[] { a, value };
                                ave.put(key, a_entry);
                                new_averages = new_average = true;
                            } else {
                                a = (Average) a_entry[0];
                                last_value = ((Long) a_entry[1]).longValue();
                                new_average = false;
                            }
                            if (stats_types.get(key) == CUMULATIVE) {
                                if (!new_average) {
                                    a.update(((Long) value).longValue() - last_value);
                                }
                            } else {
                                a.update(((Long) value).longValue());
                            }
                            a_entry[1] = value;
                        }
                    }
                    if (new_averages) {
                        fireProvidersChangeListeners();
                    }
                }
            });
        }
    } else {
        if (average_timer != null) {
            average_timer.destroy();
            average_timer = null;
            averages = null;
        }
    }
}
Also used : Timer(com.biglybt.core.util.Timer) Average(com.biglybt.core.util.average.Average)

Aggregations

Average (com.biglybt.core.util.average.Average)6 SpeedManagerPingSource (com.biglybt.core.speedmanager.SpeedManagerPingSource)3 DiskManagerPiece (com.biglybt.core.disk.DiskManagerPiece)1 DiskManagerFileInfoURL (com.biglybt.core.download.DiskManagerFileInfoURL)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)1 Timer (com.biglybt.core.util.Timer)1 PluginInterface (com.biglybt.pif.PluginInterface)1 DiskManager (com.biglybt.pif.disk.DiskManager)1 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)1 Download (com.biglybt.pif.download.Download)1 IPCInterface (com.biglybt.pif.ipc.IPCInterface)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 Pattern (java.util.regex.Pattern)1