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