KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > management > stats > AllStatistics


1 /*
2  * $Id: AllStatistics.java 4259 2006-12-14 03:12:07Z 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.stats;
12
13 import org.mule.management.stats.printers.AbstractTablePrinter;
14 import org.mule.management.stats.printers.SimplePrinter;
15
16 import java.io.PrintWriter JavaDoc;
17 import java.util.Collection JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.Iterator JavaDoc;
20
21 /**
22  * <code>AllStatistics</code> todo
23  *
24  * @author <a HREF="mailto:S.Vanmeerhaege@gfdi.be">Vanmeerhaeghe Stéphane </a>
25  * @version $Revision: 4259 $
26  */

27 public class AllStatistics
28 {
29     private boolean isStatisticsEnabled;
30     private long startTime;
31
32     private HashMap JavaDoc componentStat = new HashMap JavaDoc();
33
34     /**
35      *
36      */

37     public AllStatistics()
38     {
39         clear();
40     }
41
42     public void logSummary()
43     {
44         logSummary(new SimplePrinter(System.out));
45     }
46
47     public void logSummary(PrintWriter JavaDoc printer)
48     {
49
50         if (printer instanceof AbstractTablePrinter)
51         {
52             printer.print(componentStat.values());
53         }
54         else
55         {
56             Iterator JavaDoc it = componentStat.values().iterator();
57
58             while (it.hasNext())
59             {
60                 printer.print(it.next());
61             }
62         }
63         // printer.println("-----------------------------");
64
// printer.println("duration (ms): " + (System.currentTimeMillis() -
65
// startTime));
66
}
67
68     public synchronized void clear()
69     {
70
71         Iterator JavaDoc it = getComponentStatistics().iterator();
72
73         while (it.hasNext())
74         {
75             ((Statistics)it.next()).clear();
76         }
77         startTime = System.currentTimeMillis();
78     }
79
80     /**
81      * Are statistics logged
82      */

83     public boolean isEnabled()
84     {
85         return isStatisticsEnabled;
86     }
87
88     /**
89      * Enable statistics logs (this is a dynamic parameter)
90      */

91     public void setEnabled(boolean b)
92     {
93         isStatisticsEnabled = b;
94
95         Iterator JavaDoc it = componentStat.values().iterator();
96
97         while (it.hasNext())
98         {
99             ((ComponentStatistics)it.next()).setEnabled(b);
100         }
101     }
102
103     public synchronized long getStartTime()
104     {
105         return startTime;
106     }
107
108     public synchronized void setStartTime(long startTime)
109     {
110         this.startTime = startTime;
111     }
112
113     public synchronized void add(ComponentStatistics stat)
114     {
115         if (stat != null)
116         {
117             componentStat.put(stat.getName(), stat);
118         }
119     }
120
121     public synchronized void remove(ComponentStatistics stat)
122     {
123         if (stat != null)
124         {
125             componentStat.remove(stat.getName());
126         }
127     }
128
129     public synchronized Collection JavaDoc getComponentStatistics()
130     {
131         return componentStat.values();
132     }
133
134 }
135
Popular Tags