KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > util > counters > CounterFactory


1 /*
2  * $Id: CounterFactory.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;
12
13 import org.mule.util.counters.impl.CounterFactoryImpl;
14
15 import java.util.Iterator JavaDoc;
16
17 /**
18  * This class is the Counter's factory. It is the main entry point for operations on
19  * counters. The user can:
20  * <ul>
21  * <li>retrieve a counter by its name</li>
22  * <li>create a counter</li>
23  * <li>retrieve a list of public counters</li>
24  * </ul>
25  *
26  * @author <a HREF="mailto:gnt@codehaus.org">Guillaume Nodet</a>
27  * @version $Revision: 3798 $
28  */

29 public class CounterFactory
30 {
31
32     /**
33      * Enum class for all different types of counters. The type of a counter is
34      * defined on creation and can be retrieved on each counter.
35      *
36      * @author gnt
37      */

38     public static final class Type
39     {
40
41         /** A basic counter representing a double value */
42         public static final Type NUMBER = new Type("Number");
43         /** Counter representing the sum of two counters */
44         public static final Type SUM = new Type("Sum");
45         /** Counter representing the minimum value of a counter */
46         public static final Type MIN = new Type("Min");
47         /** Counter representing the maximum value of a counter */
48         public static final Type MAX = new Type("Max");
49         /** Counter representing the average value of a counter */
50         public static final Type AVERAGE = new Type("Average");
51         /** Counter representing the time average value of a counter */
52         public static final Type TIME_AVERAGE = new Type("TimeAverage");
53         /** Counter representing the variation of a counter */
54         public static final Type DELTA = new Type("Delta");
55         /** Counter representing the instant rate of a counter */
56         public static final Type INSTANT_RATE = new Type("InstantRate");
57         /** Counter representing rate per second of a counter */
58         public static final Type RATE_PER_SECOND = new Type("RatePerSecond");
59         /** Counter representing rate per minute of a counter */
60         public static final Type RATE_PER_MINUTE = new Type("RatePerMinute");
61         /** Counter representing rate per hour of a counter */
62         public static final Type RATE_PER_HOUR = new Type("RatePerHour");
63         /** Counter represening the sum of two other counters */
64         public static final Type PLUS = new Type("Plus");
65         /** Counter represening the difference of two other counters */
66         public static final Type MINUS = new Type("Minus");
67         /** Counter represening the multiplication of two other counters */
68         public static final Type MULTIPLY = new Type("Multiply");
69         /** Counter represening the division of two other counters */
70         public static final Type DIVIDE = new Type("Divide");
71
72         /** The string representation of this counter type */
73         private String JavaDoc name;
74
75         /**
76          * Constructor of the type
77          *
78          * @param name the name of the counter type
79          */

80         protected Type(String JavaDoc name)
81         {
82             this.name = name;
83         }
84
85         public String JavaDoc getName()
86         {
87             return this.name;
88         }
89     }
90
91     /**
92      * Search the defined counters for a counter of the given name.
93      *
94      * @param name the name of the counter to retrieve
95      * @return the counter
96      */

97     public static Counter getCounter(String JavaDoc name)
98     {
99         return CounterFactoryImpl.getCounter(name);
100     }
101
102     /**
103      * Create a new public counter of the given type.
104      *
105      * @param name the name of the counter to create
106      * @param type the type of the counter
107      * @return the newly created counter
108      */

109     public static Counter createCounter(String JavaDoc name, Type type)
110     {
111         return createCounter(name, null, null, type, true);
112     }
113
114     /**
115      * Create a new counter of the given type and visibility.
116      *
117      * @param name the name of the counter to create
118      * @param type the type of the counter
119      * @param visible boolean specifying if the counter is public or not
120      * @return the newly created counter
121      */

122     public static Counter createCounter(String JavaDoc name, Type type, boolean visible)
123     {
124         return createCounter(name, null, null, type, visible);
125     }
126
127     /**
128      * Create a new public aggregate counter of the given type.
129      *
130      * @param name the name of the counter to create
131      * @param base the name of the counter to use for computation
132      * @param type the type of the counter
133      * @return the newly created counter
134      */

135     public static Counter createCounter(String JavaDoc name, String JavaDoc base, Type type)
136     {
137         return createCounter(name, base, null, type, true);
138     }
139
140     /**
141      * Create a new aggregate counter of the given type and visibility.
142      *
143      * @param name the name of the counter to create
144      * @param base the name of the counter to use for computation
145      * @param type the type of the counter
146      * @param visible boolean specifying if the counter is public or not
147      * @return the newly created counter
148      */

149     public static Counter createCounter(String JavaDoc name, String JavaDoc base, Type type, boolean visible)
150     {
151         return createCounter(name, base, null, type, visible);
152     }
153
154     /**
155      * Create a new public aggregate counter of the given type.
156      *
157      * @param name the name of the counter to create
158      * @param first the name of the first counter to use for computation
159      * @param second the name of the first counter to use for computation
160      * @param type the type of the counter
161      * @return the newly created counter
162      */

163     public static Counter createCounter(String JavaDoc name, String JavaDoc first, String JavaDoc second, Type type)
164     {
165         return createCounter(name, first, second, type, true);
166     }
167
168     /**
169      * Create a new aggregate counter of the given type and visibility.
170      *
171      * @param name the name of the counter to create
172      * @param first the name of the first counter to use for computation
173      * @param second the name of the first counter to use for computation
174      * @param type the type of the counter
175      * @param visible boolean specifying if the counter is public or not
176      * @return the newly created counter
177      */

178     public static Counter createCounter(String JavaDoc name, String JavaDoc first, String JavaDoc second, Type type, boolean visible)
179     {
180         return CounterFactoryImpl.createCounter(name, first, second, type, visible);
181     }
182
183     /**
184      * Retrieve an iterator giving the list of public defined counters.
185      *
186      * @return an iterator to walk throught the list of public defined counters
187      */

188     public static Iterator JavaDoc getCounters()
189     {
190         return CounterFactoryImpl.getCounters();
191     }
192
193 }
194
Popular Tags