1 22 package org.jboss.varia.stats; 23 24 import org.jboss.system.ServiceMBeanSupport; 25 import org.jboss.varia.stats.report.ReportGenerator; 26 27 import java.util.Iterator ; 28 import java.util.Set ; 29 import java.util.HashSet ; 30 31 37 public class StatisticsCollector 38 extends ServiceMBeanSupport 39 implements StatisticsCollectorMBean 40 { 41 private final TxStatistics stats = new TxStatistics(); 42 43 private final Set reportGenerators = new HashSet (); 44 45 46 49 public void registerReportGenerator(ReportGenerator reportGenerator) 50 { 51 reportGenerators.add(reportGenerator); 52 } 53 54 57 public void unregisterReportGenerator(ReportGenerator reportGenerator) 58 { 59 reportGenerators.remove(reportGenerator); 60 } 61 62 65 public void clearStatistics() 66 { 67 stats.clear(); 68 } 69 70 73 public void addStatisticalItem(StatisticalItem item) 74 { 75 stats.addStatisticalItem(item); 76 } 77 78 81 public Iterator reportsIterator() 82 { 83 return stats.getReports(); 84 } 85 86 89 public TxStatistics txStatistics() 90 { 91 return stats; 92 } 93 94 97 public synchronized String reports() 98 { 99 StringBuffer buf = new StringBuffer (); 100 101 buf.append("<table><tr><th>Report</th><th>Description</th></tr>"); 102 for(Iterator generators = reportGenerators.iterator(); generators.hasNext();) 103 { 104 ReportGenerator generator = (ReportGenerator)generators.next(); 105 buf.append("<tr><td>") 106 .append("<a HREF='HtmlAdaptor?") 107 .append("action=invokeOpByName&name=") 108 .append(generator.getServiceName()) 109 .append("&methodName=generate&") 110 .append("argType=java.lang.String&arg0=") 111 .append("'>") 112 .append(generator.getName()) 113 .append("</a></td><td>") 114 .append(generator.getDescription()) 115 .append("</td></tr>"); 116 } 117 buf.append("</table>"); 118 119 218 219 return buf.toString(); 220 } 221 } 222 | Popular Tags |