Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/activemq/management/StatsImpl.java


1   /**
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * 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   **/
18  package org.activemq.management;
19  
20  import java.util.*;
21  import javax.management.j2ee.statistics.Statistic;
22  import javax.management.j2ee.statistics.Stats;
23  
24  
25  /**
26   * Base class for a Stats implementation
27   *
28   * @version $Revision: 1.1.1.1 $
29   */
30  public class StatsImpl extends StatisticImpl implements Stats, 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[] stats = getStatistics();
44          for (int i = 0, size = stats.length; i < size; i++) {
45              Statistic stat = stats[i];
46              if (stat instanceof Resettable) {
47                  Resettable r = (Resettable) stat;
48                  r.reset();
49              }
50          }
51      }
52  
53      public Statistic getStatistic(String name) {
54          return (Statistic) map.get(name);
55      }
56  
57      public String[] getStatisticNames() {
58          Set keys = map.keySet();
59          String[] answer = new String[keys.size()];
60          keys.toArray(answer);
61          return answer;
62      }
63  
64      public Statistic[] getStatistics() {
65          Collection values = map.values();
66          Statistic[] answer = new Statistic[values.size()];
67          values.toArray(answer);
68          return answer;
69      }
70  
71      protected void addStatistic(String name, StatisticImpl statistic) {
72          map.put(name, statistic);
73      }
74  }