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 | 28 | public class StatisticsService implements StatisticsServiceMBean |
29 | |
{ |
30 | |
|
31 | |
|
32 | |
|
33 | |
private static final long serialVersionUID = -4949499389883146363L; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 12 | protected static final Log logger = LogFactory.getLog(StatisticsService.class); |
39 | |
|
40 | 28 | private AllStatistics stats = new AllStatistics(); |
41 | 28 | private MuleContext muleContext = null; |
42 | |
|
43 | |
public void setMuleContext(MuleContext context) |
44 | |
{ |
45 | 22 | this.muleContext = context; |
46 | 22 | if (muleContext == null) |
47 | |
{ |
48 | 0 | stats = new AllStatistics(); |
49 | |
} |
50 | |
else |
51 | |
{ |
52 | 22 | stats = this.muleContext.getStatistics(); |
53 | |
} |
54 | |
|
55 | 22 | } |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
public void clear() |
61 | |
{ |
62 | 0 | stats.clear(); |
63 | 0 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public boolean isEnabled() |
69 | |
{ |
70 | 0 | return stats.isEnabled(); |
71 | |
} |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public void setEnabled(boolean b) |
77 | |
{ |
78 | 22 | stats.setEnabled(b); |
79 | |
|
80 | 22 | } |
81 | |
|
82 | |
public Collection getComponentStatistics() |
83 | |
{ |
84 | 0 | return stats.getComponentStatistics(); |
85 | |
} |
86 | |
|
87 | |
public void logSummary() |
88 | |
{ |
89 | 0 | stats.logSummary(); |
90 | 0 | } |
91 | |
|
92 | |
public String printCSVSummary () |
93 | |
{ |
94 | 0 | StringWriter w = new StringWriter(2048); |
95 | 0 | CSVPrinter printer = new CSVPrinter(w); |
96 | 0 | printer.setPrintHeaders(true); |
97 | 0 | stats.logSummary(printer); |
98 | 0 | return w.toString(); |
99 | |
} |
100 | |
|
101 | |
public String printHtmlSummary () |
102 | |
{ |
103 | 0 | StringWriter w = new StringWriter(8192); |
104 | 0 | HtmlTablePrinter printer = new HtmlTablePrinter(w); |
105 | 0 | stats.logSummary(printer); |
106 | 0 | return w.toString(); |
107 | |
} |
108 | |
|
109 | |
public String printXmlSummary() |
110 | |
{ |
111 | 0 | StringWriter w = new StringWriter(8192); |
112 | 0 | XMLPrinter printer = new XMLPrinter(w); |
113 | 0 | stats.logSummary(printer); |
114 | 0 | return w.toString(); |
115 | |
} |
116 | |
|
117 | |
} |