KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > management > j2ee > statistics > StatsBase


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.management.j2ee.statistics;
23
24 import javax.management.j2ee.statistics.Statistic JavaDoc;
25 import javax.management.j2ee.statistics.Stats JavaDoc;
26 import java.io.Serializable JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Iterator JavaDoc;
29 import java.util.Map JavaDoc;
30
31 /**
32  * The base JSR77.6.10 Stats interface base implementation
33  *
34  * @author Scott.Stark@jboss.org
35  * @version $Revision: 37459 $
36  */

37 public class StatsBase
38         implements Stats JavaDoc, Serializable JavaDoc
39 {
40    // Constants -----------------------------------------------------
41

42    /** @since 4.0.2 */
43    private static final long serialVersionUID = 384207297746356032L;
44    
45    // Private Data --------------------------------------------------
46

47    /**
48     * A Map<String,Statistic> of the statistics held by a given
49     * Stats implementation
50     */

51    private Map JavaDoc statistics;
52
53    // Constructors --------------------------------------------------
54

55    public StatsBase()
56    {
57       statistics = new HashMap JavaDoc();
58    }
59
60    public StatsBase(Map JavaDoc statistics)
61    {
62       this.statistics = statistics;
63    }
64
65
66 // Begin Stats interface methods
67

68    /**
69     * Access all the Statistics names
70     *
71     * @return An array of the names of the statistics held in the Stats object
72     */

73    public String JavaDoc[] getStatisticNames()
74    {
75       String JavaDoc[] names = new String JavaDoc[statistics.size()];
76       statistics.keySet().toArray(names);
77       return names;
78    }
79
80    /**
81     * Access all the Statistics
82     *
83     * @return An array of the Statistic held in the Stats object
84     */

85    public Statistic JavaDoc[] getStatistics()
86    {
87       Statistic JavaDoc[] stats = new Statistic JavaDoc[statistics.size()];
88       statistics.values().toArray(stats);
89       return stats;
90    }
91
92    /**
93     * Access a Statistic by its name.
94     *
95     * @param name
96     * @return
97     */

98    public Statistic JavaDoc getStatistic(String JavaDoc name)
99    {
100       Statistic JavaDoc stat = (Statistic JavaDoc) statistics.get(name);
101       return stat;
102    }
103 // End Stats interface methods
104

105    /**
106     * Reset all StatisticImpl objects
107     */

108    public void reset()
109    {
110       Iterator JavaDoc iter = statistics.values().iterator();
111       while (iter.hasNext())
112       {
113          Object JavaDoc next = iter.next();
114          if (next instanceof StatisticImpl)
115          {
116             StatisticImpl s = (StatisticImpl) next;
117             s.reset();
118          }
119       }
120    }
121
122    public String JavaDoc toString()
123    {
124       return this.getClass().getName() + " [ " + statistics + " ]";
125    }
126
127    /**
128     * Add or replace Statistic in the Stats collection.
129     *
130     * @param name Name of the Statistic instance
131     * @param statistic Statistic to be added
132     */

133    public void addStatistic(String JavaDoc name, Statistic JavaDoc statistic)
134    {
135       statistics.put(name, statistic);
136    }
137
138 }
139
Popular Tags