001: /*
002: * $Id: StatisticsService.java 11234 2008-03-06 23:44:34Z tcarlson $
003: * --------------------------------------------------------------------------------------
004: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
005: *
006: * The software in this package is published under the terms of the CPAL v1.0
007: * license, a copy of which has been included with this distribution in the
008: * LICENSE.txt file.
009: */
010:
011: package org.mule.module.management.mbean;
012:
013: import org.mule.api.MuleContext;
014: import org.mule.management.stats.AllStatistics;
015: import org.mule.management.stats.printers.CSVPrinter;
016: import org.mule.management.stats.printers.HtmlTablePrinter;
017: import org.mule.management.stats.printers.XMLPrinter;
018:
019: import java.io.StringWriter;
020: import java.util.Collection;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: /**
026: * <code>StatisicsService</code> exposes Mule processing statistics
027: */
028: public class StatisticsService implements StatisticsServiceMBean {
029: /**
030: * Serial version
031: */
032: private static final long serialVersionUID = -4949499389883146363L;
033:
034: /**
035: * logger used by this class
036: */
037: protected static final Log logger = LogFactory
038: .getLog(StatisticsService.class);
039:
040: private AllStatistics stats = new AllStatistics();
041: private MuleContext muleContext = null;
042:
043: public void setMuleContext(MuleContext context) {
044: this .muleContext = context;
045: if (muleContext == null) {
046: stats = new AllStatistics();
047: } else {
048: stats = this .muleContext.getStatistics();
049: }
050:
051: }
052:
053: /**
054: * @see org.mule.api.management.stats.Statistics#clear()
055: */
056: public void clear() {
057: stats.clear();
058: }
059:
060: /**
061: * @see org.mule.api.management.stats.Statistics#isEnabled()
062: */
063: public boolean isEnabled() {
064: return stats.isEnabled();
065: }
066:
067: /**
068: * @see org.mule.api.management.stats.Statistics#setEnabled(boolean)
069: */
070: public void setEnabled(boolean b) {
071: stats.setEnabled(b);
072:
073: }
074:
075: public Collection getComponentStatistics() {
076: return stats.getComponentStatistics();
077: }
078:
079: public void logSummary() {
080: stats.logSummary();
081: }
082:
083: public String printCSVSummary() {
084: StringWriter w = new StringWriter(2048);
085: CSVPrinter printer = new CSVPrinter(w);
086: printer.setPrintHeaders(true);
087: stats.logSummary(printer);
088: return w.toString();
089: }
090:
091: public String printHtmlSummary() {
092: StringWriter w = new StringWriter(8192);
093: HtmlTablePrinter printer = new HtmlTablePrinter(w);
094: stats.logSummary(printer);
095: return w.toString();
096: }
097:
098: public String printXmlSummary() {
099: StringWriter w = new StringWriter(8192);
100: XMLPrinter printer = new XMLPrinter(w);
101: stats.logSummary(printer);
102: return w.toString();
103: }
104:
105: }
|