Source Code Cross Referenced for EndPointStatisticsStack.java in  » ESB » synapse » org » apache » synapse » statistics » impl » 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 » synapse » org.apache.synapse.statistics.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one
003:         *  or more contributor license agreements.  See the NOTICE file
004:         *  distributed with this work for additional information
005:         *  regarding copyright ownership.  The ASF licenses this file
006:         *  to you under the Apache License, Version 2.0 (the
007:         *  "License"); you may not use this file except in compliance
008:         *  with the License.  You may obtain a copy of the License at
009:         *
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         *  Unless required by applicable law or agreed to in writing,
013:         *  software distributed under the License is distributed on an
014:         *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         *  KIND, either express or implied.  See the License for the
016:         *  specific language governing permissions and limitations
017:         *  under the License.
018:         */
019:        package org.apache.synapse.statistics.impl;
020:
021:        import org.apache.synapse.statistics.StatisticsStack;
022:        import org.apache.synapse.statistics.StatisticsCollector;
023:        import java.util.Iterator;
024:        import java.util.ArrayList;
025:        import java.util.List;
026:
027:        /**
028:         * The data structure to hold statistics related to the endpoints
029:         *
030:         */
031:
032:        public class EndPointStatisticsStack implements  StatisticsStack {
033:
034:            /** list of endpoint statistics */
035:            private List endpointStatistics;
036:            /** To decide whether the reporting of the in flow statistics have been completed*/
037:            private boolean isCompleteInFlowStatisicsReport = false;
038:
039:            /**
040:             * To put statistics
041:             * @param key                   - The name of the End Point
042:             * @param initTime
043:             * @param isInFlow
044:             * @param isStatisticsEnable
045:             * @param isFault
046:             */
047:            public void put(String key, long initTime, boolean isInFlow,
048:                    boolean isStatisticsEnable, boolean isFault) {
049:                if (endpointStatistics == null) {
050:                    endpointStatistics = new ArrayList();
051:                }
052:                endpointStatistics.add(new EndPointStatistics(key, initTime,
053:                        isInFlow, isStatisticsEnable, isFault));
054:            }
055:
056:            /**
057:             * This method used to report the latest  statistics to the StatisticsCollector
058:             * @param statisticsCollector
059:             * @param isFault
060:             */
061:
062:            public void reportToStatisticsCollector(
063:                    StatisticsCollector statisticsCollector, boolean isFault) {
064:                if (endpointStatistics != null && !endpointStatistics.isEmpty()) {
065:                    EndPointStatistics statistics = (EndPointStatistics) endpointStatistics
066:                            .get(endpointStatistics.size() - 1);
067:                    if (statistics != null && statistics.isStatisticsEnable
068:                            && statistics.endPointName != null) {
069:                        if (statistics.inTimeForInFlow != -1) {
070:                            long initTimeForOutFlow = System
071:                                    .currentTimeMillis();
072:                            statisticsCollector.reportForEndPoint(
073:                                    statistics.endPointName, false,
074:                                    statistics.inTimeForInFlow,
075:                                    initTimeForOutFlow, isFault);
076:                            statistics.inTimeForInFlow = -1;
077:                            statistics.inTimeForOutFlow = initTimeForOutFlow;
078:                        } else if (statistics.inTimeForOutFlow != -1
079:                                && isCompleteInFlowStatisicsReport) {
080:                            statisticsCollector.reportForEndPoint(
081:                                    statistics.endPointName, true,
082:                                    statistics.inTimeForOutFlow, System
083:                                            .currentTimeMillis(), isFault);
084:                            endpointStatistics.remove(statistics);
085:                        }
086:                    }
087:                }
088:            }
089:
090:            /**
091:             * Report a particular statistics to the StatisticsCollector
092:             * @param statisticsCollector
093:             * @param isFault
094:             * @param name
095:             */
096:            public void reportToStatisticsCollector(
097:                    StatisticsCollector statisticsCollector, boolean isFault,
098:                    String name) {
099:                if (endpointStatistics != null && !endpointStatistics.isEmpty()) {
100:                    List tobeRemoved = new ArrayList();
101:                    for (Iterator epIterator = endpointStatistics.iterator(); epIterator
102:                            .hasNext();) {
103:                        Object statisticsObj = epIterator.next();
104:                        if (statisticsObj instanceof  EndPointStatistics) {
105:                            EndPointStatistics statistics = (EndPointStatistics) statisticsObj;
106:                            if (statistics.isStatisticsEnable
107:                                    && statistics.endPointName != null
108:                                    && statistics.endPointName.equals(name)) {
109:                                if (statistics.inTimeForInFlow != -1) {
110:                                    long initTimeForOutFlow = System
111:                                            .currentTimeMillis();
112:                                    statisticsCollector.reportForEndPoint(
113:                                            statistics.endPointName, false,
114:                                            statistics.inTimeForInFlow,
115:                                            initTimeForOutFlow, isFault);
116:                                    statistics.inTimeForInFlow = -1;
117:                                    statistics.inTimeForOutFlow = initTimeForOutFlow;
118:                                } else if (statistics.inTimeForOutFlow != -1
119:                                        && isCompleteInFlowStatisicsReport) {
120:                                    statisticsCollector.reportForEndPoint(
121:                                            statistics.endPointName, true,
122:                                            statistics.inTimeForOutFlow, System
123:                                                    .currentTimeMillis(),
124:                                            isFault);
125:                                    tobeRemoved.add(statistics);
126:                                }
127:                            }
128:                        }
129:                    }
130:                    endpointStatistics.removeAll(tobeRemoved);
131:                }
132:            }
133:
134:            /**
135:             * This method  used to unreported all statistics to the StatisticsCollector
136:             * @param statisticsCollector
137:             */
138:            public void reportAllToStatisticsCollector(
139:                    StatisticsCollector statisticsCollector, boolean isFault) {
140:                if (endpointStatistics != null && !endpointStatistics.isEmpty()) {
141:                    List tobeRemoved = new ArrayList();
142:                    for (Iterator epIterator = endpointStatistics.iterator(); epIterator
143:                            .hasNext();) {
144:                        Object statisticsObj = epIterator.next();
145:                        if (statisticsObj instanceof  EndPointStatistics) {
146:                            EndPointStatistics statistics = (EndPointStatistics) statisticsObj;
147:                            if (statistics.isStatisticsEnable
148:                                    && statistics.endPointName != null) {
149:                                if (statistics.inTimeForInFlow != -1) {
150:                                    long initTimeForOutFlow = System
151:                                            .currentTimeMillis();
152:                                    statisticsCollector.reportForEndPoint(
153:                                            statistics.endPointName, false,
154:                                            statistics.inTimeForInFlow,
155:                                            initTimeForOutFlow, isFault);
156:                                    statistics.inTimeForInFlow = -1;
157:                                    statistics.inTimeForOutFlow = initTimeForOutFlow;
158:                                } else if (statistics.inTimeForOutFlow != -1
159:                                        && isCompleteInFlowStatisicsReport) {
160:                                    statisticsCollector.reportForEndPoint(
161:                                            statistics.endPointName, true,
162:                                            statistics.inTimeForOutFlow, System
163:                                                    .currentTimeMillis(),
164:                                            isFault);
165:                                    tobeRemoved.add(statistics);
166:                                }
167:                            }
168:                        }
169:                    }
170:                    endpointStatistics.removeAll(tobeRemoved);
171:                }
172:                isCompleteInFlowStatisicsReport = true;
173:            }
174:
175:            class EndPointStatistics {
176:
177:                /** The name of the endpoint    */
178:                private String endPointName;
179:                /** To check whether IN message flow or not   */
180:                private boolean isStatisticsEnable;
181:                /** To indicate whether this is fault or not  */
182:                private boolean isFault;
183:                /** The time which starts to collect statistics for IN flow */
184:                private long inTimeForInFlow = -1;
185:                /** The time which starts to collect statistics for OUT flow */
186:                private long inTimeForOutFlow = -1;
187:
188:                public EndPointStatistics(String endPointName, long initTime,
189:                        boolean inFlow, boolean statisticsEnable, boolean fault) {
190:                    if (inFlow) {
191:                        this .endPointName = endPointName;
192:                        this .inTimeForInFlow = initTime;
193:                        isStatisticsEnable = statisticsEnable;
194:                        isFault = fault;
195:                    }
196:                }
197:
198:                public boolean equals(Object o) {
199:                    if (this  == o)
200:                        return true;
201:                    if (o == null || getClass() != o.getClass())
202:                        return false;
203:
204:                    EndPointStatistics that = (EndPointStatistics) o;
205:
206:                    if (endPointName != null ? !endPointName
207:                            .equals(that.endPointName)
208:                            : that.endPointName != null)
209:                        return false;
210:
211:                    return true;
212:                }
213:
214:                public int hashCode() {
215:                    return (endPointName != null ? endPointName.hashCode() : 0);
216:                }
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.