1 18 package org.apache.activemq.management; 19 20 import java.util.*; 21 import javax.management.j2ee.statistics.Statistic ; 22 import javax.management.j2ee.statistics.Stats ; 23 24 25 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 } 75 | Popular Tags |