1
2
3
4
5
6
7
8
9
10
11 package org.mule.management.stats;
12
13 import org.mule.api.processor.ProcessingStrategy;
14 import org.mule.processor.strategy.AsynchronousProcessingStrategy;
15
16 import java.util.concurrent.atomic.AtomicLong;
17
18 public class FlowConstructStatistics extends AbstractFlowConstructStatistics implements QueueStatistics
19 {
20 private static final long serialVersionUID = 5337576392583767442L;
21 private final AtomicLong executionError = new AtomicLong(0);
22 private final AtomicLong fatalError = new AtomicLong(0);
23 private int threadPoolSize = 0;
24 protected final ComponentStatistics flowStatistics = new ComponentStatistics();
25
26
27
28 private long queuedEvent = 0;
29 private long maxQueuedEvent = 0;
30 private long averageQueueSize = 0;
31 private long totalQueuedEvent = 0;
32
33
34 public FlowConstructStatistics(String flowConstructType, String name, ProcessingStrategy processingStrategy)
35 {
36 super(flowConstructType, name);
37 flowStatistics.setEnabled(enabled);
38 if (processingStrategy instanceof AsynchronousProcessingStrategy)
39 {
40 this.threadPoolSize = ((AsynchronousProcessingStrategy) processingStrategy).getMaxThreads();
41 }
42 if (this.getClass() == FlowConstructStatistics.class)
43 {
44 clear();
45 }
46 }
47
48 public FlowConstructStatistics(String flowConstructType, String name, int maxThreadSize)
49 {
50 super(flowConstructType, name);
51 flowStatistics.setEnabled(enabled);
52 this.threadPoolSize = maxThreadSize;
53 if (this.getClass() == FlowConstructStatistics.class)
54 {
55 clear();
56 }
57 }
58
59 public FlowConstructStatistics(String flowConstructType, String name)
60 {
61 this(flowConstructType, name, null);
62 }
63
64
65
66
67 public boolean isEnabled()
68 {
69 return enabled;
70 }
71
72 public void incExecutionError()
73 {
74 executionError.addAndGet(1);
75 }
76
77 public void incFatalError()
78 {
79 fatalError.addAndGet(1);
80 }
81
82
83
84
85 public synchronized void setEnabled(boolean b)
86 {
87 super.setEnabled(b);
88 flowStatistics.setEnabled(enabled);
89 }
90
91 public synchronized void clear()
92 {
93 super.clear();
94
95 executionError.set(0);
96 fatalError.set(0);
97 if (flowStatistics != null)
98 {
99 flowStatistics.clear();
100 }
101 }
102
103 public void addCompleteFlowExecutionTime(long time)
104 {
105 flowStatistics.addCompleteExecutionTime(time);
106 }
107
108 public void addFlowExecutionBranchTime(long time, long total)
109 {
110 flowStatistics.addExecutionBranchTime(time == total, time, total);
111 }
112
113 public long getAverageProcessingTime()
114 {
115 return flowStatistics.getAverageExecutionTime();
116 }
117
118 public long getProcessedEvents()
119 {
120 return flowStatistics.getExecutedEvents();
121 }
122
123 public long getMaxProcessingTime()
124 {
125 return flowStatistics.getMaxExecutionTime();
126 }
127
128 public long getMinProcessingTime()
129 {
130 return flowStatistics.getMinExecutionTime();
131 }
132
133 public long getTotalProcessingTime()
134 {
135 return flowStatistics.getTotalExecutionTime();
136 }
137
138 public long getExecutionErrors()
139 {
140 return executionError.get();
141 }
142
143 public long getFatalErrors()
144 {
145 return fatalError.get();
146 }
147
148 public int getThreadPoolSize()
149 {
150 return threadPoolSize;
151 }
152
153 public synchronized void incQueuedEvent()
154 {
155 queuedEvent++;
156 totalQueuedEvent++;
157 if (queuedEvent > maxQueuedEvent)
158 {
159 maxQueuedEvent = queuedEvent;
160 }
161 averageQueueSize = receivedEventASync.get() / totalQueuedEvent;
162 }
163
164 public synchronized void decQueuedEvent()
165 {
166 queuedEvent--;
167 }
168
169 public synchronized long getAverageQueueSize()
170 {
171 return averageQueueSize;
172 }
173
174 }