package org.jboss.varia.stats.report;
import org.jboss.system.ServiceMBeanSupport;
import org.jboss.varia.stats.TxStatistics;
import javax.management.ObjectName;
import java.util.Iterator;
public abstract class ReportGenerator
extends ServiceMBeanSupport
implements ReportGeneratorMBean
{
protected ObjectName statsCollector;
protected String name;
protected String description;
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setDescription(String description)
{
this.description = description;
}
public String getDescription()
{
return description;
}
public void setStatsCollector(ObjectName statsCollector)
{
this.statsCollector = statsCollector;
}
public ObjectName getStatsCollector()
{
return statsCollector;
}
public void startService() throws Exception
{
try
{
server.invoke(
statsCollector,
"registerReportGenerator",
new Object[]{this},
new String[]{ReportGenerator.class.getName()});
}
catch(Exception e)
{
log.error("Failed to register report generator.");
throw e;
}
}
public void stopService() throws Exception
{
try
{
server.invoke(statsCollector,
"unregisterReportGenerator",
new Object[]{this},
new String[]{ReportGenerator.class.getName()});
}
catch(Exception e)
{
log.error("Failed to unregister report generator.");
throw e;
}
}
public String generate(String reportName) throws Exception
{
StringBuffer content = new StringBuffer();
content.append("<a href='HtmlAdaptor?")
.append("action=invokeOpByName&name=")
.append(statsCollector)
.append("&methodName=reports")
.append("'>Back to report list</a>");
content(reportName, content);
return content.toString();
}
protected abstract void content(String reportName, StringBuffer buf) throws Exception;
protected Iterator getReportsIterator()
throws Exception
{
try
{
return (Iterator) server.invoke(statsCollector, "reportsIterator", new Object[]{}, new String[]{});
}
catch(Exception e)
{
log.error("Failed to invoke getReportsIterator() operation.");
throw e;
}
}
protected TxStatistics getTxStatistics()
throws Exception
{
try
{
return (TxStatistics) server.invoke(statsCollector, "txStatistics", new Object[]{}, new String[]{});
}
catch(Exception e)
{
log.error("Failed to invoke getTxStatistics() operation.");
throw e;
}
}
}