1
2
3
4
5
6
7
8
9
10
11 package org.mule.management.stats;
12
13 import org.mule.api.management.stats.Statistics;
14 import org.mule.management.stats.printers.SimplePrinter;
15
16 import java.io.PrintWriter;
17
18
19
20
21 public class ComponentStatistics implements Statistics
22 {
23
24
25
26 private static final long serialVersionUID = -2086999226732861674L;
27
28 private long minExecutionTime = 0;
29 private long maxExecutionTime = 0;
30 private long averageExecutionTime = 0;
31 private long executedEvent = 0;
32 private long totalExecTime = 0;
33 private boolean enabled = false;
34
35 public void clear()
36 {
37 minExecutionTime = 0;
38 maxExecutionTime = 0;
39 executedEvent = 0;
40 totalExecTime = 0;
41 }
42
43 public boolean isEnabled()
44 {
45 return enabled;
46 }
47
48 public void logSummary()
49 {
50 logSummary(new SimplePrinter(System.out));
51 }
52
53 public void logSummary(PrintWriter printer)
54 {
55 printer.print(this);
56 }
57
58 public void setEnabled(boolean b)
59 {
60 this.enabled = b;
61 }
62
63 public long getMaxExecutionTime()
64 {
65 return maxExecutionTime;
66 }
67
68 public long getMinExecutionTime()
69 {
70 return minExecutionTime;
71 }
72
73 public long getTotalExecutionTime()
74 {
75 return totalExecTime;
76 }
77
78 public long getExecutedEvents()
79 {
80 return executedEvent;
81 }
82
83 public synchronized void addExecutionTime(long time)
84 {
85 executedEvent++;
86
87 totalExecTime += (time == 0 ? 1 : time);
88
89 if (minExecutionTime == 0 || time < minExecutionTime)
90 {
91 minExecutionTime = time;
92 }
93 if (maxExecutionTime == 0 || time > maxExecutionTime)
94 {
95 maxExecutionTime = time;
96 }
97 averageExecutionTime = Math.round(totalExecTime / executedEvent);
98 }
99
100 public long getAverageExecutionTime()
101 {
102 return averageExecutionTime;
103 }
104
105 }