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.Map;
20
21
22
23
24 public class AllStatistics
25 {
26 private boolean isStatisticsEnabled;
27 private long startTime;
28
29 private Map<String, ServiceStatistics> serviceStats = new HashMap<String, ServiceStatistics>();
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(serviceStats.values());
50 }
51 else
52 {
53 for (ServiceStatistics serviceStatistics : serviceStats.values())
54 {
55 printer.print(serviceStatistics);
56 }
57 }
58
59
60
61 }
62
63 public synchronized void clear()
64 {
65 for (ServiceStatistics serviceStatistics : getServiceStatistics())
66 {
67 (serviceStatistics).clear();
68 }
69 startTime = System.currentTimeMillis();
70 }
71
72
73
74
75 public boolean isEnabled()
76 {
77 return isStatisticsEnabled;
78 }
79
80
81
82
83 public void setEnabled(boolean b)
84 {
85 isStatisticsEnabled = b;
86
87 for (ServiceStatistics serviceStatistics : serviceStats.values())
88 {
89 (serviceStatistics).setEnabled(b);
90 }
91 }
92
93 public synchronized long getStartTime()
94 {
95 return startTime;
96 }
97
98 public synchronized void setStartTime(long startTime)
99 {
100 this.startTime = startTime;
101 }
102
103 public synchronized void add(ServiceStatistics stat)
104 {
105 if (stat != null)
106 {
107 serviceStats.put(stat.getName(), stat);
108 }
109 }
110
111 public synchronized void remove(ServiceStatistics stat)
112 {
113 if (stat != null)
114 {
115 serviceStats.remove(stat.getName());
116 }
117 }
118
119
120
121
122 @Deprecated
123 public synchronized Collection<ServiceStatistics> getComponentStatistics()
124 {
125 return serviceStats.values();
126 }
127
128 public synchronized Collection<ServiceStatistics> getServiceStatistics()
129 {
130 return serviceStats.values();
131 }
132 }