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 super();
27 this.name = name;
28 this.type = type;
29 this.aggregates = Collections.synchronizedList(new ArrayList());
30 }
31
32 public Type getType()
33 {
34 return this.type;
35 }
36
37 public String getName()
38 {
39 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 this.aggregates.add(counter);
55 }
56
57 protected void propagate()
58 {
59 Iterator it = this.aggregates.iterator();
60 while (it.hasNext())
61 {
62 AggregateCounter agg = (AggregateCounter) it.next();
63 agg.compute();
64 }
65 }
66
67 }