01: /*
02: * $Id: AbstractCounter.java 8077 2007-08-27 20:15:25Z aperepel $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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: private final Type type;
24: private final String name;
25: private final List aggregates;
26:
27: public AbstractCounter(String name, Type type) {
28: super ();
29: this .name = name;
30: this .type = type;
31: this .aggregates = Collections.synchronizedList(new ArrayList());
32: }
33:
34: public Type getType() {
35: return this .type;
36: }
37:
38: public String getName() {
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: this .aggregates.add(counter);
54: }
55:
56: protected void propagate() {
57: Iterator it = this .aggregates.iterator();
58: while (it.hasNext()) {
59: AggregateCounter agg = (AggregateCounter) it.next();
60: agg.compute();
61: }
62: }
63:
64: }
|