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 | 38 | super(); |
31 | 38 | this.name = name; |
32 | 38 | this.type = type; |
33 | 38 | this.aggregates = Collections.synchronizedList(new ArrayList()); |
34 | 38 | } |
35 | |
|
36 | |
public Type getType() |
37 | |
{ |
38 | 0 | return this.type; |
39 | |
} |
40 | |
|
41 | |
public String getName() |
42 | |
{ |
43 | 0 | 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 | 26 | this.aggregates.add(counter); |
59 | 26 | } |
60 | |
|
61 | |
protected void propagate() |
62 | |
{ |
63 | 110 | Iterator it = this.aggregates.iterator(); |
64 | 170 | while (it.hasNext()) |
65 | |
{ |
66 | 60 | AggregateCounter agg = (AggregateCounter) it.next(); |
67 | 60 | agg.compute(); |
68 | 60 | } |
69 | 110 | } |
70 | |
|
71 | |
} |