Mercurial > hg > blitz_stable
comparison src/org/dancres/blitz/entry/OpSwitchListener.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.entry; | |
2 | |
3 import org.dancres.blitz.stats.SwitchListener; | |
4 import org.dancres.blitz.stats.Switch; | |
5 import org.dancres.blitz.stats.OpSwitch; | |
6 import org.dancres.blitz.stats.OpStat; | |
7 import org.dancres.blitz.stats.StatsBoard; | |
8 import org.dancres.blitz.stats.SwitchSettings; | |
9 | |
10 /** | |
11 Listens for changes in OpSwitches pertinent to a particular Entry type | |
12 and manages counts and statistics accordingly. | |
13 */ | |
14 class OpSwitchListener implements SwitchListener { | |
15 private boolean trackTakes; | |
16 private boolean trackReads; | |
17 private boolean trackWrites; | |
18 | |
19 private String theType; | |
20 | |
21 private OpStat theTakes; | |
22 private OpStat theReads; | |
23 private OpStat theWrites; | |
24 | |
25 OpSwitchListener(String aType) { | |
26 theType = aType; | |
27 theTakes = new OpStat(theType, OpStat.TAKES); | |
28 theReads = new OpStat(theType, OpStat.READS); | |
29 theWrites = new OpStat(theType, OpStat.WRITES); | |
30 | |
31 SwitchSettings.get().add(this); | |
32 } | |
33 | |
34 public synchronized void switchFlipped(Switch aSwitch) { | |
35 if (aSwitch instanceof OpSwitch) { | |
36 OpSwitch mySwitch = (OpSwitch) aSwitch; | |
37 | |
38 if ((mySwitch.getType().equals(theType)) || | |
39 (mySwitch.isWildcard())) { | |
40 | |
41 boolean mySetting = mySwitch.isEnabled(); | |
42 | |
43 switch (mySwitch.getOp()) { | |
44 case OpSwitch.TAKE_OPS : { | |
45 trackTakes = mySetting; | |
46 | |
47 if (mySetting) | |
48 StatsBoard.get().add(theTakes); | |
49 else | |
50 StatsBoard.get().remove(theTakes); | |
51 | |
52 break; | |
53 } | |
54 case OpSwitch.READ_OPS : { | |
55 trackReads = mySetting; | |
56 | |
57 if (mySetting) | |
58 StatsBoard.get().add(theReads); | |
59 else | |
60 StatsBoard.get().remove(theReads); | |
61 | |
62 break; | |
63 } | |
64 case OpSwitch.WRITE_OPS : { | |
65 trackWrites = mySetting; | |
66 | |
67 if (mySetting) | |
68 StatsBoard.get().add(theWrites); | |
69 else | |
70 StatsBoard.get().remove(theWrites); | |
71 | |
72 break; | |
73 } | |
74 } | |
75 } | |
76 } | |
77 } | |
78 | |
79 synchronized void didWrite() { | |
80 if (trackWrites) | |
81 theWrites.incCount(); | |
82 } | |
83 | |
84 synchronized void didRead() { | |
85 if (trackReads) | |
86 theReads.incCount(); | |
87 } | |
88 | |
89 synchronized void didTake() { | |
90 if (trackTakes) | |
91 theTakes.incCount(); | |
92 } | |
93 | |
94 void destroy() { | |
95 SwitchSettings.get().remove(this); | |
96 StatsBoard.get().remove(theReads); | |
97 StatsBoard.get().remove(theTakes); | |
98 StatsBoard.get().remove(theWrites); | |
99 } | |
100 } |