KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > varia > stats > report > ReportGenerator


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

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 JavaDoc;
28 import java.util.Iterator JavaDoc;
29
30 /**
31  * @jmx:mbean extends="org.jboss.system.ServiceMBean"
32  *
33  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
34  * @version <tt>$Revision: 37459 $</tt>
35  */

36 public abstract class ReportGenerator
37    extends ServiceMBeanSupport
38    implements ReportGeneratorMBean
39 {
40    protected ObjectName JavaDoc statsCollector;
41
42    protected String JavaDoc name;
43    protected String JavaDoc description;
44
45    /**
46     * @jmx.managed-attribute
47     */

48    public void setName(String JavaDoc name)
49    {
50       this.name = name;
51    }
52
53    /**
54     * @jmx.managed-attribute
55     */

56    public String JavaDoc getName()
57    {
58       return name;
59    }
60
61    /**
62     * @jmx.managed-attribute
63     */

64    public void setDescription(String JavaDoc description)
65    {
66       this.description = description;
67    }
68
69    /**
70     * @jmx.managed-attribute
71     */

72    public String JavaDoc getDescription()
73    {
74       return description;
75    }
76
77    /**
78     * @jmx.managed-attribute
79     */

80    public void setStatsCollector(ObjectName JavaDoc statsCollector)
81    {
82       this.statsCollector = statsCollector;
83    }
84
85    /**
86     * @jmx.managed-attribute
87     */

88    public ObjectName JavaDoc getStatsCollector()
89    {
90       return statsCollector;
91    }
92
93    public void startService() throws Exception JavaDoc
94    {
95       try
96       {
97          server.invoke(
98             statsCollector,
99             "registerReportGenerator",
100             new Object JavaDoc[]{this},
101             new String JavaDoc[]{ReportGenerator.class.getName()});
102       }
103       catch(Exception JavaDoc e)
104       {
105          log.error("Failed to register report generator.");
106          throw e;
107       }
108    }
109
110    public void stopService() throws Exception JavaDoc
111    {
112       try
113       {
114          server.invoke(statsCollector,
115             "unregisterReportGenerator",
116             new Object JavaDoc[]{this},
117             new String JavaDoc[]{ReportGenerator.class.getName()});
118       }
119       catch(Exception JavaDoc e)
120       {
121          log.error("Failed to unregister report generator.");
122          throw e;
123       }
124    }
125
126    /**
127     * @jmx.managed-operation
128     */

129    public String JavaDoc generate(String JavaDoc reportName) throws Exception JavaDoc
130    {
131       StringBuffer JavaDoc content = new StringBuffer JavaDoc();
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    // Protected
144

145    protected abstract void content(String JavaDoc reportName, StringBuffer JavaDoc buf) throws Exception JavaDoc;
146
147    protected Iterator JavaDoc getReportsIterator()
148       throws Exception JavaDoc
149    {
150       try
151       {
152          return (Iterator JavaDoc) server.invoke(statsCollector, "reportsIterator", new Object JavaDoc[]{}, new String JavaDoc[]{});
153       }
154       catch(Exception JavaDoc e)
155       {
156          log.error("Failed to invoke getReportsIterator() operation.");
157          throw e;
158       }
159    }
160
161    protected TxStatistics getTxStatistics()
162       throws Exception JavaDoc
163    {
164       try
165       {
166          return (TxStatistics) server.invoke(statsCollector, "txStatistics", new Object JavaDoc[]{}, new String JavaDoc[]{});
167       }
168       catch(Exception JavaDoc e)
169       {
170          log.error("Failed to invoke getTxStatistics() operation.");
171          throw e;
172       }
173    }
174 }
175
Popular Tags