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