1 22 package org.jboss.varia.stats.report; 23 24 import org.jboss.system.ServiceMBeanSupport; 25 import org.jboss.varia.stats.TxStatistics; 26 27 import javax.management.ObjectName ; 28 import java.util.Iterator ; 29 30 36 public abstract class ReportGenerator 37 extends ServiceMBeanSupport 38 implements ReportGeneratorMBean 39 { 40 protected ObjectName statsCollector; 41 42 protected String name; 43 protected String description; 44 45 48 public void setName(String name) 49 { 50 this.name = name; 51 } 52 53 56 public String getName() 57 { 58 return name; 59 } 60 61 64 public void setDescription(String description) 65 { 66 this.description = description; 67 } 68 69 72 public String getDescription() 73 { 74 return description; 75 } 76 77 80 public void setStatsCollector(ObjectName statsCollector) 81 { 82 this.statsCollector = statsCollector; 83 } 84 85 88 public ObjectName getStatsCollector() 89 { 90 return statsCollector; 91 } 92 93 public void startService() throws Exception 94 { 95 try 96 { 97 server.invoke( 98 statsCollector, 99 "registerReportGenerator", 100 new Object []{this}, 101 new String []{ReportGenerator.class.getName()}); 102 } 103 catch(Exception e) 104 { 105 log.error("Failed to register report generator."); 106 throw e; 107 } 108 } 109 110 public void stopService() throws Exception 111 { 112 try 113 { 114 server.invoke(statsCollector, 115 "unregisterReportGenerator", 116 new Object []{this}, 117 new String []{ReportGenerator.class.getName()}); 118 } 119 catch(Exception e) 120 { 121 log.error("Failed to unregister report generator."); 122 throw e; 123 } 124 } 125 126 129 public String generate(String reportName) throws Exception 130 { 131 StringBuffer content = new StringBuffer (); 132 content.append("<a HREF='HtmlAdaptor?") 133 .append("action=invokeOpByName&name=") 134 .append(statsCollector) 135 .append("&methodName=reports") 136 .append("'>Back to report list</a>"); 137 138 content(reportName, content); 139 140 return content.toString(); 141 } 142 143 145 protected abstract void content(String reportName, StringBuffer buf) throws Exception ; 146 147 protected Iterator getReportsIterator() 148 throws Exception 149 { 150 try 151 { 152 return (Iterator ) server.invoke(statsCollector, "reportsIterator", new Object []{}, new String []{}); 153 } 154 catch(Exception e) 155 { 156 log.error("Failed to invoke getReportsIterator() operation."); 157 throw e; 158 } 159 } 160 161 protected TxStatistics getTxStatistics() 162 throws Exception 163 { 164 try 165 { 166 return (TxStatistics) server.invoke(statsCollector, "txStatistics", new Object []{}, new String []{}); 167 } 168 catch(Exception e) 169 { 170 log.error("Failed to invoke getTxStatistics() operation."); 171 throw e; 172 } 173 } 174 } 175 | Popular Tags |