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