Package penny.downloadmanager.util

Source Code of penny.downloadmanager.util.PropertyChangeCounter

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

import penny.util.StopWatch;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

/**
*
* @author john
*/
public class PropertyChangeCounter implements PropertyChangeListener {
    private long count;
    private StopWatch watch;
    private String name;
   
    public PropertyChangeCounter(String name) {
        this.name = name;
        watch = new StopWatch();
        watch.start();
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        watch.add();
        if(watch.getTimeMillis() > 1000) {
            float rate = count / ((float) watch.getTimeMillis() / (float)1000);
            //System.out.println(Thread.currentThread().getName() + ": " + name + " event rate: " + rate + "/s");
            watch.restart();
            count = 0;
        }
        count++;
    }
}
TOP

Related Classes of penny.downloadmanager.util.PropertyChangeCounter

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.