01: /**
02: *
03: */package clime.messadmin.model.stats;
04:
05: import java.io.Serializable;
06:
07: /**
08: * Used for counting hits and building basic statistics.
09: *
10: * @author Cédrik LIME
11: */
12: public class HitsCounter implements Serializable {
13: /** The total number of calls to this object's hit() method */
14: protected volatile int hits = 0;
15:
16: /** The first time this object was updated */
17: // protected volatile long firstAccessTime = 0;
18: /** The last time this object was updated */
19: // protected volatile long lastAccessTime = 0;
20: public HitsCounter() {
21: super ();
22: }
23:
24: public void hit() {
25: hit(System.currentTimeMillis());
26: }
27:
28: public void hit(long currentTimeMillis) {
29: ++hits;
30: setLastAccessTime(currentTimeMillis);
31: }
32:
33: public void setLastAccessTime(long now) {
34: // set the first and last access times.
35: // if (firstAccessTime == 0) {
36: // firstAccessTime = now;
37: // }
38:
39: // lastAccessTime = now;
40: }
41:
42: public int getHits() {
43: return hits;
44: }
45:
46: // public Date getFirstAccessTime() {
47: // return new Date(firstAccessTime);
48: // }
49:
50: // public Date getLastAccessTime() {
51: // return new Date(lastAccessTime);
52: // }
53:
54: /**
55: * {@inheritDoc}
56: */
57: public String toString() {
58: return toStringBuffer().append(']').toString();
59: }
60:
61: protected StringBuffer toStringBuffer() {
62: StringBuffer buffer = new StringBuffer(128);
63: buffer.append(getClass().getName()).append('[');
64: buffer.append("hits=").append(getHits());//.append(',');//$NON-NLS-1$
65: // buffer.append("firstAccessTime=").append(getFirstAccessTime()).append(',');//$NON-NLS-1$
66: // buffer.append("lastAccessTime=").append(getLastAccessTime());//$NON-NLS-1$
67: return buffer;
68: }
69: }
|