KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > management > StatsImpl


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

18 package org.apache.activemq.management;
19
20 import java.util.*;
21 import javax.management.j2ee.statistics.Statistic JavaDoc;
22 import javax.management.j2ee.statistics.Stats JavaDoc;
23
24
25 /**
26  * Base class for a Stats implementation
27  *
28  * @version $Revision: 1.2 $
29  */

30 public class StatsImpl extends StatisticImpl implements Stats JavaDoc, Resettable{
31     private Map map;
32
33     public StatsImpl() {
34         this(new HashMap());
35     }
36
37     public StatsImpl(Map map) {
38         super("stats", "many", "Used only as container, not Statistic");
39         this.map = map;
40     }
41
42     public void reset() {
43         Statistic JavaDoc[] stats = getStatistics();
44         for (int i = 0, size = stats.length; i < size; i++) {
45             Statistic JavaDoc stat = stats[i];
46             if (stat instanceof Resettable) {
47                 Resettable r = (Resettable) stat;
48                 r.reset();
49             }
50         }
51     }
52
53     public Statistic JavaDoc getStatistic(String JavaDoc name) {
54         return (Statistic JavaDoc) map.get(name);
55     }
56
57     public String JavaDoc[] getStatisticNames() {
58         Set keys = map.keySet();
59         String JavaDoc[] answer = new String JavaDoc[keys.size()];
60         keys.toArray(answer);
61         return answer;
62     }
63
64     public Statistic JavaDoc[] getStatistics() {
65         Collection values = map.values();
66         Statistic JavaDoc[] answer = new Statistic JavaDoc[values.size()];
67         values.toArray(answer);
68         return answer;
69     }
70
71     protected void addStatistic(String JavaDoc name, StatisticImpl statistic) {
72         map.put(name, statistic);
73     }
74 }
75
Popular Tags