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