1
2
3
4
5
6
7 package org.mule.management.stats;
8
9 import org.mule.management.stats.printers.AbstractTablePrinter;
10 import org.mule.management.stats.printers.SimplePrinter;
11
12 import java.io.PrintWriter;
13 import java.util.Collection;
14 import java.util.HashMap;
15 import java.util.Map;
16
17
18
19
20 public class AllStatistics
21 {
22 private boolean isStatisticsEnabled;
23 private long startTime;
24 private ApplicationStatistics appStats;
25 private Map<String, FlowConstructStatistics> flowConstructStats = new HashMap<String, FlowConstructStatistics>();
26
27
28
29
30 public AllStatistics()
31 {
32 clear();
33 appStats = new ApplicationStatistics(this);
34 appStats.setEnabled(isStatisticsEnabled);
35 add(appStats);
36 }
37
38 public void logSummary()
39 {
40 logSummary(new SimplePrinter(System.out));
41 }
42
43 public void logSummary(PrintWriter printer)
44 {
45
46 if (printer instanceof AbstractTablePrinter)
47 {
48 printer.print(flowConstructStats.values());
49 }
50 else
51 {
52 for (FlowConstructStatistics statistics : flowConstructStats.values())
53 {
54 printer.print(statistics);
55 }
56 }
57
58
59
60 }
61
62 public synchronized void clear()
63 {
64 for (FlowConstructStatistics statistics : getServiceStatistics())
65 {
66 statistics.clear();
67 }
68 startTime = System.currentTimeMillis();
69 }
70
71
72
73
74 public boolean isEnabled()
75 {
76 return isStatisticsEnabled;
77 }
78
79
80
81
82 public void setEnabled(boolean b)
83 {
84 isStatisticsEnabled = b;
85
86 for (FlowConstructStatistics statistics : flowConstructStats.values())
87 {
88 statistics.setEnabled(b);
89 }
90 }
91
92 public synchronized long getStartTime()
93 {
94 return startTime;
95 }
96
97 public synchronized void setStartTime(long startTime)
98 {
99 this.startTime = startTime;
100 }
101
102 public synchronized void add(FlowConstructStatistics stat)
103 {
104 if (stat != null)
105 {
106 flowConstructStats.put(stat.getName(), stat);
107 }
108 }
109
110 public synchronized void remove(FlowConstructStatistics stat)
111 {
112 if (stat != null)
113 {
114 flowConstructStats.remove(stat.getName());
115 }
116 }
117
118
119
120
121 @Deprecated
122 public synchronized Collection<FlowConstructStatistics> getComponentStatistics()
123 {
124 return flowConstructStats.values();
125 }
126
127 public synchronized Collection<FlowConstructStatistics> getServiceStatistics()
128 {
129 return flowConstructStats.values();
130 }
131
132 public FlowConstructStatistics getApplicationStatistics()
133 {
134 return appStats;
135 }
136 }