Mercurial > hg > blitz_stable
comparison src/org/dancres/blitz/entry/InstanceSwitchListener.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.Stat; | |
4 import org.dancres.blitz.stats.SwitchListener; | |
5 import org.dancres.blitz.stats.Switch; | |
6 import org.dancres.blitz.stats.StatsBoard; | |
7 import org.dancres.blitz.stats.InstanceSwitch; | |
8 import org.dancres.blitz.stats.InstanceCount; | |
9 import org.dancres.blitz.stats.SwitchSettings; | |
10 | |
11 class InstanceSwitchListener implements SwitchListener { | |
12 private String theInstanceType; | |
13 private InstanceCount theCount; | |
14 | |
15 InstanceSwitchListener(String aType, int anInitialCount) { | |
16 theInstanceType = aType; | |
17 theCount = new InstanceCount(aType, anInitialCount); | |
18 | |
19 SwitchSettings.get().add(this); | |
20 } | |
21 | |
22 public synchronized void switchFlipped(Switch aSwitch) { | |
23 if (aSwitch instanceof InstanceSwitch) { | |
24 InstanceSwitch mySwitch = (InstanceSwitch) aSwitch; | |
25 | |
26 if ((mySwitch.getType().equals(theInstanceType)) || | |
27 (mySwitch.isWildcard())) { | |
28 | |
29 if (mySwitch.isOn()) { | |
30 StatsBoard.get().add(theCount); | |
31 } else | |
32 StatsBoard.get().remove(theCount); | |
33 } | |
34 } | |
35 } | |
36 | |
37 synchronized void wrote() { | |
38 theCount.wrote(); | |
39 } | |
40 | |
41 synchronized void took() { | |
42 theCount.took(); | |
43 } | |
44 | |
45 Stat getInstanceStat() { | |
46 return theCount.generate(); | |
47 } | |
48 | |
49 synchronized int getTotal() { | |
50 return theCount.getCount(); | |
51 } | |
52 | |
53 void destroy() { | |
54 SwitchSettings.get().remove(this); | |
55 StatsBoard.get().remove(theCount); | |
56 } | |
57 } |