1
2
3
4
5
6
7
8
9
10
11 package org.mule.util.counters.impl;
12
13 import org.mule.util.counters.Counter;
14 import org.mule.util.counters.CounterFactory.Type;
15
16 import java.util.ArrayList;
17 import java.util.Collections;
18 import java.util.Iterator;
19 import java.util.List;
20
21 public abstract class AbstractCounter implements Counter
22 {
23
24 private final Type type;
25 private final String name;
26 private final List aggregates;
27
28 public AbstractCounter(String name, Type type)
29 {
30 super();
31 this.name = name;
32 this.type = type;
33 this.aggregates = Collections.synchronizedList(new ArrayList());
34 }
35
36 public Type getType()
37 {
38 return this.type;
39 }
40
41 public String getName()
42 {
43 return this.name;
44 }
45
46 public abstract double increment();
47
48 public abstract double incrementBy(double value);
49
50 public abstract double decrement();
51
52 public abstract void setRawValue(double value);
53
54 public abstract double nextValue();
55
56 protected void addAggregate(AggregateCounter counter)
57 {
58 this.aggregates.add(counter);
59 }
60
61 protected void propagate()
62 {
63 Iterator it = this.aggregates.iterator();
64 while (it.hasNext())
65 {
66 AggregateCounter agg = (AggregateCounter) it.next();
67 agg.compute();
68 }
69 }
70
71 }