KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > management > stats > StatsImpl


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.management.stats;
18
19 import java.io.Serializable JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22 import javax.management.j2ee.statistics.Statistic JavaDoc;
23 import javax.management.j2ee.statistics.Stats JavaDoc;
24
25 /**
26  * Geronimo implementation of the JSR-77 Stats interface. Dynamically tracks
27  * available statistics for its subclasses, to make it easy to iterate
28  * available statistics without knowing exactly what kind of class you're
29  * looking at. Not sure when you'd want to do that, but hey.
30  *
31  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
32  */

33 public class StatsImpl implements Stats JavaDoc, Serializable JavaDoc {
34     private final Map JavaDoc stats = new HashMap JavaDoc();
35
36     public StatsImpl() {
37     }
38
39     protected void addStat(String JavaDoc name, Statistic JavaDoc value) {
40         stats.put(name, value);
41     }
42
43     /**
44      * Used when the available statistics are dynamic (e.g. depend on the
45      * current clients of the service, etc.).
46      *
47      * @param name The statistic to remove
48      */

49     protected void removeStat(String JavaDoc name) {
50         stats.remove(name);
51     }
52
53     public Statistic JavaDoc getStatistic(String JavaDoc statisticName) {
54         return (Statistic JavaDoc)stats.get(statisticName);
55     }
56
57     public String JavaDoc[] getStatisticNames() {
58         return (String JavaDoc[]) stats.keySet().toArray(new String JavaDoc[stats.size()]);
59     }
60
61     public Statistic JavaDoc[] getStatistics() {
62         String JavaDoc[] names = getStatisticNames();
63         Statistic JavaDoc[] result = new Statistic JavaDoc[names.length];
64         for (int i = 0; i < names.length; i++) {
65             result[i] = (Statistic JavaDoc) stats.get(names[i]);
66         }
67         return result;
68     }
69 }
70
Popular Tags