1 22 package org.jboss.management.j2ee.statistics; 23 24 import javax.management.j2ee.statistics.Statistic ; 25 import javax.management.j2ee.statistics.Stats ; 26 import java.io.Serializable ; 27 import java.util.HashMap ; 28 import java.util.Iterator ; 29 import java.util.Map ; 30 31 37 public class StatsBase 38 implements Stats , Serializable 39 { 40 42 43 private static final long serialVersionUID = 384207297746356032L; 44 45 47 51 private Map statistics; 52 53 55 public StatsBase() 56 { 57 statistics = new HashMap (); 58 } 59 60 public StatsBase(Map statistics) 61 { 62 this.statistics = statistics; 63 } 64 65 66 68 73 public String [] getStatisticNames() 74 { 75 String [] names = new String [statistics.size()]; 76 statistics.keySet().toArray(names); 77 return names; 78 } 79 80 85 public Statistic [] getStatistics() 86 { 87 Statistic [] stats = new Statistic [statistics.size()]; 88 statistics.values().toArray(stats); 89 return stats; 90 } 91 92 98 public Statistic getStatistic(String name) 99 { 100 Statistic stat = (Statistic ) statistics.get(name); 101 return stat; 102 } 103 105 108 public void reset() 109 { 110 Iterator iter = statistics.values().iterator(); 111 while (iter.hasNext()) 112 { 113 Object next = iter.next(); 114 if (next instanceof StatisticImpl) 115 { 116 StatisticImpl s = (StatisticImpl) next; 117 s.reset(); 118 } 119 } 120 } 121 122 public String toString() 123 { 124 return this.getClass().getName() + " [ " + statistics + " ]"; 125 } 126 127 133 public void addStatistic(String name, Statistic statistic) 134 { 135 statistics.put(name, statistic); 136 } 137 138 } 139 | Popular Tags |