1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
package org.mule.management.stats; |
8 | |
|
9 | |
import org.mule.api.MuleContext; |
10 | |
import org.mule.api.MuleSession; |
11 | |
import org.mule.api.construct.FlowConstruct; |
12 | |
|
13 | |
import java.io.Serializable; |
14 | |
import java.util.concurrent.atomic.AtomicLong; |
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
public class ProcessingTime implements Serializable |
20 | |
{ |
21 | |
|
22 | |
|
23 | |
|
24 | |
|
25 | |
private static final long serialVersionUID = 1L; |
26 | |
|
27 | 0 | private AtomicLong accumulator = new AtomicLong(); |
28 | |
private FlowConstructStatistics statistics; |
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
public static ProcessingTime newInstance(MuleSession session, MuleContext muleContext) |
36 | |
{ |
37 | 0 | if (session != null) |
38 | |
{ |
39 | 0 | FlowConstruct fc = session.getFlowConstruct(); |
40 | 0 | if (fc != null) |
41 | |
{ |
42 | 0 | FlowConstructStatistics stats = fc.getStatistics(); |
43 | 0 | if (stats != null && fc.getStatistics().isEnabled()) |
44 | |
{ |
45 | 0 | return new ProcessingTime(stats, muleContext); |
46 | |
} |
47 | |
} |
48 | |
|
49 | |
} |
50 | |
|
51 | 0 | return null; |
52 | |
} |
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
private ProcessingTime(FlowConstructStatistics stats, MuleContext muleContext) |
61 | 0 | { |
62 | 0 | this.statistics = stats; |
63 | 0 | ProcessingTimeWatcher processorTimeWatcher = muleContext.getProcessorTimeWatcher(); |
64 | 0 | processorTimeWatcher.addProcessingTime(this); |
65 | 0 | } |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public void addFlowExecutionBranchTime(long startTime) |
73 | |
{ |
74 | 0 | if (statistics.isEnabled()) |
75 | |
{ |
76 | 0 | long elapsedTime = getEffectiveTime(System.currentTimeMillis() - startTime); |
77 | 0 | statistics.addFlowExecutionBranchTime(elapsedTime, accumulator.addAndGet(elapsedTime)); |
78 | |
} |
79 | 0 | } |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
public static long getEffectiveTime(long time) |
86 | |
{ |
87 | 0 | return (time <= 0) ? 1L : time; |
88 | |
} |
89 | |
|
90 | |
public FlowConstructStatistics getStatistics() |
91 | |
{ |
92 | 0 | return statistics; |
93 | |
} |
94 | |
|
95 | |
public AtomicLong getAccumulator() |
96 | |
{ |
97 | 0 | return accumulator; |
98 | |
} |
99 | |
} |