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 | |
public class AllStatistics |
25 | |
{ |
26 | |
private boolean isStatisticsEnabled; |
27 | |
private long startTime; |
28 | |
|
29 | 392 | private HashMap componentStat = new HashMap(); |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public AllStatistics() |
35 | 392 | { |
36 | 392 | clear(); |
37 | 392 | } |
38 | |
|
39 | |
public void logSummary() |
40 | |
{ |
41 | 0 | logSummary(new SimplePrinter(System.out)); |
42 | 0 | } |
43 | |
|
44 | |
public void logSummary(PrintWriter printer) |
45 | |
{ |
46 | |
|
47 | 0 | if (printer instanceof AbstractTablePrinter) |
48 | |
{ |
49 | 0 | printer.print(componentStat.values()); |
50 | |
} |
51 | |
else |
52 | |
{ |
53 | 0 | Iterator it = componentStat.values().iterator(); |
54 | |
|
55 | 0 | while (it.hasNext()) |
56 | |
{ |
57 | 0 | printer.print(it.next()); |
58 | |
} |
59 | |
} |
60 | |
|
61 | |
|
62 | |
|
63 | 0 | } |
64 | |
|
65 | |
public synchronized void clear() |
66 | |
{ |
67 | |
|
68 | 392 | Iterator it = getComponentStatistics().iterator(); |
69 | |
|
70 | 392 | while (it.hasNext()) |
71 | |
{ |
72 | 0 | ((Statistics) it.next()).clear(); |
73 | |
} |
74 | 392 | startTime = System.currentTimeMillis(); |
75 | 392 | } |
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public boolean isEnabled() |
81 | |
{ |
82 | 44 | return isStatisticsEnabled; |
83 | |
} |
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
public void setEnabled(boolean b) |
89 | |
{ |
90 | 0 | isStatisticsEnabled = b; |
91 | |
|
92 | 0 | Iterator it = componentStat.values().iterator(); |
93 | |
|
94 | 0 | while (it.hasNext()) |
95 | |
{ |
96 | 0 | ((ComponentStatistics) it.next()).setEnabled(b); |
97 | |
} |
98 | 0 | } |
99 | |
|
100 | |
public synchronized long getStartTime() |
101 | |
{ |
102 | 0 | return startTime; |
103 | |
} |
104 | |
|
105 | |
public synchronized void setStartTime(long startTime) |
106 | |
{ |
107 | 0 | this.startTime = startTime; |
108 | 0 | } |
109 | |
|
110 | |
public synchronized void add(ComponentStatistics stat) |
111 | |
{ |
112 | 44 | if (stat != null) |
113 | |
{ |
114 | 44 | componentStat.put(stat.getName(), stat); |
115 | |
} |
116 | 44 | } |
117 | |
|
118 | |
public synchronized void remove(ComponentStatistics stat) |
119 | |
{ |
120 | 38 | if (stat != null) |
121 | |
{ |
122 | 34 | componentStat.remove(stat.getName()); |
123 | |
} |
124 | 38 | } |
125 | |
|
126 | |
public synchronized Collection getComponentStatistics() |
127 | |
{ |
128 | 392 | return componentStat.values(); |
129 | |
} |
130 | |
|
131 | |
} |