KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > management > stats > ComponentStatistics


1 /*
2  * $Id: ComponentStatistics.java 4259 2006-12-14 03:12:07Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.management.stats;
12
13 import java.io.PrintWriter JavaDoc;
14
15 import org.mule.management.stats.printers.SimplePrinter;
16
17 public class ComponentStatistics implements Statistics
18 {
19     /**
20      * Serial version
21      */

22     private static final long serialVersionUID = -2086999226732861674L;
23
24     private String JavaDoc name;
25     private long totalExecTime = 0;
26     private long receivedEventSync = 0;
27     private long receivedEventASync = 0;
28     private long queuedEvent = 0;
29     private long maxQueuedEvent = 0;
30     private long averageQueueSize = 0;
31     private long totalQueuedEvent = 0;
32     private long sentEventSync = 0;
33     private long sentReplyToEvent = 0;
34     private long sentEventASync = 0;
35     private long executedEvent = 0;
36     private long executionError = 0;
37     private long fatalError = 0;
38     private long minExecutionTime = 0;
39     private long maxExecutionTime = 0;
40     private long averageExecutionTime = 0;
41     private boolean enabled = false;
42     private int componentPoolMaxSize = 0;
43     private int componentPoolAbsoluteMaxSize = 0;
44     private int componentPoolSize = 0;
45     private int threadPoolSize = 0;
46     private long samplePeriod = 0;
47
48     private RouterStatistics inboundRouterStat = null;
49     private RouterStatistics outboundRouterStat = null;
50
51     /**
52      * The constructor
53      *
54      * @param name
55      */

56     public ComponentStatistics(String JavaDoc name, int componentPoolsize, int threadPoolSize)
57     {
58         super();
59         this.name = name;
60         this.componentPoolMaxSize = componentPoolsize;
61         this.componentPoolAbsoluteMaxSize = componentPoolMaxSize;
62         this.threadPoolSize = threadPoolSize;
63         clear();
64     }
65
66     /**
67      * Are statistics logged
68      */

69     public boolean isEnabled()
70     {
71         return enabled;
72     }
73
74     /**
75      * Enable statistics logs (this is a dynamic parameter)
76      */

77     public synchronized void setEnabled(boolean b)
78     {
79         enabled = b;
80
81         if (inboundRouterStat != null)
82         {
83             inboundRouterStat.setEnabled(b);
84         }
85         if (outboundRouterStat != null)
86         {
87             outboundRouterStat.setEnabled(b);
88         }
89     }
90
91     public synchronized void incReceivedEventSync()
92     {
93         receivedEventSync++;
94     }
95
96     public synchronized void incReceivedEventASync()
97     {
98         receivedEventASync++;
99     }
100
101     public synchronized void incExecutionError()
102     {
103         executionError++;
104     }
105
106     public synchronized void incFatalError()
107     {
108         fatalError++;
109     }
110
111     public synchronized void incSentEventSync()
112     {
113         sentEventSync++;
114     }
115
116     public synchronized void incSentEventASync()
117     {
118         sentEventASync++;
119     }
120
121     public synchronized void incSentReplyToEvent()
122     {
123         sentReplyToEvent++;
124     }
125
126     public synchronized void incQueuedEvent()
127     {
128         queuedEvent++;
129         totalQueuedEvent++;
130         if (queuedEvent > maxQueuedEvent)
131         {
132             maxQueuedEvent = queuedEvent;
133         }
134         // if(queuedEvent > 1) {
135
averageQueueSize = Math.round(getAsyncEventsReceived() / totalQueuedEvent);
136         // }
137
}
138
139     public synchronized void decQueuedEvent()
140     {
141         queuedEvent--;
142     }
143
144     public synchronized void addExecutionTime(long time)
145     {
146         executedEvent++;
147
148         totalExecTime += (time == 0 ? 1 : time);
149
150         if (minExecutionTime == 0 || time < minExecutionTime)
151         {
152             minExecutionTime = time;
153         }
154         if (maxExecutionTime == 0 || time > maxExecutionTime)
155         {
156             maxExecutionTime = time;
157         }
158         averageExecutionTime = Math.round(totalExecTime / executedEvent);
159     }
160
161     public long getAverageExecutionTime()
162     {
163         return averageExecutionTime;
164     }
165
166     public long getAverageQueueSize()
167     {
168         return averageQueueSize;
169     }
170
171     public long getMaxQueueSize()
172     {
173         return maxQueuedEvent;
174     }
175
176     public long getMaxExecutionTime()
177     {
178         return maxExecutionTime;
179     }
180
181     public long getFatalErrors()
182     {
183         return fatalError;
184     }
185
186     public long getMinExecutionTime()
187     {
188         return minExecutionTime;
189     }
190
191     public long getTotalExecutionTime()
192     {
193         return totalExecTime;
194     }
195
196     public long getQueuedEvents()
197     {
198         return queuedEvent;
199     }
200
201     public long getAsyncEventsReceived()
202     {
203         return receivedEventASync;
204     }
205
206     public long getSyncEventsReceived()
207     {
208         return receivedEventSync;
209     }
210
211     public long getReplyToEventsSent()
212     {
213         return sentReplyToEvent;
214     }
215
216     public long getSyncEventsSent()
217     {
218         return sentEventSync;
219     }
220
221     public long getAsyncEventsSent()
222     {
223         return sentEventASync;
224     }
225
226     public long getTotalEventsSent()
227     {
228         return getSyncEventsSent() + getAsyncEventsSent();
229     }
230
231     public long getTotalEventsReceived()
232     {
233         return getSyncEventsReceived() + getAsyncEventsReceived();
234     }
235
236     public long getExecutedEvents()
237     {
238         return executedEvent;
239     }
240
241     public long getExecutionErrors()
242     {
243         return executionError;
244     }
245
246     public synchronized String JavaDoc getName()
247     {
248         return name;
249     }
250
251     public synchronized void setName(String JavaDoc name)
252     {
253         this.name = name;
254     }
255
256     /**
257      * log in info level the main statistics
258      */

