comparison src/org/dancres/blitz/stats/InstanceCount.java @ 0:3dc0c5604566

Initial checkin of blitz 2.0 fcs - no installer yet.
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 21 Mar 2009 11:00:06 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:3dc0c5604566
1 package org.dancres.blitz.stats;
2
3 /**
4 <p>Tracks the number of instance of a particular type within a Blitz
5 instance. The instance count accounts for writes and takes but does not
6 account for lease expired entries because the cleanup of lease expired
7 entries is done lazily. Thus the instance counts should be treated as
8 a guide not an exact number.</p>
9 */
10 public class InstanceCount implements Stat, StatGenerator {
11 private long theId = StatGenerator.UNSET_ID;
12
13 private String theType;
14 private int theCount;
15
16 public InstanceCount(String aType, int aCount) {
17 theType = aType;
18 theCount = aCount;
19 }
20
21 private InstanceCount(long anId, String aType, int aCount) {
22 theId = anId;
23 theType = aType;
24 theCount = aCount;
25 }
26
27 public void setId(long anId) {
28 theId = anId;
29 }
30
31 public long getId() {
32 return theId;
33 }
34
35 public synchronized Stat generate() {
36 InstanceCount myStat = new InstanceCount(theId, theType, theCount);
37 return myStat;
38 }
39
40 public String getType() {
41 return theType;
42 }
43
44 public int getCount() {
45 return theCount;
46 }
47
48 public synchronized void wrote() {
49 ++theCount;
50 }
51
52 public synchronized void took() {
53 --theCount;
54 }
55
56 public String toString() {
57 return "Total instance of type " + theType + " is " + theCount;
58 }
59 }