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