259     public void logSummary()
260     {
261         logSummary(new SimplePrinter(System.out));
262     }
263
264     public void logSummary(PrintWriter JavaDoc printer)
265     {
266         printer.print(this);
267     }
268
269     public synchronized void clear()
270     {
271
272         componentPoolSize = 0;
273         componentPoolAbsoluteMaxSize = 0;
274         totalExecTime = 0;
275         receivedEventSync = 0;
276         receivedEventASync = 0;
277         queuedEvent = 0;
278         maxQueuedEvent = 0;
279         totalQueuedEvent = 0;
280         averageQueueSize = 0;
281
282         sentEventSync = 0;
283         sentEventASync = 0;
284         sentReplyToEvent = 0;
285
286         executedEvent = 0;
287         executionError = 0;
288         fatalError = 0;
289
290         minExecutionTime = 0;
291         maxExecutionTime = 0;
292
293         if (getInboundRouterStat() != null)
294         {
295             getInboundRouterStat().clear();
296         }
297         if (getOutboundRouterStat() != null)
298         {
299             getOutboundRouterStat().clear();
300         }
301
302         samplePeriod = System.currentTimeMillis();
303
304     }
305
306     /**
307      * @return Returns the inboundRouterStat.
308      */

309     public RouterStatistics getInboundRouterStat()
310     {
311         return inboundRouterStat;
312     }
313
314     /**
315      * @param inboundRouterStat The inboundRouterStat to set.
316      */

317     public void setInboundRouterStat(RouterStatistics inboundRouterStat)
318     {
319         this.inboundRouterStat = inboundRouterStat;
320         this.inboundRouterStat.setEnabled(enabled);
321     }
322
323     /**
324      * @return Returns the outboundRouterStat.
325      */

326     public RouterStatistics getOutboundRouterStat()
327     {
328         return outboundRouterStat;
329     }
330
331     /**
332      * @param outboundRouterStat The outboundRouterStat to set.
333      */

334     public void setOutboundRouterStat(RouterStatistics outboundRouterStat)
335     {
336         this.outboundRouterStat = outboundRouterStat;
337         this.outboundRouterStat.setEnabled(enabled);
338     }
339
340     public int getComponentPoolMaxSize()
341     {
342         return componentPoolMaxSize;
343     }
344
345     public int getComponentPoolAbsoluteMaxSize()
346     {
347         return componentPoolAbsoluteMaxSize;
348     }
349
350     public int getComponentPoolSize()
351     {
352         return componentPoolSize;
353     }
354
355     public synchronized void setComponentPoolSize(int componentPoolSize)
356     {
357         this.componentPoolSize = componentPoolSize;
358         if (componentPoolSize > componentPoolAbsoluteMaxSize)
359         {
360             componentPoolAbsoluteMaxSize = componentPoolSize;
361         }
362     }
363
364     public int getThreadPoolSize()
365     {
366         return threadPoolSize;
367     }
368
369     public long getSamplePeriod()
370     {
371         return System.currentTimeMillis() - samplePeriod;
372     }
373 }
374
Popular Tags