comparison src/org/dancres/blitz/SearchTasks.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;
2
3 import org.dancres.blitz.stats.BlockingOpsStat;
4 import org.dancres.blitz.stats.MissedOpsStat;
5 import org.dancres.blitz.stats.Stat;
6 import org.dancres.blitz.stats.StatGenerator;
7 import org.dancres.blitz.stats.StatsBoard;
8
9 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
10 import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong;
11
12 /**
13 * Tracks the number ouf outstanding blocked operations (take and read)
14 */
15 class SearchTasks {
16 private static SearchTasks theTasks = new SearchTasks();
17
18 private AtomicInteger theTakeCount = new AtomicInteger();
19 private AtomicInteger theReadCount = new AtomicInteger();
20 private AtomicLong theMissedTakes = new AtomicLong();
21 private AtomicLong theMissedReads = new AtomicLong();
22
23 public static SearchTasks get() {
24 return theTasks;
25 }
26
27 private SearchTasks() {
28 StatsBoard.get().add(new BlockingStatGenerator());
29 StatsBoard.get().add(new MissedStatGenerator());
30 }
31
32 public void add(MatchTask aTask) {
33 if (aTask.getVisitor().isDeleter())
34 theTakeCount.incrementAndGet();
35 else
36 theReadCount.incrementAndGet();
37 }
38
39 public void remove(MatchTask aTask, boolean didMiss) {
40 if (aTask.getVisitor().isDeleter()) {
41 theTakeCount.decrementAndGet();
42
43 if (didMiss)
44 theMissedTakes.incrementAndGet();
45 } else {
46 theReadCount.decrementAndGet();
47
48 if (didMiss)
49 theMissedReads.incrementAndGet();
50 }
51 }
52
53 private class BlockingStatGenerator implements StatGenerator {
54 private long theStatId = StatGenerator.UNSET_ID;
55
56 public long getId() {
57 return theStatId;
58 }
59
60 public void setId(long anId) {
61 theStatId = anId;
62 }
63
64 public Stat generate() {
65 return new BlockingOpsStat(
66 theStatId, theReadCount.intValue(), theTakeCount.intValue());
67 }
68 }
69
70 private class MissedStatGenerator implements StatGenerator {
71 private long theStatId = StatGenerator.UNSET_ID;
72
73 public long getId() {
74 return theStatId;
75 }
76
77 public void setId(long anId) {
78 theStatId = anId;
79 }
80
81 public Stat generate() {
82 return new MissedOpsStat(
83 theStatId, theMissedReads.longValue(),
84 theMissedTakes.longValue());
85 }
86 }
87 }