Package penny.downloadmanager.util

Source Code of penny.downloadmanager.util.EventRateCounter

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package penny.downloadmanager.util;

import penny.util.StopWatch;
import java.awt.AWTEvent;
import java.awt.EventQueue;

/**
*
* @author john
*/
public class EventRateCounter extends EventQueue {
    private long count;
    private StopWatch watch;
   
    public EventRateCounter() {
        watch = new StopWatch();
        watch.start();
    }
   
    @Override
    protected void dispatchEvent(AWTEvent event) {
        watch.add();
        if(watch.getTimeMillis() > 1000) {
            float rate = count / ((float) watch.getTimeMillis() / (float)1000);
            //System.out.println("swing event rate: " + rate + "/s");
            watch.restart();
            count = 0;
        }
        count++;
        super.dispatchEvent(event);
    }
}
TOP

Related Classes of penny.downloadmanager.util.EventRateCounter

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.