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