KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > util > counters > impl > AbstractCounter


1 /*
2  * $Id: AbstractCounter.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
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 JavaDoc;
17 import java.util.Iterator JavaDoc;
18
19 /**
20  * @author <a HREF="mailto:gnt@codehaus.org">Guillaume Nodet</a>
21  * @version $Revision: 3798 $
22  */

23 public abstract class AbstractCounter implements Counter
24 {
25
26     private Type type;
27     private String JavaDoc name;
28     private ArrayList JavaDoc aggregates = null;
29
30     public AbstractCounter(String JavaDoc name, Type type)
31     {
32         this.name = name;
33         this.type = type;
34     }
35
36     public Type getType()
37     {
38         return this.type;
39     }
40
41     public String JavaDoc 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         if (this.aggregates == null)
59         {
60             this.aggregates = new ArrayList JavaDoc();
61         }
62         this.aggregates.add(counter);
63     }
64
65     protected void propagate()
66     {
67         if (this.aggregates != null)
68         {
69             Iterator JavaDoc it = this.aggregates.iterator();
70             while (it.hasNext())
71             {
72                 AggregateCounter agg = (AggregateCounter)it.next();
73                 agg.compute();
74             }
75         }
76     }
77
78 }
79
Popular Tags