1
2
3
4
5
6
7
8
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;
17 import java.util.Collection;
18 import java.util.HashMap;
19 import java.util.Iterator;
20
21
22
23
24
25
26
27 public class AllStatistics
28 {
29 private boolean isStatisticsEnabled;
30 private long startTime;
31
32 private HashMap componentStat = new HashMap();
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 printer)
48 {
49
50 if (printer instanceof AbstractTablePrinter)
51 {
52 printer.print(componentStat.values());
53 }
54 else
55 {
56 Iterator it = componentStat.values().iterator();
57
58 while (it.hasNext())
59 {
60 printer.print(it.next());
61 }
62 }
63
64
65
66 }
67
68 public synchronized void clear()
69 {
70
71 Iterator it = getComponentStatistics().iterator();
72
73 while (it.hasNext())
74 {
75 ((Statistics) it.next()).clear();
76 }
77 startTime = System.currentTimeMillis();
78 }
79
80
81
82
83 public boolean isEnabled()
84 {
85 return isStatisticsEnabled;
86 }
87
88
89
90
91 public void setEnabled(boolean b)
92 {
93 isStatisticsEnabled = b;
94
95 Iterator 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 getComponentStatistics()
130 {
131 return componentStat.values();
132 }
133
134 }