All Downloads are FREE. Search and download functionalities are using the official Maven repository.

clime.messadmin.model.stats.HitsCounter Maven / Gradle / Ivy

Go to download

Notification system and Session administration for J2EE Web Applications

There is a newer version: 4.1.1
Show newest version
/**
 * 
 */
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;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy