KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > management > mbeans > StatisticsService


1 /*
2  * $Id: StatisticsService.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.management.mbeans;
12
13 import java.io.StringWriter JavaDoc;
14 import java.util.Collection JavaDoc;
15
16 import org.apache.commons.logging.Log;
17 import org.apache.commons.logging.LogFactory;
18 import org.mule.MuleManager;
19 import org.mule.management.stats.AllStatistics;
20 import org.mule.management.stats.printers.CSVPrinter;
21 import org.mule.management.stats.printers.HtmlTablePrinter;
22 import org.mule.umo.manager.UMOManager;
23
24 /**
25  * <code>StatisicsService</code> exposes Mule processing statistics
26  *
27  * @author <a HREF="mailto:S.Vanmeerhaege@gfdi.be">Vanmeerhaeghe Stéphane </a>
28  * @version $Revision: 3798 $
29  */

30 public class StatisticsService implements StatisticsServiceMBean
31 {
32     /**
33      * Serial version
34      */

35     private static final long serialVersionUID = -4949499389883146363L;
36
37     /**
38      * logger used by this class
39      */

40     protected static Log logger = LogFactory.getLog(StatisticsService.class);
41
42     private AllStatistics stats = new AllStatistics();
43     private MuleManager manager = null;
44
45     public void setManager(UMOManager manager)
46     {
47         this.manager = (MuleManager)manager;
48         if (manager == null)
49         {
50             stats = new AllStatistics();
51         }
52         else
53         {
54             stats = this.manager.getStatistics();
55         }
56
57     }
58
59     /**
60      * @see org.mule.management.stats.Statistics#clear()
61      */

62     public void clear()
63     {
64         stats.clear();
65     }
66
67     /**
68      * @see org.mule.management.stats.Statistics#isEnabled()
69      */

70     public boolean isEnabled()
71     {
72         return stats.isEnabled();
73     }
74
75     /**
76      * @see org.mule.management.stats.Statistics#setEnabled(boolean)
77      */

78     public void setEnabled(boolean b)
79     {
80         stats.setEnabled(b);
81
82     }
83
84     public Collection JavaDoc getComponentStatistics()
85     {
86         return stats.getComponentStatistics();
87     }
88
89     public void logSummary()
90     {
91         stats.logSummary();
92     }
93
94     public void logCSVSummary()
95     {
96         CSVPrinter printer = new CSVPrinter(System.out);
97         printer.setPrintHeaders(true);
98         stats.logSummary(printer);
99     }
100
101     /**
102      * @return
103      * @deprecated Use getHtmlSummary
104      */

105     public String JavaDoc printHtmlSummary()
106     {
107         StringWriter JavaDoc w = new StringWriter JavaDoc();
108         HtmlTablePrinter printer = new HtmlTablePrinter(w);
109         stats.logSummary(printer);
110         return w.toString();
111     }
112
113     public String JavaDoc getHtmlSummary()
114     {
115         return printHtmlSummary();
116     }
117 }
118
Popular Tags