1
2
3
4
5
6
7
8
9
10
11 package org.mule.module.management.mbean;
12
13 import org.mule.api.MuleContext;
14 import org.mule.management.stats.AllStatistics;
15 import org.mule.management.stats.printers.CSVPrinter;
16 import org.mule.management.stats.printers.HtmlTablePrinter;
17 import org.mule.management.stats.printers.XMLPrinter;
18
19 import java.io.StringWriter;
20 import java.util.Collection;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24
25
26
27
28 public class StatisticsService implements StatisticsServiceMBean
29 {
30
31
32
33 private static final long serialVersionUID = -4949499389883146363L;
34
35
36
37
38 protected static final Log logger = LogFactory.getLog(StatisticsService.class);
39
40 private AllStatistics stats = new AllStatistics();
41 private MuleContext muleContext = null;
42
43 public void setMuleContext(MuleContext context)
44 {
45 this.muleContext = context;
46 if (muleContext == null)
47 {
48 stats = new AllStatistics();
49 }
50 else
51 {
52 stats = this.muleContext.getStatistics();
53 }
54
55 }
56
57
58
59
60 public void clear()
61 {
62 stats.clear();
63 }
64
65
66
67
68 public boolean isEnabled()
69 {
70 return stats.isEnabled();
71 }
72
73
74
75
76 public void setEnabled(boolean b)
77 {
78 stats.setEnabled(b);
79
80 }
81
82 public Collection getComponentStatistics()
83 {
84 return stats.getComponentStatistics();
85 }
86
87 public void logSummary()
88 {
89 stats.logSummary();
90 }
91
92 public String printCSVSummary ()
93 {
94 StringWriter w = new StringWriter(2048);
95 CSVPrinter printer = new CSVPrinter(w);
96 printer.setPrintHeaders(true);
97 stats.logSummary(printer);
98 return w.toString();
99 }
100
101 public String printHtmlSummary ()
102 {
103 StringWriter w = new StringWriter(8192);
104 HtmlTablePrinter printer = new HtmlTablePrinter(w);
105 stats.logSummary(printer);
106 return w.toString();
107 }
108
109 public String printXmlSummary()
110 {
111 StringWriter w = new StringWriter(8192);
112 XMLPrinter printer = new XMLPrinter(w);
113 stats.logSummary(printer);
114 return w.toString();
115 }
116
117 }