Source Code Cross Referenced for MessagingStatistics.java in  » ESB » open-esb » com » sun » jbi » messaging » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » open esb » com.sun.jbi.messaging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)MessagingStatistics.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.messaging;
030:
031:        import java.util.Date;
032:        import javax.management.openmbean.CompositeData;
033:        import javax.management.openmbean.CompositeDataSupport;
034:        import javax.management.openmbean.CompositeType;
035:        import javax.management.openmbean.OpenType;
036:        import javax.management.openmbean.SimpleType;
037:
038:        /**
039:         * This class provides methods for creation and retrieval of messaging
040:         * statistics in the message service.
041:         *
042:         * @author Sun Microsystems, Inc.
043:         */
044:        public class MessagingStatistics {
045:            /**
046:             * Count of the current number of active Message Exchanges.
047:             */
048:            private int mActiveExchanges;
049:
050:            /**
051:             * Count of the total number of InOnly Message Exchanges created since the
052:             * last component or message service startup.
053:             */
054:            private long mInOnlyExchanges;
055:
056:            /**
057:             * Count of the total number of RobustInOnly Message Exchanges created since
058:             * the last component or message service startup.
059:             */
060:            private long mRobustInOnlyExchanges;
061:
062:            /**
063:             * Count of the total number of InOptionalOut Message Exchanges created
064:             * since the last component or message service startup.
065:             */
066:            private long mInOptionalOutExchanges;
067:
068:            /**
069:             * Count of the total number of InOut Message Exchanges created since the
070:             * last component or message service startup.
071:             */
072:            private long mInOutExchanges;
073:
074:            /**
075:             * Running total of times from the creation to the closing of all Message
076:             * Exchanges. This is used to compute the mean time to close an ME.
077:             */
078:            private long mTotalExchangeTimeToClose;
079:
080:            /**
081:             * Count of the total number of failed Message Exchanges since the last
082:             * component or message service startup.
083:             */
084:            private long mFailedExchanges;
085:
086:            /**
087:             * Count of the total number of transacted Message Exchanges since the last
088:             * component or message service startup.
089:             */
090:            private long mTransactedExchanges;
091:
092:            /**
093:             * Count of the Message Exchange send's since the last
094:             * component or message service startup.
095:             */
096:            private long mSends;
097:
098:            /**
099:             * Count of the Message Exchange sendSync's since the last
100:             * component or message service startup.
101:             */
102:            private long mSendSyncs;
103:
104:            /**
105:             * Count of the Message Exchange accept's since the last
106:             * component or message service startup.
107:             */
108:            private long mAccepts;
109:
110:            /**
111:             * Count of the Message Exchange acceptTimeout's since the last
112:             * component or message service startup.
113:             */
114:            private long mAcceptTimeouts;
115:
116:            /**
117:             * Count of the Message Exchange completed with a Fault since the last
118:             * component or message service startup.
119:             */
120:            private long mFaultedExchanges;
121:
122:            /**
123:             * Time of last restart of either the component or the message service.
124:             */
125:            private Date mLastRestartTime;
126:
127:            /**
128:             * Constant used to compute percentages.
129:             */
130:            private static final int ONE_HUNDRED = 100;
131:
132:            /**
133:             * Constant used to compute rates.
134:             */
135:            private static final int MILLISECONDS_PER_HOUR = 3600000;
136:
137:            /**
138:             * Constant used to compute rates.
139:             */
140:            private static final int MILLISECONDS_PER_MINUTE = 60000;
141:
142:            /**
143:             * List of item names for CompositeData construction.
144:             */
145:            private static final String[] ITEM_NAMES = { "ActiveExchanges",
146:                    "ActiveExchangeRate", "InOnlyExchanges",
147:                    "RobustInOnlyExchanges", "InOptionalOutExchanges",
148:                    "InOutExchanges", "ExchangeMeanTimeToClose",
149:                    "ExchangeSuccessRate", "FailedExchanges",
150:                    "TransactedExchanges", "FaultedExchanges", "SentExchanges",
151:                    "SynchronousSentExchanges", "AcceptExchanges",
152:                    "AcceptExchangesTimeout" };
153:
154:            /**
155:             * List of descriptions of items for ComponsiteData construction.
156:             */
157:            private static final String ITEM_DESCRIPTIONS[] = {
158:                    "Number of message exchanges currently active",
159:                    "Current rate of active exchanges per hour",
160:                    "Total number of InOnly message exchanges processed",
161:                    "Total number of RobustInOnly message exchanges processed",
162:                    "Total number of InOptionalOut message exchanges processed",
163:                    "Total number of InOut message exchanges  processed",
164:                    "Mean time to close a message exchange",
165:                    "Message exchange success rate",
166:                    "Total number of failed message exchanges",
167:                    "Total number of transacted message exchanges",
168:                    "Total number of faulted message exchanges",
169:                    "Total number of message exchange send operations",
170:                    "Total number of message exchange sendSync operations",
171:                    "Total number of message exchange accept operations",
172:                    "Total number of message exchange accept timeouts" };
173:
174:            /**
175:             * List of types of items for CompositeData construction.
176:             */
177:            private static final OpenType ITEM_TYPES[] = { SimpleType.INTEGER,
178:                    SimpleType.DOUBLE, SimpleType.LONG, SimpleType.LONG,
179:                    SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
180:                    SimpleType.FLOAT, SimpleType.LONG, SimpleType.LONG,
181:                    SimpleType.LONG, SimpleType.LONG, SimpleType.LONG,
182:                    SimpleType.LONG, SimpleType.LONG };
183:
184:            /**
185:             * CompositeType used to describe CompositeData representing messaging
186:             * statistics.
187:             */
188:            private static CompositeType sMessagingStatisticsType;
189:
190:            /**
191:             * Static initializer.
192:             */
193:            {
194:                try {
195:                    sMessagingStatisticsType = new CompositeType(
196:                            "MessagingStatistics",
197:                            "Message exchange statistics", ITEM_NAMES,
198:                            ITEM_DESCRIPTIONS, ITEM_TYPES);
199:                } catch (javax.management.openmbean.OpenDataException odEx) {
200:                    ; // ignore this for now
201:                }
202:            }
203:
204:            //
205:            // Methods to retrieve statistics.
206:            //
207:
208:            /**
209:             * Get the time of the last restart of the associated entity.
210:             * @return The last restart time.
211:             */
212:            public Date getLastRestartTime() {
213:                return mLastRestartTime;
214:            }
215:
216:            /**
217:             * Get the current number of active message exchanges.
218:             * @return The number of active message exchanges.
219:             */
220:            public Integer getActiveExchanges() {
221:                return new Integer(mActiveExchanges);
222:            }
223:
224:            /**
225:             * Get the current active message exchange rate per hour.
226:             * @return The number of active message exchanges per hour.
227:             */
228:            public Double getActiveExchangeRate() {
229:                // Compute the total number of MessageExchanges
230:                double totalExchanges = mInOnlyExchanges
231:                        + mRobustInOnlyExchanges + mInOptionalOutExchanges
232:                        + mInOutExchanges;
233:
234:                // Compute the number of hours since the component started
235:                long totalTime = new Date().getTime()
236:                        - mLastRestartTime.getTime();
237:                double totalHours = totalTime / MILLISECONDS_PER_HOUR;
238:
239:                // Compute exchange rate.
240:                double exchangeRate = 0;
241:                if (0 < totalExchanges && 0 < totalHours) {
242:                    exchangeRate = totalExchanges / totalHours;
243:                }
244:
245:                return new Double(exchangeRate);
246:            }
247:
248:            /**
249:             * Get the total number of InOnly Message Exchanges created since the
250:             * last message service startup.
251:             * @return The number of InOnly MEs.
252:             */
253:            public Long getInOnlyExchanges() {
254:                return new Long(mInOnlyExchanges);
255:            }
256:
257:            /**
258:             * Get the total number of RobustInOnly Message Exchanges created since the
259:             * last message service startup.
260:             * @return The number of RobustInOnly MEs.
261:             */
262:            public Long getRobustInOnlyExchanges() {
263:                return new Long(mRobustInOnlyExchanges);
264:            }
265:
266:            /**
267:             * Get the total number of InOptionalOut Message Exchanges created since the
268:             * last message service startup.
269:             * @return The number of InOptionalOut MEs.
270:             */
271:            public Long getInOptionalOutExchanges() {
272:                return new Long(mInOptionalOutExchanges);
273:            }
274:
275:            /**
276:             * Get the total number of InOut Message Exchanges created since the
277:             * last message service startup.
278:             * @return The number of InOut MEs.
279:             */
280:            public Long getInOutExchanges() {
281:                return new Long(mInOutExchanges);
282:            }
283:
284:            /**
285:             * Get the total number of Message Exchanges of all types created since the 
286:             * last message service startup.
287:             * @return The total number of MEs.
288:             */
289:            public Long getTotalExchanges() {
290:                return new Long(mInOnlyExchanges + mRobustInOnlyExchanges
291:                        + mInOptionalOutExchanges + mInOutExchanges);
292:            }
293:
294:            /**
295:             * Get the total time from the creation to the closing of all Message
296:             * Exchanges.
297:             * @return The total time to close for all MEs.
298:             */
299:            public long getTotalExchangeTimeToClose() {
300:                return mTotalExchangeTimeToClose;
301:            }
302:
303:            /**
304:             * Get the average time from the creation to the closing of a Message
305:             * Exchange.
306:             * @return The mean time to close an ME.
307:             */
308:            public Long getExchangeMeanTimeToClose() {
309:                // Compute the total number of MessageExchanges
310:                long totalTime = mTotalExchangeTimeToClose;
311:                long totalExchanges = mInOnlyExchanges + mRobustInOnlyExchanges
312:                        + mInOptionalOutExchanges + mInOutExchanges;
313:                long meanTime = 0;
314:                if (0 < totalExchanges) {
315:                    meanTime = totalTime / totalExchanges;
316:                }
317:                return new Long(meanTime);
318:            }
319:
320:            /**
321:             * Get the total number of failed Message Exchanges since the last message
322:             * service startup.
323:             * @return The number of failed MEs.
324:             */
325:            public Long getFailedExchanges() {
326:                return new Long(mFailedExchanges);
327:            }
328:
329:            /**
330:             * Get the total number of faulted Message Exchanges since the last message
331:             * service startup.
332:             * @return The number of failed MEs.
333:             */
334:            public Long getFaultedExchanges() {
335:                return new Long(mFaultedExchanges);
336:            }
337:
338:            /**
339:             * Get the total number of  Message Exchange send operations since the last message
340:             * service startup.
341:             * @return The number of failed MEs.
342:             */
343:            public Long getSendExchanges() {
344:                return new Long(mSends);
345:            }
346:
347:            /**
348:             * Get the total number of Message Exchange sendSync operations since the last message
349:             * service startup.
350:             * @return The number of failed MEs.
351:             */
352:            public Long getSendSyncExchanges() {
353:                return new Long(mSendSyncs);
354:            }
355:
356:            /**
357:             * Get the total number of Message Exchange accept operations since the last message
358:             * service startup.
359:             * @return The number of failed MEs.
360:             */
361:            public Long getAcceptExchanges() {
362:                return new Long(mAccepts);
363:            }
364:
365:            /**
366:             * Get the total number of Message Exchange accept timeout operations since the last message
367:             * service startup.
368:             * @return The number of failed MEs.
369:             */
370:            public Long getAcceptTimeoutExchanges() {
371:                return new Long(mAcceptTimeouts);
372:            }
373:
374:            /**
375:             * Get the total number of transacted Message Exchanges since the last 
376:             * message service startup.
377:             * @return The number of transacted MEs.
378:             */
379:            public Long getTransactedExchanges() {
380:                return new Long(mTransactedExchanges);
381:            }
382:
383:            /**
384:             * Get the success rate for Message Exchanges, as a percentage.
385:             * @return The percentage of MEs that were successful.
386:             */
387:            public Float getExchangeSuccessRate() {
388:                // Compute the total number of MessageExchanges
389:                if (0 == mFailedExchanges) {
390:                    return new Float(ONE_HUNDRED);
391:                } else {
392:                    long failedExchanges = mFailedExchanges;
393:                    long totalExchanges = mInOnlyExchanges
394:                            + mRobustInOnlyExchanges + mInOptionalOutExchanges
395:                            + mInOutExchanges;
396:                    float successRate = ((totalExchanges - failedExchanges) / totalExchanges)
397:                            * ONE_HUNDRED;
398:                    return new Float(successRate);
399:                }
400:            }
401:
402:            //
403:            // Methods to update statistics.
404:            //
405:
406:            /**
407:             * Decrement the current number of active message exchanges.
408:             */
409:            public synchronized void decrementActiveExchanges() {
410:                --mActiveExchanges;
411:            }
412:
413:            /**
414:             * Increment the current number of active message exchanges.
415:             */
416:            public synchronized void incrementActiveExchanges() {
417:                ++mActiveExchanges;
418:            }
419:
420:            /**
421:             * Increment the total number of InOnly Message Exchanges created since the
422:             * last message service startup.
423:             */
424:            public synchronized void incrementInOnlyExchanges() {
425:                ++mInOnlyExchanges;
426:            }
427:
428:            /**
429:             * Increment the total number of RobustInOnly Message Exchanges created
430:             * since the last message service startup.
431:             */
432:            public synchronized void incrementRobustInOnlyExchanges() {
433:                ++mRobustInOnlyExchanges;
434:            }
435:
436:            /**
437:             * Increment the total number of InOptionalOut Message Exchanges created
438:             * since the last message service startup.
439:             */
440:            public synchronized void incrementInOptionalOutExchanges() {
441:                ++mInOptionalOutExchanges;
442:            }
443:
444:            /**
445:             * Increment the total number of InOut Message Exchanges created since the
446:             * last message service startup.
447:             */
448:            public synchronized void incrementInOutExchanges() {
449:                ++mInOutExchanges;
450:            }
451:
452:            /**
453:             * Add the time to close a Message Exchange to the running total used to
454:             * compute the average.
455:             * @param timeToClose The time to close an ME in milliseconds.
456:             */
457:            public synchronized void addTotalExchangeTimeToClose(
458:                    long timeToClose) {
459:                mTotalExchangeTimeToClose += timeToClose;
460:            }
461:
462:            /**
463:             * Increment the total number of failed Message Exchanges since the last
464:             * message service startup.
465:             */
466:            public synchronized void incrementFailedExchanges() {
467:                ++mFailedExchanges;
468:            }
469:
470:            /**
471:             * Increment the total number of transacted Message Exchanges since the last
472:             * message service startup.
473:             */
474:            public synchronized void incrementTransactedExchanges() {
475:                ++mTransactedExchanges;
476:            }
477:
478:            /**
479:             * Set the time of the last restart of the associated entity (component or
480:             * message service);
481:             */
482:            public synchronized void setLastRestartTime(Date restartTime) {
483:                mLastRestartTime = restartTime;
484:            }
485:
486:            /**
487:             * Increment the total number of Message Exchange send operations since the last
488:             * message service startup.
489:             */
490:            public synchronized void incrementSends() {
491:                mSends++;
492:            }
493:
494:            /**
495:             * Increment the total number of Message Exchange sendSync operations since the last
496:             * message service startup.
497:             */
498:            public synchronized void incrementSendSyncs() {
499:                mSendSyncs++;
500:            }
501:
502:            /**
503:             * Increment the total number of Message Exchange accept operations since the last
504:             * message service startup.
505:             */
506:            public synchronized void incrementAccepts() {
507:                mAccepts++;
508:            }
509:
510:            /**
511:             * Increment the total number of Message Exchange accept timeout operations since the last
512:             * message service startup.
513:             */
514:            public synchronized void incrementAcceptTimeouts() {
515:                mAcceptTimeouts++;
516:            }
517:
518:            /**
519:             * Increment the total number of faulted Message Exchanges since the last
520:             * message service startup.
521:             */
522:            public synchronized void incrementFaults() {
523:                mFaultedExchanges++;
524:            }
525:
526:            /**
527:             * Reset all statistics.
528:             */
529:            public synchronized void resetStatistics() {
530:                mActiveExchanges = 0;
531:                mInOnlyExchanges = 0;
532:                mRobustInOnlyExchanges = 0;
533:                mInOptionalOutExchanges = 0;
534:                mInOutExchanges = 0;
535:                mTotalExchangeTimeToClose = 0;
536:                mFailedExchanges = 0;
537:                mTransactedExchanges = 0;
538:                mSends = 0;
539:                mSendSyncs = 0;
540:                mAccepts = 0;
541:                mAcceptTimeouts = 0;
542:                mFaultedExchanges = 0;
543:                mLastRestartTime = new Date();
544:            }
545:
546:            /**
547:             * Convert this instance to a CompositeData type.
548:             */
549:            public CompositeData toCompositeData()
550:                    throws javax.management.openmbean.OpenDataException {
551:                Object values[] = { getActiveExchanges(),
552:                        getActiveExchangeRate(), getInOnlyExchanges(),
553:                        getRobustInOnlyExchanges(),
554:                        getInOptionalOutExchanges(), getInOutExchanges(),
555:                        getExchangeMeanTimeToClose(), getExchangeSuccessRate(),
556:                        getFailedExchanges(), getTransactedExchanges(),
557:                        getFaultedExchanges(), getSendExchanges(),
558:                        getSendSyncExchanges(), getAcceptExchanges(),
559:                        getAcceptTimeoutExchanges() };
560:
561:                return new CompositeDataSupport(sMessagingStatisticsType,
562:                        ITEM_NAMES, values);
563:            }
564:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.