clime.messadmin.model.stats.HitsCounter Maven / Gradle / Ivy
/**
*
*/
package clime.messadmin.model.stats;
import java.io.Serializable;
/**
* Used for counting hits and building basic statistics.
*
* @author Cédrik LIME
*/
public class HitsCounter implements Serializable {
/** The total number of calls to this object's hit() method */
protected volatile int hits = 0;
/** The first time this object was updated */
// protected volatile long firstAccessTime = 0;
/** The last time this object was updated */
// protected volatile long lastAccessTime = 0;
public HitsCounter() {
super();
}
public void hit() {
hit(System.currentTimeMillis());
}
public void hit(long currentTimeMillis) {
++hits;
setLastAccessTime(currentTimeMillis);
}
public void setLastAccessTime(long now) {
// set the first and last access times.
// if (firstAccessTime == 0) {
// firstAccessTime = now;
// }
// lastAccessTime = now;
}
public int getHits() {
return hits;
}
// public Date getFirstAccessTime() {
// return new Date(firstAccessTime);
// }
// public Date getLastAccessTime() {
// return new Date(lastAccessTime);
// }
/**
* {@inheritDoc}
*/
public String toString() {
return toStringBuffer().append(']').toString();
}
protected StringBuffer toStringBuffer() {
StringBuffer buffer = new StringBuffer(128);
buffer.append(getClass().getName()).append('[');
buffer.append("hits=").append(getHits());//.append(',');
// buffer.append("firstAccessTime=").append(getFirstAccessTime()).append(',');
// buffer.append("lastAccessTime=").append(getLastAccessTime());
return buffer;
}
}